Skip to content
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

tests, zone manager: Adding unit tests for zone manager component #43

Merged
merged 2 commits into from
Dec 7, 2022

Conversation

dteplits
Copy link
Contributor

@dteplits dteplits commented Dec 5, 2022

Unit tests added for:

  • ZoneManager
  • ZoneFileCache
  • ZoneFile

Signed-off-by: Diana Teplits dteplits@redhat.com

None

@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Dec 5, 2022
@dteplits
Copy link
Contributor Author

dteplits commented Dec 5, 2022

/release-note-none

@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Dec 5, 2022
aRecord_nic4_vm1_ns2 = fmt.Sprintf(aRecordFmt, nic4Name, vmi1Name, vmi2Namespace, nic4IP)
)

validateUpdateFunc := func(newVmiName, newVmiNamespace string, newInterfaces []v1.VirtualMachineInstanceNetworkInterface,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the new prefix from the variable names. It is not necessary new, maybe an existing VMI is updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

When("interfaces records list is empty", func() {
BeforeEach(func() {
zoneFileCache = NewZoneFileCache(nameServerIP, domain)
zoneFileCache.init()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't invoke private methods from the test.
Maybe it make sense to invoke the init directly from NewZoneFileCache.

Copy link
Contributor Author

@dteplits dteplits Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done
also renamed init() function name

vmi1Name,
vmi1Namespace,
[]v1.VirtualMachineInstanceNetworkInterface{{IPs: []string{nic1IP}, Name: nic1Name}},
true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a const for Updated, NotUpdated to make the test more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const (
vmi1Name = "vmi1"
vmi2Name = "vmi2"
vmi1Namespace = "ns1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the namespace is used for both vm1 and vm2 I would change the names to namespace1 and namespace2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Expect(os.RemoveAll("zones")).To(Succeed())
})

testFileFunc := func(fileContent string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change fileContent to expectedFileContent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

zoneMgr = NewZoneManager()
})

AfterEach(func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to add an empty AfterEach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


Context("Initialization", func() {
It("should validate input data", func() {
Expect(zoneMgr.UpdateZone(k8stypes.NamespacedName{Name: "vm1"}, nil)).NotTo(Succeed())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split into two tests. should fail updating a VMI with no name and should fail updating a VMI with no namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

})

It("should set custom data", func() {
Expect(zoneMgr.UpdateZone(k8stypes.NamespacedName{Namespace: "ns1", Name: "vm1"}, nil)).To(Succeed())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateZone is updating the domain and nameServerIP? I would expect NewZoneManager to do it.

Copy link
Contributor Author

@dteplits dteplits Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewZoneManager indeed updates domain and nameServerIP. I use UpdateZone just to check that values are fetched and populated correctly.
I will change the test to be more clear


When("zone file already exist", func() {
It("should update cached SOA serial value", func() {
//todo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO can be filtered by the IDE.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@dteplits dteplits force-pushed the dns_sec branch 2 times, most recently from d0f9205 to eb3f5c2 Compare December 6, 2022 12:46
Signed-off-by: Diana Teplits <dteplits@redhat.com>
Signed-off-by: Diana Teplits <dteplits@redhat.com>
@AlonaKaplan
Copy link
Member

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AlonaKaplan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 6, 2022
@AlonaKaplan
Copy link
Member

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 7, 2022
@kubevirt-bot kubevirt-bot merged commit eb47eb5 into kubevirt:main Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants