Skip to content

Commit

Permalink
[ADD] Testcases for A and AAAA with next-available function (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaithra001 authored Oct 15, 2024
1 parent d819696 commit e22d136
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
51 changes: 51 additions & 0 deletions object_manager_a-record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,57 @@ var _ = Describe("Object Manager: A-record", func() {
Expect(actualRecord).To(Equal(aniFakeConnector.resultObject))
})
})
Describe("Create an A-Record using AllocateNextAvailableIp", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
netviewName := "private"
vmID := "93f9249abc039284"
vmName := "dummyvm"
dnsView := "default"
recordName := "test"
comment := "test comment"
ipAddrType := "IPV4" // Specify IP address type as IPv4
objectType := "record:a"
eas := make(EA)
eas["VM ID"] = vmID
eas["VM Name"] = vmName
params := make(map[string][]string)

fakeRefReturn := fmt.Sprintf(
"record:a/ZG5zLmJpbmRfY25h:%s/%s",
recordName,
netviewName)

objectForCreation := NewIpNextAvailable(netviewName, objectType, nil, params, false, eas, comment, false, nil, ipAddrType)
objectAsResult := NewRecordA(
dnsView, "", recordName, "53.0.0.1", 5, true, comment, eas, fakeRefReturn)

fakeConnector := &fakeConnector{
createObjectObj: objectForCreation,
getObjectRef: fakeRefReturn,
getObjectObj: NewEmptyRecordA(),
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: objectAsResult,
fakeRefReturn: fakeRefReturn,
}

objMgr := NewObjectManager(fakeConnector, cmpType, tenantID)

It("should create A record with next available IP", func() {
// Call the function to allocate next available IP and create A record
result, err := objMgr.AllocateNextAvailableIp(netviewName, objectType, nil, params, false, eas, comment, false, nil, ipAddrType)

// Assert no error occurred
Expect(err).To(BeNil())

// Assert the returned result is a valid A record
actualRecord, ok := result.(*RecordA)
Expect(ok).To(BeTrue())

// Assert the returned record matches the expected result
Expect(actualRecord).To(Equal(fakeConnector.resultObject))
})
})

Describe("Get A record", func() {
cmpType := "Docker"
Expand Down
47 changes: 47 additions & 0 deletions object_manager_aaaa-record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,53 @@ var _ = Describe("Object Manager: AAAA-record", func() {
})
})

Describe("AllocateNextAvailableIp for AAAA Record", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
vmID := "93f9249abc039284"
vmName := "dummyvm"
dnsView := "default"
recordName := "test.domain.com"
comment := "Test creation"
ipAddrType := "IPV6"
objectType := "record:aaaa"
params := make(map[string][]string)

ea := EA{"VM Name": vmName, "VM ID": vmID}

fakeRefReturn := fmt.Sprintf("record:aaaa/ZG5zLmJpbmRfY25h:%s/%20%20", recordName)

objectForCreation := NewIpNextAvailable("", objectType, nil, params, false, ea, comment, false, nil, ipAddrType)
objectAsResult := NewRecordAAAA(
dnsView, recordName, "2001:db8:abcd:14::1", false, 0, comment, ea, fakeRefReturn)

fakeConnector := &fakeConnector{
createObjectObj: objectForCreation,
getObjectRef: fakeRefReturn,
getObjectObj: NewEmptyRecordAAAA(),
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: objectAsResult,
fakeRefReturn: fakeRefReturn,
}

objMgr := NewObjectManager(fakeConnector, cmpType, tenantID)

It("should allocate next available IP and create AAAA record", func() {
// Call AllocateNextAvailableIp for AAAA record
result, err := objMgr.AllocateNextAvailableIp("", objectType, nil, params, false, ea, comment, false, nil, ipAddrType)

// Assert no error occurred
Expect(err).To(BeNil())

// Assert that the result is a valid AAAA record
actualRecord, ok := result.(*RecordAAAA)
Expect(ok).To(BeTrue())

// Assert the record matches the expected result
Expect(actualRecord).To(Equal(fakeConnector.resultObject))
})
})

Describe("Negative case: returns an error message when an IPv4 address is passed", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
Expand Down

0 comments on commit e22d136

Please sign in to comment.