-
Notifications
You must be signed in to change notification settings - Fork 51
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
Conversation
Pull Request Test Coverage Report for Build 6498774292
💛 - Coveralls |
|
||
testFramework.ExpectUpdated(ctx, policy) | ||
|
||
httpsTG := testFramework.GetTargetGroupWithProtocol(ctx, service, "https", "http1") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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" ?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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) | ||
|
There was a problem hiding this comment.
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?
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
appsv1 "k8s.io/api/apps/v1" | ||
v1 "k8s.io/api/core/v1" |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") | ||
|
There was a problem hiding this comment.
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
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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
}
}
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you
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: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.