Skip to content

Commit

Permalink
tests, zone manager: Adding unit test for existing SOA serial use case
Browse files Browse the repository at this point in the history
Signed-off-by: Diana Teplits <dteplits@redhat.com>
  • Loading branch information
dteplits committed Dec 21, 2022
1 parent 2ad2850 commit 6b05ba3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
17 changes: 8 additions & 9 deletions pkg/zonemgr/zone_file_cache_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package zonemgr

import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"fmt"
"sort"
"strings"

Expand Down Expand Up @@ -32,11 +31,11 @@ var _ = Describe("cached zone file content maintenance", func() {
)

DescribeTable("generate zone file header", func(nameServerIP, domain, expectedHeader string) {
zoneFileCache = NewZoneFileCache(nameServerIP, domain)
zoneFileCache = NewZoneFileCache(nameServerIP, domain, 0)
Expect(zoneFileCache.header).To(Equal(expectedHeader))
},
Entry("header should contain default values", "", "", headerDefault),
Entry("header should contain custom values", nameServerIP, domain, headerCustom),
Entry("header should contain default values", "", "vm", headerDefault),
Entry("header should contain custom values", nameServerIP, "vm."+domain, headerCustom),
)
})

Expand Down Expand Up @@ -86,7 +85,7 @@ var _ = Describe("cached zone file content maintenance", func() {

When("interfaces records list is empty", func() {
BeforeEach(func() {
zoneFileCache = NewZoneFileCache(nameServerIP, domain)
zoneFileCache = NewZoneFileCache(nameServerIP, domain, 0)
})

DescribeTable("Updating interfaces records", validateUpdateFunc,
Expand All @@ -111,7 +110,7 @@ var _ = Describe("cached zone file content maintenance", func() {

When("interfaces records list contains single vmi", func() {
BeforeEach(func() {
zoneFileCache = NewZoneFileCache(nameServerIP, domain)
zoneFileCache = NewZoneFileCache(nameServerIP, domain, 0)
isUpdated := zoneFileCache.updateVMIRecords(k8stypes.NamespacedName{Namespace: namespace1, Name: vmi1Name},
[]v1.VirtualMachineInstanceNetworkInterface{{IPs: []string{nic1IP}, Name: nic1Name}, {IPs: []string{nic2IP}, Name: nic2Name}})
Expect(isUpdated).To(BeTrue())
Expand Down Expand Up @@ -160,7 +159,7 @@ var _ = Describe("cached zone file content maintenance", func() {

When("interfaces records list contains multiple vmis", func() {
BeforeEach(func() {
zoneFileCache = NewZoneFileCache(nameServerIP, domain)
zoneFileCache = NewZoneFileCache(nameServerIP, domain, 0)
isUpdated := zoneFileCache.updateVMIRecords(k8stypes.NamespacedName{Namespace: namespace1, Name: vmi1Name},
[]v1.VirtualMachineInstanceNetworkInterface{{IPs: []string{nic1IP}, Name: nic1Name}, {IPs: []string{nic2IP}, Name: nic2Name}})
Expect(isUpdated).To(BeTrue())
Expand Down Expand Up @@ -219,7 +218,7 @@ var _ = Describe("cached zone file content maintenance", func() {

When("interfaces records list contains vmi with multiple IPs", func() {
BeforeEach(func() {
zoneFileCache = NewZoneFileCache(nameServerIP, domain)
zoneFileCache = NewZoneFileCache(nameServerIP, domain, 0)
})

DescribeTable("Updating interfaces records list", validateUpdateFunc,
Expand Down
10 changes: 7 additions & 3 deletions pkg/zonemgr/zone_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var _ = Describe("disk zone file maintenance", func() {
zoneFileName = "zones/db.vm"
zoneFileContent = "zone file content"
zoneFileUpdatedContent = "zone file updated content"
headerSoaSerial = "$ORIGIN vm. \n$TTL 3600 \n@ IN SOA ns.vm. email.vm. (12345 3600 3600 1209600 3600)\n"
)
var zoneFile *ZoneFile

Expand Down Expand Up @@ -42,15 +43,18 @@ var _ = Describe("disk zone file maintenance", func() {
})

When("zone file already exist", func() {
BeforeEach(func() {
Expect(os.WriteFile(zoneFileName, []byte(zoneFileContent), zoneFilePerm)).To(Succeed())
})
AfterEach(func() {
Expect(os.RemoveAll(zoneFileName)).To(Succeed())
})

It("should override a zone file on disk", func() {
Expect(os.WriteFile(zoneFileName, []byte(zoneFileContent), zoneFilePerm)).To(Succeed())
testFileFunc(zoneFileUpdatedContent)
})

It("should read SOA serial", func() {
Expect(os.WriteFile(zoneFileName, []byte(headerSoaSerial), 0777)).To(Succeed())
Expect(zoneFile.ReadSoaSerial()).To(Equal(12345))
})
})
})
6 changes: 0 additions & 6 deletions pkg/zonemgr/zone_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,5 @@ var _ = Describe("Zone Manager functionality", func() {
It("should create zone file with correct name", func() {
Expect(zoneMgr.zoneFile.zoneFileFullName).To(Equal("/zones/db.vm." + customDomain))
})

When("zone file already exist", func() {
It("should update cached SOA serial value", func() {
//TODO
})
})
})
})

0 comments on commit 6b05ba3

Please sign in to comment.