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

test: add e2e tests for Target Group Policy CRD #434

Merged
merged 1 commit into from
Oct 26, 2023

Conversation

scottlaiaws
Copy link
Contributor

What type of PR is this? test

Which issue does this PR fix: #379

What does this PR do / Why do we need it: add e2e tests for Target Group Policy CRD

If an issue # is not available please add repro steps and logs from aws-gateway-controller showing the issue:

Testing done on this change:

make e2e-test outputs:

Ran 38 of 38 Specs in 2715.256 seconds
SUCCESS! -- 38 Passed | 0 Failed | 0 Pending | 0 Skipped
--- PASS: TestIntegration (2716.14s)
PASS
ok      github.com/aws/aws-application-networking-k8s/test/suites/integration   2716.173s

Automation added to e2e: add test/suites/integration/target_group_policy_test.go

Will this PR introduce any new dependencies?: No

Will this break upgrades or downgrades. Has updating a running cluster been tested?: N/A

Does this PR introduce any user-facing change?: No

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@coveralls
Copy link

coveralls commented Oct 12, 2023

Pull Request Test Coverage Report for Build 6498774292

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 45.149%

Totals Coverage Status
Change from base Build 6489472856: 0.0%
Covered Lines: 3825
Relevant Lines: 8472

💛 - Coveralls

test/pkg/test/framework.go Show resolved Hide resolved

testFramework.ExpectUpdated(ctx, policy)

httpsTG := testFramework.GetTargetGroupWithProtocol(ctx, service, "https", "http1")
Copy link
Contributor

Choose a reason for hiding this comment

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

Verify old tg is deleted?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather not mix use cases. Let deletion check happens in another spec.

Expect(*httpsTG.Protocol).To(Equal(vpclattice.TargetGroupProtocolHttps))
})

It("Delete Target Group Policy reset health check config for HTTP and HTTP1 Target Group", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

That can be a better name : "Delete Target Group Policy will reset health check config to default value" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, since for other type of Target Group (e.g. HTTPS or HTTP2), when we delete the Target Group Policy, the controller will create new Target group since those fields are create-only

Expect(updatedTG.Config.HealthCheck.Port).To(BeNil())
})

It("Delete Target Group Policy create HTTP and HTTP1 Target Group", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

A better name ? "Delete Target Group Policy fallback to default TargetGroupProtocol and TargetGroupProtocolVersion"

})

httpRoute = testFramework.NewHttpRoute(testGateway, service, service.Kind)

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to create httpRoute, deployment, service 3 times? can these 3 test cases reuse one httpRoute, deployment, service to save some time?

test/pkg/test/framework.go Show resolved Hide resolved
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

corev1


testFramework.ExpectUpdated(ctx, policy)

httpsTG := testFramework.GetTargetGroupWithProtocol(ctx, service, "https", "http1")
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather not mix use cases. Let deletion check happens in another spec.

testFramework.ExpectUpdated(ctx, policy)

httpsTG := testFramework.GetTargetGroupWithProtocol(ctx, service, "https", "http1")

Copy link
Contributor

Choose a reason for hiding this comment

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

you can remove empty lines

Comment on lines 97 to 106
Expect(*updatedTG.Config.HealthCheck.Enabled).To(BeTrue())
Expect(*updatedTG.Config.HealthCheck.Path).To(Equal("/"))
Expect(*updatedTG.Config.HealthCheck.HealthCheckIntervalSeconds).To(BeEquivalentTo(30))
Expect(*updatedTG.Config.HealthCheck.HealthCheckTimeoutSeconds).To(BeEquivalentTo(5))
Expect(*updatedTG.Config.HealthCheck.HealthyThresholdCount).To(BeEquivalentTo(5))
Expect(*updatedTG.Config.HealthCheck.UnhealthyThresholdCount).To(BeEquivalentTo(2))
Expect(*updatedTG.Config.HealthCheck.Protocol).To(Equal(vpclattice.TargetGroupProtocolHttp))
Expect(*updatedTG.Config.HealthCheck.ProtocolVersion).To(Equal(vpclattice.TargetGroupProtocolVersionHttp1))
Expect(*updatedTG.Config.HealthCheck.Matcher.HttpCode).To(Equal("200"))
Expect(updatedTG.Config.HealthCheck.Port).To(BeNil())
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you compare structs rather than each field of struct? Also when we reset health check config there should be some DefaultHealthCheckConfig struct in source code that we should compare with, otherwise we declare default behavior in 2 different places source and test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default Health Check config is different based on the Target Group Protocol (it's a private method that takes in TargetGroupProtocol)

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, you can make it public, also dont compare each field of struct but compare structs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since each field of a struct is a pointer, I can't use Equal to compare them.

Also for the default health check config method, it returned a struct with a "reset" value of 0 for each field instead the actual value, it's not possible to use that.

e.g. Our UpdateTargetGroup operation takes the following request:

{
  "healthCheck": {
    "healthCheckIntervalSeconds": 0
  }
}

and then GetTargetGroup operation on the same target group will return

{
  "healthCheck": {
    "healthCheckIntervalSeconds": 5
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Since each field of a struct is a pointer, I can't use Equal to compare them.

Are you sure? assert.Equals de-reference pointers. Works fine for me

type A struct {
	i int
	s string
	b *B
}

type B struct {
	i int
	s string
}

func TestA(t *testing.T) {
	a1 := &A{
		i: 10,
		s: "10",
		b: &B{
			i: 20,
			s: "20",
		},
	}
	a2 := &A{
		i: 10,
		s: "10",
		b: &B{
			i: 20,
			s: "20",
		},
	}
	assert.Equal(t, a1, a2)
}
m

Copy link
Contributor Author

@scottlaiaws scottlaiaws Oct 25, 2023

Choose a reason for hiding this comment

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

I'm using gomega.Equal which uses reflect.DeepEqual under the hood, and that doesn't dereference the pointers. But even if that issue is resolved, I still have the other issue of the GetDefaultHealthCheck config method returning different values than the GetTargetGroup call

Wait nvm, I just tested again, reflect.DeepEqual did dereference pointers.

Copy link
Contributor

Choose a reason for hiding this comment

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

reflect.DeepEqual de-reference pointers https://pkg.go.dev/reflect#DeepEqual

Pointer values are deeply equal if they are equal using Go's == operator or if they point to deeply equal values.

Code above also resolves into True, with reflect.DeepEqual(a1, a2)


testFramework.ExpectDeletedThenNotFound(ctx, policy)

time.Sleep(2 * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

magic 2 seconds?


tg := testFramework.GetFullTargetGroupFromSummary(ctx, tgSummary)

g.Expect(*tg.Config.HealthCheck).To(Equal(vpclattice.HealthCheckConfig{
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

@scottlaiaws scottlaiaws merged commit ad00db0 into aws:main Oct 26, 2023
5 checks passed
@scottlaiaws scottlaiaws deleted the 379 branch October 26, 2023 22:34
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.

4 participants