-
Notifications
You must be signed in to change notification settings - Fork 260
Improving and adding CNI unit tests #543
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
Conversation
DancingLinks
commented
Apr 10, 2020
- Add ipam/pool_test.go
- Add network/*test.go
- Using ginkgo test ipv6ipam
mainred
left a comment
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.
Left some comments, and I need time for another look later.
ipam/pool_test.go
Outdated
| }) | ||
|
|
||
| Context("Create a new pool ID when the string is too long", func() { | ||
| It("Should create a pool ID by parsing the string", 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.
should raise an error?
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.
Yes, sorry my mistake
ipam/pool_test.go
Outdated
| }) | ||
| }) | ||
|
|
||
| Context("", 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.
We may forget the context.
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.
it should be "When pool's epoch is less than the space's epoch and the pool is never in use"
network/network_test.go
Outdated
| }) | ||
| }) | ||
| }) | ||
| ) No newline at end of file |
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.
lost a newline.
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.
added, thx :)
| Id: poolId, | ||
| IsIPv6: false, | ||
| } | ||
| ap, err := as.requestPool("", "", nil, true) |
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.
| ap, err := as.requestPool("", "", nil, true) | |
| ap, err := as.requestPool(poolId, "", nil, true) |
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.
This test case is to test requesting an ipv6 pool from an address space which only contain ipv4 pool, by only not assign the pool id it will enter the IP version matching "if branch".
ipam/pool_test.go
Outdated
| }) | ||
| }) | ||
|
|
||
| Context("When as has pools with different addresses", 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.
What about using the struct name addressSpace or addressSpace object instead of the variable name in a context, so that we can understand from the plain text context better? we can discuss here.
| Context("When as has pools with different addresses", func() { | |
| Context("When a addressSpace has pools with different number of addresses", 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.
If you agree, please also edit all other affected cases.
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.
agree, I also changed the ar to addressRecord
ipam/pool_test.go
Outdated
| Id: "pool2", | ||
| Addresses: map[string]*addressRecord{}, | ||
| } | ||
| as.Pools["pool2"].Addresses["ar"] = &addressRecord{} |
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.
What about we assign values from real cases, so that:
- it may detect more errors or better safeguard our code by walking through the code with real values.
- it can help people understand the structure of the code even without running env.
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.
Thx, very helpful suggestion!
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.
done
ipam/pool_test.go
Outdated
|
|
||
| Describe("Test releasePool", func() { | ||
| Context("When pool not found", func() { | ||
| It("Should return error", 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.
| It("Should return error", func() { | |
| It("Should return an error", 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.
"Should raise an error?" seems better?
ipam/pool_test.go
Outdated
| }) | ||
|
|
||
| Context("", func() { | ||
| It("", 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.
We may forget the expectation.
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.
thx, it should be "When pool's epoch is less than the space's epoch and pool is never in use"
ipam/pool_test.go
Outdated
| }) | ||
| }) | ||
|
|
||
| Context("When ar is ubhealthy", 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.
| Context("When ar is ubhealthy", func() { | |
| Context("When an addressPool is unhealthy", 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.
maybe "When addressRecords are unhealthy" ?
| if runtime.GOOS == windows { | ||
| kubeConfigPath = defaultWindowsKubeConfigFilePath | ||
| } else { | ||
| kubeConfigPath = defaultLinuxKubeConfigFilePath | ||
| } |
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.
The Less, the tidy, and define kubeConfigPath when being used here.
| if runtime.GOOS == windows { | |
| kubeConfigPath = defaultWindowsKubeConfigFilePath | |
| } else { | |
| kubeConfigPath = defaultLinuxKubeConfigFilePath | |
| } | |
| kubeConfigPath := defaultLinuxKubeConfigFilePath | |
| if runtime.GOOS == windows { | |
| kubeConfigPath = defaultWindowsKubeConfigFilePath | |
| } |
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.
done
ipam/ipv6Ipam_test.go
Outdated
| }, | ||
| } | ||
| Context("When node doesn't have IPv6 subnet", func() { | ||
| It("Expected to fail IPv6 IP retrieval", 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.
| It("Expected to fail IPv6 IP retrieval", func() { | |
| It("Should fail to retrieve the IPv6 address", 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.
changed
network/endpoint_test.go
Outdated
| }) | ||
|
|
||
| Describe("Test updateEndpoint", func() { | ||
| Context("", 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.
We lost something.
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.
Thx, I forget adding this test case.
| testData := map[string]string{ | ||
| "nginx-deployment-5c689d88bb": "nginx", | ||
| "nginx-deployment-5c689d88bb-qwq47": "nginx-deployment", | ||
| "nginx": "nginx", | ||
| } |
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.
| testData := map[string]string{ | |
| "nginx-deployment-5c689d88bb": "nginx", | |
| "nginx-deployment-5c689d88bb-qwq47": "nginx-deployment", | |
| "nginx": "nginx", | |
| } | |
| testData := map[string]string{ | |
| "nginx-deployment-5c689d88bb": "nginx", | |
| "nginx-deployment-5c689d88bb-qwq47": "nginx-deployment", | |
| "nginx" : "nginx", | |
| } |
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 guess you need a lint tool. Could you please run gofmt or more in the first place?
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.
This is copied from the origin test cases, I'll format it
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.
seems like we need a lint check in CI.
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.
Thanks for your effort, and the values borrowed from real cases impressed me a lot.
ipam/pool_test.go
Outdated
| }) | ||
| }) | ||
|
|
||
| Context("When IfName is not match", 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.
| Context("When IfName is not match", func() { | |
| Context("When the requested interface name does not exist", 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.
can you resolve this also?
|
/azp run |
|
Commenter does not have sufficient privileges for PR 543 in repo Azure/azure-container-networking |
ec4095f to
951ad59
Compare
tamilmani1989
left a comment
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 so much for this PR. Appreciate your effort. Left some comments
ipam/ipv6Ipam_test.go
Outdated
|
|
||
| Describe("Test newIPv6IpamSource", func() { | ||
|
|
||
| Context("When using windows environment", 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.
why context is windows env?
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.
It should be "When creating with current environment", thx
| ) | ||
|
|
||
| func TestManagerIpv6Ipam(t *testing.T) { | ||
| RegisterFailHandler(Fail) |
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.
where these functions are defined? can you add comment as well about these functions and what it does
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.
Defined in pkg Gpmega. RegisterFailHandler connects Ginkgo to Gomega. When a matcher fails the fail handler passed into RegisterFailHandler is called.
ipam/manager_ipv6Ipam_test.go
Outdated
| }) | ||
| }) | ||
|
|
||
| Context("When test with a specified address", 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.
test without requesting address explicitly
ipam/pool_test.go
Outdated
| }) | ||
| }) | ||
|
|
||
| Context("Create a new pool ID when the string is too long", 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.
Create a new pool ID when string format is incorrect
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.
Changed, thx
network/endpoint_test.go
Outdated
| }) | ||
| }) | ||
|
|
||
| Context("When SandboxKey now in use", 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.
| Context("When SandboxKey now in use", func() { | |
| Context("When SandboxKey not in use", 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.
dont
network/network_test.go
Outdated
| _ = Describe("Test Network", func() { | ||
|
|
||
| Describe("Test newExternalInterface", func() { | ||
| Context("When external interface alread exists", 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.
| Context("When external interface alread exists", func() { | |
| Context("When external interface already exists", 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.
done
network/manager_test.go
Outdated
| Expect(nm.TimeStamp).To(Equal(time.Time{})) | ||
| }) | ||
| }) | ||
| Context("When store.Write error", 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.
| Context("When store.Write error", func() { | |
| Context("When store.Write returns error", 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.
done
network/manager_test.go
Outdated
| }) | ||
| }) | ||
|
|
||
| Context("When ifName is empty", 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.
couldnt understand this? what you mean by ifName is empty? Can you add a proper description of this test case
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.
"When ifName is not specified"
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 update description saying "When ifName not specifed in GetNumberofEndpoints"
network/network_test.go
Outdated
|
|
||
| Describe("Test newExternalInterface", func() { | ||
| Context("When external interface alread exists", func() { | ||
| It("Should return nil", 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.
have to check if nm.ExternalInterfaces is updated with "subnet" right?
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.
Yes, very good suggestion!
tamilmani1989
left a comment
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 see some comments are unaddressed still..address those
ipam/pool_test.go
Outdated
| }) | ||
| }) | ||
|
|
||
| Context("When IfName is not match", 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.
can you resolve this also?
| }) | ||
| }) | ||
|
|
||
| Context("When pool's epoch is less than the space's epoch and pool is never in use", 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.
RefCount: 1 so it mean pool in use by one entity and should be deleted. If pool not in use, delete should fail
network/manager_test.go
Outdated
| }) | ||
| }) | ||
|
|
||
| Context("When ifName is empty", 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.
can you update description saying "When ifName not specifed in GetNumberofEndpoints"
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Codecov Report
@@ Coverage Diff @@
## master #543 +/- ##
===========================================
- Coverage 49.22% 38.97% -10.26%
===========================================
Files 28 42 +14
Lines 3437 5047 +1610
===========================================
+ Hits 1692 1967 +275
- Misses 1455 2811 +1356
+ Partials 290 269 -21 |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
tamilmani1989
left a comment
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.
lgtm
* Add ipam/pool_test.go & add network/*test.go * add testing ./network/ in Makefile * fix context