Skip to content

Commit 5031ea4

Browse files
committed
Use fake images for machine tests
In tests that do not start a machine, we can use "fake" images to speed up tests. In the case of darwin and Linux, that can be /dev/null. The hypervisors don't care. In the case of Windows, some research will need to be done to determine the same approach but this is a start. Signed-off-by: Brent Baude <bbaude@redhat.com>
1 parent 6a2f1cf commit 5031ea4

File tree

12 files changed

+85
-47
lines changed

12 files changed

+85
-47
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
package e2e_test
22

3+
import "os"
4+
35
const podmanBinary = "../../../bin/darwin/podman"
6+
7+
var (
8+
fakeImagePath string = os.DevNull
9+
)
10+
11+
func (i *initMachine) withFakeImage(_ *machineTestBuilder) *initMachine {
12+
i.image = fakeImagePath
13+
return i
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
package e2e_test
22

3+
import "os"
4+
35
const podmanBinary = "../../../bin/podman-remote"
6+
7+
var (
8+
fakeImagePath string = os.DevNull
9+
)
10+
11+
func (i *initMachine) withFakeImage(_ *machineTestBuilder) *initMachine {
12+
i.image = fakeImagePath
13+
return i
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
package e2e_test
22

3+
import "os"
4+
35
const podmanBinary = "../../../bin/podman-remote"
6+
7+
var (
8+
fakeImagePath string = os.DevNull
9+
)
10+
11+
func (i *initMachine) withFakeImage(_ *machineTestBuilder) *initMachine {
12+
i.image = fakeImagePath
13+
return i
14+
}

pkg/machine/e2e/config_windows_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ func runWslCommand(cmdArgs []string) (*machineSession, error) {
4040
ms.waitWithTimeout(defaultTimeout)
4141
return &ms, nil
4242
}
43+
44+
func (i *initMachine) withFakeImage(_ *machineTestBuilder) *initMachine {
45+
i.image = mb.imagePath
46+
return i
47+
}

pkg/machine/e2e/info_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var _ = Describe("podman machine info", func() {
2828

2929
// Create a machine and check if info has been updated
3030
i := new(initMachine)
31-
initSession, err := mb.setCmd(i.withImage(mb.imagePath)).run()
31+
initSession, err := mb.setCmd(i.withFakeImage(mb)).run()
3232
Expect(err).ToNot(HaveOccurred())
3333
Expect(initSession).To(Exit(0))
3434

pkg/machine/e2e/init_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ var _ = Describe("podman machine init", func() {
8888
// Check that mounting to certain target directories like /tmp at the / level is NOT ok
8989
tmpVol := initMachine{}
9090
targetMount := "/tmp"
91-
tmpVolSession, err := mb.setCmd(tmpVol.withImage(mb.imagePath).withVolume(fmt.Sprintf("/whatever:%s", targetMount))).run()
91+
tmpVolSession, err := mb.setCmd(tmpVol.withFakeImage(mb).withVolume(fmt.Sprintf("/whatever:%s", targetMount))).run()
9292
Expect(err).ToNot(HaveOccurred())
9393
Expect(tmpVolSession).To(Exit(125))
9494
Expect(tmpVolSession.errorToString()).To(ContainSubstring(fmt.Sprintf("Error: machine mount destination cannot be %q: consider another location or a subdirectory of an existing location", targetMount)))
@@ -102,7 +102,7 @@ var _ = Describe("podman machine init", func() {
102102

103103
It("simple init", func() {
104104
i := new(initMachine)
105-
session, err := mb.setCmd(i.withImage(mb.imagePath)).run()
105+
session, err := mb.setCmd(i.withFakeImage(mb)).run()
106106
Expect(err).ToNot(HaveOccurred())
107107
Expect(session).To(Exit(0))
108108

@@ -118,7 +118,7 @@ var _ = Describe("podman machine init", func() {
118118
Expect(testMachine.Resources.Memory).To(BeEquivalentTo(uint64(2048)))
119119
}
120120
// creating a new VM with the same name must fail
121-
repeatSession, err := mb.setCmd(i.withImage(mb.imagePath)).run()
121+
repeatSession, err := mb.setCmd(i.withFakeImage(mb)).run()
122122
Expect(err).ToNot(HaveOccurred())
123123
Expect(repeatSession).To(Exit(125))
124124
Expect(repeatSession.errorToString()).To(ContainSubstring(fmt.Sprintf("Error: machine %q already exists", mb.names[0])))
@@ -193,7 +193,7 @@ var _ = Describe("podman machine init", func() {
193193

194194
It("simple init with start", func() {
195195
i := initMachine{}
196-
session, err := mb.setCmd(i.withImage(mb.imagePath)).run()
196+
session, err := mb.setCmd(i.withFakeImage(mb)).run()
197197
Expect(err).ToNot(HaveOccurred())
198198
Expect(session).To(Exit(0))
199199

@@ -230,7 +230,7 @@ var _ = Describe("podman machine init", func() {
230230
It("simple init with username", func() {
231231
i := new(initMachine)
232232
remoteUsername := "remoteuser"
233-
session, err := mb.setCmd(i.withImage(mb.imagePath).withUsername(remoteUsername)).run()
233+
session, err := mb.setCmd(i.withFakeImage(mb).withUsername(remoteUsername)).run()
234234
Expect(err).ToNot(HaveOccurred())
235235
Expect(session).To(Exit(0))
236236

@@ -263,7 +263,7 @@ var _ = Describe("podman machine init", func() {
263263
skipIfWSL("setting hardware resource numbers and timezone are not supported on WSL")
264264
name := randomString()
265265
i := new(initMachine)
266-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withCPUs(2).withDiskSize(102).withMemory(4096).withTimezone("Pacific/Honolulu")).run()
266+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb).withCPUs(2).withDiskSize(102).withMemory(4096).withTimezone("Pacific/Honolulu")).run()
267267
Expect(err).ToNot(HaveOccurred())
268268
Expect(session).To(Exit(0))
269269

@@ -310,7 +310,7 @@ var _ = Describe("podman machine init", func() {
310310
skipIfWSL("Configuring swap is not supported on WSL")
311311
name := randomString()
312312
i := new(initMachine)
313-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withSwap(2048).withNow()).run()
313+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb).withSwap(2048).withNow()).run()
314314
Expect(err).ToNot(HaveOccurred())
315315
Expect(session).To(Exit(0))
316316

@@ -343,7 +343,7 @@ var _ = Describe("podman machine init", func() {
343343

344344
name := randomString()
345345
i := new(initMachine)
346-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withVolume(mount).withVolume(mountWithSpaces).withNow()).run()
346+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb).withVolume(mount).withVolume(mountWithSpaces).withNow()).run()
347347
Expect(err).ToNot(HaveOccurred())
348348
Expect(session).To(Exit(0))
349349

@@ -379,7 +379,7 @@ var _ = Describe("podman machine init", func() {
379379

380380
name := randomString()
381381
i := new(initMachine)
382-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withIgnitionPath(tmpFile.Name())).run()
382+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb).withIgnitionPath(tmpFile.Name())).run()
383383
Expect(err).ToNot(HaveOccurred())
384384
Expect(session).To(Exit(0))
385385

@@ -406,7 +406,7 @@ var _ = Describe("podman machine init", func() {
406406
It("machine init rootless docker.sock check", func() {
407407
i := initMachine{}
408408
name := randomString()
409-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath)).run()
409+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb)).run()
410410
Expect(err).ToNot(HaveOccurred())
411411
Expect(session).To(Exit(0))
412412

@@ -428,7 +428,7 @@ var _ = Describe("podman machine init", func() {
428428
It("machine init rootful with docker.sock check", func() {
429429
i := initMachine{}
430430
name := randomString()
431-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withRootful(true)).run()
431+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb).withRootful(true)).run()
432432
Expect(err).ToNot(HaveOccurred())
433433
Expect(session).To(Exit(0))
434434

@@ -455,7 +455,7 @@ var _ = Describe("podman machine init", func() {
455455
It("init should cleanup on failure", func() {
456456
i := new(initMachine)
457457
name := randomString()
458-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath)).run()
458+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb)).run()
459459

460460
Expect(err).ToNot(HaveOccurred())
461461
Expect(session).To(Exit(0))
@@ -482,7 +482,7 @@ var _ = Describe("podman machine init", func() {
482482
// Bad ignition path - init fails
483483
i = new(initMachine)
484484
i.ignitionPath = "/bad/path"
485-
session, err = mb.setName(name).setCmd(i.withImage(mb.imagePath)).run()
485+
session, err = mb.setName(name).setCmd(i.withFakeImage(mb)).run()
486486
Expect(err).ToNot(HaveOccurred())
487487
Expect(session).To(Exit(125))
488488

@@ -534,7 +534,7 @@ var _ = Describe("podman machine init", func() {
534534
// We should be able to init with a bad config present
535535
i := new(initMachine)
536536
name := randomString()
537-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath)).run()
537+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb)).run()
538538
Expect(err).ToNot(HaveOccurred())
539539
Expect(session).To(Exit(0))
540540

@@ -561,7 +561,7 @@ var _ = Describe("podman machine init", func() {
561561

562562
i := initMachine{}
563563
name := randomString()
564-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath)).run()
564+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb)).run()
565565
Expect(err).ToNot(HaveOccurred())
566566
Expect(session).To(Exit(0))
567567

@@ -612,7 +612,7 @@ var _ = Describe("podman machine init", func() {
612612

613613
i := initMachine{}
614614
name := randomString()
615-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath)).run()
615+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb)).run()
616616
Expect(err).ToNot(HaveOccurred())
617617
Expect(session).To(Exit(0))
618618

@@ -657,7 +657,7 @@ var _ = Describe("podman machine init", func() {
657657

658658
i := initMachine{}
659659
machineName := randomString()
660-
session, err := mb.setName(machineName).setCmd(i.withImage(mb.imagePath).withProvider(providerOverride)).run()
660+
session, err := mb.setName(machineName).setCmd(i.withFakeImage(mb).withProvider(providerOverride)).run()
661661
Expect(err).ToNot(HaveOccurred())
662662
Expect(session.errorToString()).To(ContainSubstring(fmt.Sprintf("unsupported provider %q", providerOverride)))
663663
})
@@ -678,7 +678,7 @@ var _ = Describe("podman machine init", func() {
678678
// --provider
679679
for name, p := range verify {
680680
i := initMachine{}
681-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withProvider(p)).run()
681+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb).withProvider(p)).run()
682682
Expect(err).ToNot(HaveOccurred())
683683
Expect(session.ExitCode()).To(Equal(0))
684684
}

pkg/machine/e2e/init_windows_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var _ = Describe("podman machine init - windows only", func() {
2222
}
2323
i := new(initMachine)
2424
name := randomString()
25-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withUserModeNetworking(true)).run()
25+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb).withUserModeNetworking(true)).run()
2626
Expect(err).ToNot(HaveOccurred())
2727
Expect(session).To(Exit(0))
2828

@@ -79,7 +79,7 @@ var _ = Describe("podman machine init - windows only", func() {
7979
}
8080
}()
8181
i := new(initMachine)
82-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath)).run()
82+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb)).run()
8383
Expect(err).ToNot(HaveOccurred())
8484
Expect(session).To(Exit(125))
8585
Expect(session.errorToString()).To(ContainSubstring("already exists on hypervisor"))
@@ -97,7 +97,7 @@ var _ = Describe("podman machine init - windows only", func() {
9797

9898
// create a bogus machine
9999
i := new(initMachine)
100-
session, err := mb.setName("foobarexport").setCmd(i.withImage(mb.imagePath)).run()
100+
session, err := mb.setName("foobarexport").setCmd(i.withFakeImage(mb)).run()
101101
Expect(err).ToNot(HaveOccurred())
102102
Expect(session).To(Exit(0))
103103

@@ -122,7 +122,7 @@ var _ = Describe("podman machine init - windows only", func() {
122122
}()
123123

124124
// Trying to make a vm with the same name as an existing name should result in a 125
125-
checkSession, err := mb.setName(name).setCmd(i.withImage(mb.imagePath)).run()
125+
checkSession, err := mb.setName(name).setCmd(i.withFakeImage(mb)).run()
126126
Expect(err).ToNot(HaveOccurred())
127127
Expect(checkSession).To(Exit(125))
128128
})

pkg/machine/e2e/inspect_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ var _ = Describe("podman inspect stop", func() {
2323

2424
It("inspect two machines", func() {
2525
i := new(initMachine)
26-
foo1, err := mb.setName("foo1").setCmd(i.withImage(mb.imagePath)).run()
26+
foo1, err := mb.setName("foo1").setCmd(i.withFakeImage(mb)).run()
2727
Expect(err).ToNot(HaveOccurred())
2828
Expect(foo1).To(Exit(0))
2929

3030
ii := new(initMachine)
31-
foo2, err := mb.setName("foo2").setCmd(ii.withImage(mb.imagePath)).run()
31+
foo2, err := mb.setName("foo2").setCmd(ii.withFakeImage(mb)).run()
3232
Expect(err).ToNot(HaveOccurred())
3333
Expect(foo2).To(Exit(0))
3434

@@ -43,7 +43,7 @@ var _ = Describe("podman inspect stop", func() {
4343
It("inspect with go format", func() {
4444
name := randomString()
4545
i := new(initMachine)
46-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath)).run()
46+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb)).run()
4747
Expect(err).ToNot(HaveOccurred())
4848
Expect(session).To(Exit(0))
4949

@@ -83,7 +83,7 @@ var _ = Describe("podman inspect stop", func() {
8383
for range 2 {
8484
name := randomString()
8585
i := new(initMachine)
86-
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath)).run()
86+
session, err := mb.setName(name).setCmd(i.withFakeImage(mb)).run()
8787
Expect(err).ToNot(HaveOccurred())
8888
Expect(session).To(Exit(0))
8989

pkg/machine/e2e/list_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var _ = Describe("podman machine list", func() {
2323
Expect(firstList.outputToStringSlice()).To(HaveLen(1)) // just the header
2424

2525
i := new(initMachine)
26-
session, err := mb.setCmd(i.withImage(mb.imagePath)).run()
26+
session, err := mb.setCmd(i.withFakeImage(mb)).run()
2727
Expect(err).ToNot(HaveOccurred())
2828
Expect(session).To(Exit(0))
2929

@@ -50,11 +50,11 @@ var _ = Describe("podman machine list", func() {
5050
Expect(noheaderSession.outputToStringSlice()).To(BeEmpty())
5151

5252
i := new(initMachine)
53-
session, err := mb.setName(name1).setCmd(i.withImage(mb.imagePath)).run()
53+
session, err := mb.setName(name1).setCmd(i.withFakeImage(mb)).run()
5454
Expect(err).ToNot(HaveOccurred())
5555
Expect(session).To(Exit(0))
5656

57-
session2, err := mb.setName(name2).setCmd(i.withImage(mb.imagePath)).run()
57+
session2, err := mb.setName(name2).setCmd(i.withFakeImage(mb)).run()
5858
Expect(err).ToNot(HaveOccurred())
5959
Expect(session2).To(Exit(0))
6060

@@ -72,7 +72,7 @@ var _ = Describe("podman machine list", func() {
7272
It("list machine: check if running while starting", func() {
7373
skipIfWSL("the below logic does not work on WSL. #20978")
7474
i := new(initMachine)
75-
session, err := mb.setCmd(i.withImage(mb.imagePath)).run()
75+
session, err := mb.setCmd(i.withFakeImage(mb)).run()
7676
Expect(err).ToNot(HaveOccurred())
7777
Expect(session).To(Exit(0))
7878

@@ -113,7 +113,7 @@ var _ = Describe("podman machine list", func() {
113113
name1 := randomString()
114114

115115
i := new(initMachine)
116-
session, err := mb.setName(name1).setCmd(i.withImage(mb.imagePath)).run()
116+
session, err := mb.setName(name1).setCmd(i.withFakeImage(mb)).run()
117117
Expect(err).ToNot(HaveOccurred())
118118
Expect(session).To(Exit(0))
119119

@@ -150,7 +150,7 @@ var _ = Describe("podman machine list", func() {
150150
})
151151
It("list machine in machine-readable byte format", func() {
152152
i := new(initMachine)
153-
session, err := mb.setCmd(i.withImage(mb.imagePath)).run()
153+
session, err := mb.setCmd(i.withFakeImage(mb)).run()
154154
Expect(err).ToNot(HaveOccurred())
155155
Expect(session).To(Exit(0))
156156

@@ -172,7 +172,7 @@ var _ = Describe("podman machine list", func() {
172172
})
173173
It("list machine in human-readable format", func() {
174174
i := new(initMachine)
175-
session, err := mb.setCmd(i.withImage(mb.imagePath)).run()
175+
session, err := mb.setCmd(i.withFakeImage(mb)).run()
176176
Expect(err).ToNot(HaveOccurred())
177177
Expect(session).To(Exit(0))
178178

0 commit comments

Comments
 (0)