(assert): there should be something like ```haveManifest(...)``` and ```haveHelmChart``` or a matcher like ```k8sobjectlike``` that allow unit tests for kubernetes objects
See original GitHub issueDescription
It would be nice if we could write unit tests for eks components like helmcharts and manifests. These resources contain JSON objects (the kubernetes manifests or helmchart values) that are stringified via:
/**
* Convert an object, potentially containing tokens, to a JSON string
*/
public toJsonString(obj: any, space?: number): string {
return CloudFormationLang.toJSON(obj, space).toString();
}
It would be nice if this would be parsed and then could be used with matchers like objectLike or arrayWith
Use Case
I want to create unit tests for constructs that contain kubernetes resources. At the moment it’s not possible or I didn’t found the docs how to do this.
I only find examples that do something like:
expect(stack).toHaveResource(KubernetesManifest.RESOURCE_TYPE, {
Manifest: JSON.stringify([
{
apiVersion: 'v1beta',
kind: 'Foo',
metadata: {
labels: {
'aws.cdk.eks/prune-c89a5983505f58231ac2a9a86fd82735ccf2308eac': '',
},
},
},
]),
PruneLabel: 'aws.cdk.eks/prune-c89a5983505f58231ac2a9a86fd82735ccf2308eac',
});
but I would like to have something like:
expect(stack).toHaveManifest('SomeIdentifier?', {
Manifest: arrayWith(
{
apiVersion: 'v1beta',
kind: 'Foo',
...
anything: objectLike({
some: 'value'
}
},
]),
...
});
Proposed Solution
I have no Idea at the moment… somehow we have to JSON parse the stringified k8s objects
Other information
no
Acknowledge
- I may be able to implement this feature request
- This feature might incur a breaking change
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Unit testing Kubernetes operators using mocks - ITNEXT
In this post, I'll walk you through the idea of unit testing Kubernetes operators using mocks, why you'd need them, and how to...
Read more >Mocking the Kubernetes client in Go for Unit Testing - Medium
When we run this main.go file against a running cluster, we end up creating a pod called test-pod in the default namespace. Now,...
Read more >Testing - The Cluster API Book
In Cluster API, integration tests are based on envtest and one or more controllers configured to run against the test cluster. With this...
Read more >Unit Testing Kubernetes Resources with Go - Thomas Stringer
In the previous blog post I talked about how to connect to a Kubernetes cluster from Go. But we're missing something here with...
Read more >Running integration tests in Kubernetes - Opensource.com
This can only be tested by running all these parts next to each other and not enabling "test mode" within our application. Unit...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks perfect! Will give it a try tomorrow!
only for others who stumble over this: works like a charm!