-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -371,6 +371,7 @@ test-all: | |
| ./ipam/ \ | ||
| ./log/ \ | ||
| ./netlink/ \ | ||
| ./network/ \ | ||
| ./store/ \ | ||
| ./telemetry/ \ | ||
| ./aitelemetry/ \ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,17 +6,25 @@ package ipam | |
| import ( | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/ginkgo" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/Azure/azure-container-networking/common" | ||
| ) | ||
|
|
||
| var ( | ||
|
|
||
| // Pools and addresses used by tests. | ||
| ipv6subnet1 = "ace:cab:deca:deed::" + testSubnetSize | ||
| ipv6addr2 = "ace:cab:deca:deed::2" | ||
| ipv6addr3 = "ace:cab:deca:deed::3" | ||
| ) | ||
|
|
||
| func TestManagerIpv6Ipam(t *testing.T) { | ||
| RegisterFailHandler(Fail) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| RunSpecs(t, "Manager ipv6ipam Suite") | ||
| } | ||
|
|
||
|
|
||
| func createTestIpv6AddressManager() (AddressManager, error) { | ||
| var config common.PluginConfig | ||
| var options map[string]interface{} | ||
|
|
@@ -43,69 +51,74 @@ func createTestIpv6AddressManager() (AddressManager, error) { | |
| return am, nil | ||
| } | ||
|
|
||
| // | ||
| // Address manager tests. | ||
| // | ||
| // request pool, request address with no address specified, request address with address specified, | ||
| // release both addresses, release pool | ||
| func TestIPv6GetAddressPoolAndAddress(t *testing.T) { | ||
| // Start with the test address space. | ||
| am, err := createTestIpv6AddressManager() | ||
| if err != nil { | ||
| t.Fatalf("createAddressManager failed, err:%+v.", err) | ||
| } | ||
|
|
||
| // Test if the address spaces are returned correctly. | ||
| local, _ := am.GetDefaultAddressSpaces() | ||
|
|
||
| if local != LocalDefaultAddressSpaceId { | ||
| t.Errorf("GetDefaultAddressSpaces returned invalid local address space.") | ||
| } | ||
|
|
||
| // Request two separate address pools. | ||
| poolID1, subnet1, err := am.RequestPool(LocalDefaultAddressSpaceId, "", "", nil, true) | ||
| if err != nil { | ||
| t.Errorf("RequestPool failed, err:%v", err) | ||
| } | ||
|
|
||
| if subnet1 != ipv6subnet1 { | ||
| t.Errorf("Mismatched retrieved subnet, expected:%+v, actual %+v", ipv6subnet1, subnet1) | ||
| } | ||
|
|
||
| // test with a specified address | ||
| address2, err := am.RequestAddress(LocalDefaultAddressSpaceId, poolID1, ipv6addr2, nil) | ||
| if err != nil { | ||
| t.Errorf("RequestAddress failed, err:%v", err) | ||
| } | ||
|
|
||
| if address2 != ipv6addr2+testSubnetSize { | ||
| t.Errorf("RequestAddress failed, expected: %v, actual: %v", ipv6addr2+testSubnetSize, address2) | ||
| } | ||
|
|
||
| // test with a specified address | ||
| address3, err := am.RequestAddress(LocalDefaultAddressSpaceId, poolID1, "", nil) | ||
| if err != nil { | ||
| t.Errorf("RequestAddress failed, err:%v", err) | ||
| } | ||
|
|
||
| if address3 != ipv6addr3+testSubnetSize { | ||
| t.Errorf("RequestAddress failed, expected: %v, actual: %v", ipv6addr3+testSubnetSize, address3) | ||
| } | ||
|
|
||
| // Release addresses and the pool. | ||
| err = am.ReleaseAddress(LocalDefaultAddressSpaceId, poolID1, address2, nil) | ||
| if err != nil { | ||
| t.Errorf("ReleaseAddress failed, err:%v", err) | ||
| } | ||
|
|
||
| // Release addresses and the pool. | ||
| err = am.ReleaseAddress(LocalDefaultAddressSpaceId, poolID1, address3, nil) | ||
| if err != nil { | ||
| t.Errorf("ReleaseAddress failed, err:%v", err) | ||
| } | ||
|
|
||
| err = am.ReleasePool(LocalDefaultAddressSpaceId, poolID1) | ||
| if err != nil { | ||
| t.Errorf("ReleasePool failed, err:%v", err) | ||
| } | ||
| } | ||
| var ( | ||
| _ = Describe("Test manager ipv6Ipam", func() { | ||
|
|
||
| Describe("Test IPv6 get address pool and address", func() { | ||
|
|
||
| var ( | ||
| am AddressManager | ||
| err error | ||
| poolID1 string | ||
| subnet1 string | ||
| address2 string | ||
| address3 string | ||
| ) | ||
|
|
||
| Context("Start with the test address space", func() { | ||
| It("Should create AddressManager successfully", func() { | ||
| am, err = createTestIpv6AddressManager() | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| }) | ||
| }) | ||
|
|
||
| Context("When test if the address spaces are returned correctly", func() { | ||
| It("GetDefaultAddressSpaces returned valid local address space", func() { | ||
| local, _ := am.GetDefaultAddressSpaces() | ||
| Expect(local).To(Equal(LocalDefaultAddressSpaceId)) | ||
| }) | ||
| }) | ||
|
|
||
| Context("When request two separate address pools", func() { | ||
| It("Should request pool successfully and return subnet matched ipv6subnet1", func() { | ||
| poolID1, subnet1, err = am.RequestPool(LocalDefaultAddressSpaceId, "", "", nil, true) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(subnet1).To(Equal(ipv6subnet1)) | ||
|
|
||
| }) | ||
| }) | ||
|
|
||
| Context("When test with a specified address", func() { | ||
| It("Should request address successfully", func() { | ||
| address2, err := am.RequestAddress(LocalDefaultAddressSpaceId, poolID1, ipv6addr2, nil) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(address2).To(Equal(ipv6addr2+testSubnetSize)) | ||
| }) | ||
| }) | ||
|
|
||
| Context("When test without requesting address explicitly", func() { | ||
| It("Should request address successfully", func() { | ||
| address3, err := am.RequestAddress(LocalDefaultAddressSpaceId, poolID1, "", nil) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(address3).To(Equal(ipv6addr3+testSubnetSize)) | ||
| }) | ||
| }) | ||
|
|
||
| Context("When release address2", func() { | ||
| It("Should release successfully", func() { | ||
| err = am.ReleaseAddress(LocalDefaultAddressSpaceId, poolID1, address2, nil) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| }) | ||
| }) | ||
|
|
||
| Context("When release address3 and the pool", func() { | ||
| It("Should release successfully", func() { | ||
| err = am.ReleaseAddress(LocalDefaultAddressSpaceId, poolID1, address3, nil) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| err = am.ReleasePool(LocalDefaultAddressSpaceId, poolID1) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.