Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests for /apis, /internal, /pkg #63

Merged
merged 4 commits into from
Jan 24, 2024
Merged

Conversation

lisguo
Copy link
Contributor

@lisguo lisguo commented Jan 23, 2024

Description of changes:
Unit test fixes, can run full suite of unit tests with make test.

  • Removed TargetAllocator artifacts and tests since we do not use it
  • Fixed configmap tests to use the agent json instead of otel collector yaml configs
  • Fixed default instrumentation test to validate default values for auto instrumentation
  • Changed make test to ignore the integration test
  • Changed naming conventions to be consistent

Code snippet of tests passing in packages

ok  	github.com/aws/amazon-cloudwatch-agent-operator/apis/v1alpha1	(cached)
ok  	github.com/aws/amazon-cloudwatch-agent-operator/internal/config	(cached)
ok  	github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests/collector/adapters	(cached)
ok  	github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests/manifestutils	(cached)
ok  	github.com/aws/amazon-cloudwatch-agent-operator/internal/naming	(cached)
ok  	github.com/aws/amazon-cloudwatch-agent-operator/internal/version	(cached)
ok  	github.com/aws/amazon-cloudwatch-agent-operator/internal/webhook/podmutation	(cached)
ok  	github.com/aws/amazon-cloudwatch-agent-operator/pkg/featuregate	(cached)

More failing tests will need to be addressed in the future

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -67,14 +67,6 @@ rules:
- patch
- update
- watch
- apiGroups:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this section is unneeded as it is duplicated from line 107

@@ -82,10 +84,10 @@ ci: test
# Run tests
# setup-envtest uses KUBEBUILDER_ASSETS which points to a directory with binaries (api-server, etcd and kubectl)
.PHONY: test
test: generate fmt vet ensure-generate-is-noop envtest
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure-generate-is-noop doesn't exist in the Makefile, we don't use it

@@ -51,6 +51,8 @@ CONTROLLER_TOOLS_VERSION ?= v0.12.0
ALL_SRC := $(shell find . -name '*.go' -type f | sort)
CW_AGENT_OPERATOR_IMPORT_PATH = "github.com/aws/amazon-cloudwatch-agent-operator"

GOTEST_OPTS := $(shell go list ./... | grep -v integration-tests)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can ignore the integration-tests as part of make test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could add an integration-test build tag to the integration tests, so they're skipped normally.

//go:build integration-test

newName: aws/amazon-cloudwatch-agent-operator
newTag: latest
newName: aws/cloudwatch-agent-operator
newTag: 1.0.2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was made to be consistent with the image produced in the Makefile by make container

@jefchien
Copy link
Contributor

Thanks for fixing the unit tests! Can you summarize the major changes you had to make?

jefchien
jefchien previously approved these changes Jan 23, 2024
@@ -51,7 +51,7 @@ func paramsWithMode(mode v1alpha1.Mode) manifests.Params {
UID: instanceUID,
},
Spec: v1alpha1.AmazonCloudWatchAgentSpec{
Image: "ghcr.io/aws/amazon-cloudwatch-agent-operator/amazon-cloudwatch-agent-operator:0.47.0",
Image: "public.ecr.aws/cloudwatch-agent/cloudwatch-agent:1.300031.1b317",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we're using this specific image?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to be consistent with this line in configmap_test.go:

		expectedLables["app.kubernetes.io/version"] = "1.300031.1b317"

I can change it to something more generic like 0.0.0

@@ -51,6 +51,8 @@ CONTROLLER_TOOLS_VERSION ?= v0.12.0
ALL_SRC := $(shell find . -name '*.go' -type f | sort)
CW_AGENT_OPERATOR_IMPORT_PATH = "github.com/aws/amazon-cloudwatch-agent-operator"

GOTEST_OPTS := $(shell go list ./... | grep -v integration-tests)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could add an integration-test build tag to the integration tests, so they're skipped normally.

//go:build integration-test

// +kubebuilder:webhook:path=/mutate-cloudwatch-aws-amazon-com-v1alpha1-amazoncloudwatchagent,mutating=true,failurePolicy=fail,groups=cloudwatch.aws.amazon.co,resources=amazoncloudwatchagents,verbs=create;update,versions=v1alpha1,name=mamazoncloudwatchagent.kb.io,sideEffects=none,admissionReviewVersions=v1
// +kubebuilder:webhook:verbs=create;update,path=/validate-cloudwatch-aws-amazon-com-v1alpha1-amazoncloudwatchagent,mutating=false,failurePolicy=fail,groups=cloudwatch.aws.amazon.co,resources=amazoncloudwatchagents,versions=v1alpha1,name=vamazoncloudwatchagentcreateupdate.kb.io,sideEffects=none,admissionReviewVersions=v1
// +kubebuilder:webhook:verbs=delete,path=/validate-cloudwatch-aws-amazon-com-v1alpha1-amazoncloudwatchagent,mutating=false,failurePolicy=ignore,groups=cloudwatch.aws.amazon.co,resources=amazoncloudwatchagents,versions=v1alpha1,name=vamazoncloudwatchagentdelete.kb.io,sideEffects=none,admissionReviewVersions=v1
// +kubebuilder:webhook:path=/mutate-cloudwatch-aws-amazon-com-v1alpha1-amazoncloudwatchagent,mutating=true,failurePolicy=fail,groups=cloudwatch.aws.amazon.com,resources=amazoncloudwatchagents,verbs=create;update,versions=v1alpha1,name=mamazoncloudwatchagent.kb.io,sideEffects=none,admissionReviewVersions=v1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this

@lisguo lisguo merged commit fe144bb into aws:main Jan 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants