Skip to content

Commit

Permalink
Added test for empty gateway
Browse files Browse the repository at this point in the history
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk-pawel.strusiewicz-surmacki@external.telekom.de>
  • Loading branch information
p-strusiewiczsurmacki-mobica committed Jan 10, 2024
1 parent 5df5a31 commit 7309316
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions internal/controllers/ipaddressclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,93 @@ var _ = Describe("IPAddressClaimReconciler", func() {
})
})

When("the referenced namespaced pool does not define gateway for subnet", func() {
const poolName = "test-pool"
const claimName = "test-claim"

var expectedIPAddress ipamv1.IPAddress

var pool v1alpha1.InfobloxIPPool

BeforeEach(func() {
localInfobloxClientMock = ibmock.NewMockClient(mockCtrl)
getInfobloxClientForInstanceFunc = mockGetInfobloxClientForInstance
pool = v1alpha1.InfobloxIPPool{
ObjectMeta: metav1.ObjectMeta{
Name: poolName,
Namespace: namespace,
},
Spec: v1alpha1.InfobloxIPPoolSpec{
InstanceRef: corev1.LocalObjectReference{Name: instanceName},
Subnets: []v1alpha1.Subnet{
{CIDR: "10.0.0.0/24"},
{CIDR: "10.0.1.0/24"},
},
NetworkView: "default",
DNSZone: "",
},
}
Expect(k8sClient.Create(context.Background(), &pool)).To(Succeed())
})

AfterEach(func() {
deleteClaim(claimName, namespace)
deleteNamespacedPool(poolName, namespace)
getInfobloxClientForInstanceFunc = getInfobloxClientForInstance
})

It("should allocate an Address from the Pool", func() {
addr, err := netip.ParseAddr("10.0.0.2")
Expect(err).NotTo(HaveOccurred())
localInfobloxClientMock.EXPECT().GetOrAllocateAddress(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(addr, nil).AnyTimes()
localInfobloxClientMock.EXPECT().ReleaseAddress(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()

claim := newClaim(claimName, namespace, "InfobloxIPPool", poolName)
expectedIPAddress = ipamv1.IPAddress{
ObjectMeta: metav1.ObjectMeta{
Name: claimName,
Namespace: namespace,
Finalizers: []string{ipamutil.ProtectAddressFinalizer},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: ipamAPIVersion,
BlockOwnerDeletion: ptr.To[bool](true),
Controller: ptr.To[bool](true),
Kind: "IPAddressClaim",
Name: claimName,
},
{
APIVersion: "ipam.cluster.x-k8s.io/v1alpha1",
BlockOwnerDeletion: ptr.To[bool](true),
Controller: ptr.To[bool](false),
Kind: "InfobloxIPPool",
Name: poolName,
},
},
},
Spec: ipamv1.IPAddressSpec{
ClaimRef: corev1.LocalObjectReference{
Name: claimName,
},
PoolRef: corev1.TypedLocalObjectReference{
APIGroup: ptr.To[string]("ipam.cluster.x-k8s.io"),
Kind: "InfobloxIPPool",
Name: poolName,
},
Address: "10.0.0.2",
Prefix: 24,
},
}

Expect(k8sClient.Create(context.Background(), &claim)).To(Succeed())

Eventually(findAddress(claimName, namespace)).
WithTimeout(1 * time.Second).WithPolling(100 * time.Millisecond).Should(
EqualObject(&expectedIPAddress, IgnoreAutogeneratedMetadata, IgnoreUIDsOnIPAddress),
)
})
})

When("the referenced namespaced pool does not exists", func() {
const wrongPoolName = "wrong-test-pool"
const poolName = "test-pool"
Expand Down

0 comments on commit 7309316

Please sign in to comment.