Skip to content

Commit

Permalink
tests: Refactor GetAllDomainStats test
Browse files Browse the repository at this point in the history
Simplify the matching of arguments in the expected call and introduce
consts to make the test more readable.

Signed-off-by: Vasiliy Ulyanov <[email protected]>
  • Loading branch information
vasiliy-ul committed Mar 14, 2023
1 parent c9bd72e commit a180c7a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pkg/virt-launcher/virtwrap/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1589,14 +1589,20 @@ var _ = Describe("Manager", func() {

Context("on successful GetAllDomainStats", func() {
It("should return content", func() {
fake_jobinfo := stats.DomainJobInfo{}
mockConn.EXPECT().GetDomainStats(
gomock.Eq(libvirt.DOMAIN_STATS_BALLOON|libvirt.DOMAIN_STATS_CPU_TOTAL|libvirt.DOMAIN_STATS_VCPU|libvirt.DOMAIN_STATS_INTERFACE|libvirt.DOMAIN_STATS_BLOCK|libvirt.DOMAIN_STATS_DIRTYRATE),
&fake_jobinfo,
gomock.Eq(libvirt.CONNECT_GET_ALL_DOMAINS_STATS_RUNNING),
).Return([]*stats.DomainStats{
const (
domainStats = libvirt.DOMAIN_STATS_BALLOON |
libvirt.DOMAIN_STATS_CPU_TOTAL |
libvirt.DOMAIN_STATS_VCPU |
libvirt.DOMAIN_STATS_INTERFACE |
libvirt.DOMAIN_STATS_BLOCK |
libvirt.DOMAIN_STATS_DIRTYRATE
flags = libvirt.CONNECT_GET_ALL_DOMAINS_STATS_RUNNING
)
fakeDomainStats := []*stats.DomainStats{
{},
}, nil)
}

mockConn.EXPECT().GetDomainStats(domainStats, gomock.Any(), flags).Return(fakeDomainStats, nil)

manager, _ := NewLibvirtDomainManager(mockConn, testVirtShareDir, testEphemeralDiskDir, nil, "/usr/share/OVMF", ephemeralDiskCreatorMock, metadataCache)
domStats, err := manager.GetDomainStats()
Expand Down

0 comments on commit a180c7a

Please sign in to comment.