Skip to content

Commit 11c163f

Browse files
committed
Use boot image in controller tests
1 parent 11abf81 commit 11c163f

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

internal/controllers/controllers_suite_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ var _ = BeforeSuite(func() {
222222
}
223223
}()
224224

225+
By("starting image cache")
226+
go func() {
227+
defer GinkgoRecover()
228+
err := imgCache.Start(controllerCtx)
229+
if err != nil && controllerCtx.Err() == nil {
230+
// Only fail if not cancelled
231+
Expect(err).NotTo(HaveOccurred())
232+
}
233+
}()
234+
225235
// Wait a bit for controller and events to start
226236
time.Sleep(500 * time.Millisecond)
227237

internal/controllers/machine_controller_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package controllers_test
55

66
import (
7+
"time"
8+
79
"github.com/digitalocean/go-libvirt"
810
"github.com/ironcore-dev/libvirt-provider/api"
911
libvirtutils "github.com/ironcore-dev/libvirt-provider/internal/libvirt/utils"
@@ -56,8 +58,9 @@ var _ = Describe("MachineController", func() {
5658

5759
})
5860

59-
It("should handle machine without boot image, but with volume and network interface", func(ctx SpecContext) {
60-
By("creating a machine with volume and network interface")
61+
It("should handle machine with boot image and network interface", func(ctx SpecContext) {
62+
By("creating a machine with boot image and network interface")
63+
image := osImage
6164
machine, err := createMachine(api.MachineSpec{
6265
Power: api.PowerStatePowerOn,
6366
Cpu: 2,
@@ -66,7 +69,7 @@ var _ = Describe("MachineController", func() {
6669
{
6770
Name: "disk-1",
6871
LocalDisk: &api.LocalDiskSpec{
69-
Size: emptyDiskSize,
72+
Image: &image,
7073
},
7174
Device: "oda",
7275
},
@@ -97,7 +100,7 @@ var _ = Describe("MachineController", func() {
97100
Eventually(func() error {
98101
domain, err = libvirtConn.DomainLookupByUUID(libvirtutils.UUIDStringToBytes(machine.ID))
99102
return err
100-
}).Should(Succeed())
103+
}).WithTimeout(5 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
101104
domainXMLData, err := libvirtConn.DomainGetXMLDesc(domain, 0)
102105
Expect(err).NotTo(HaveOccurred())
103106
Expect(domainXMLData).NotTo(BeEmpty())
@@ -116,12 +119,11 @@ var _ = Describe("MachineController", func() {
116119
return &m.Status
117120
}).Should(SatisfyAll(
118121
HaveField("ImageRef", BeEmpty()),
119-
HaveField("VolumeStatus", ContainElement(api.VolumeStatus{
120-
Name: "disk-1",
121-
Handle: "libvirt-provider.ironcore.dev/local-disk/disk-1",
122-
State: api.VolumeStateAttached,
123-
Size: emptyDiskSize,
124-
})),
122+
HaveField("VolumeStatus", ContainElement(SatisfyAll(
123+
HaveField("Name", Equal("disk-1")),
124+
HaveField("Handle", Equal("libvirt-provider.ironcore.dev/local-disk/disk-1")),
125+
HaveField("State", Equal(api.VolumeStateAttached)),
126+
))),
125127
HaveField("NetworkInterfaceStatus", ContainElement(api.NetworkInterfaceStatus{
126128
Name: "nic-1",
127129
State: api.NetworkInterfaceStateAttached,

0 commit comments

Comments
 (0)