Skip to content

Commit

Permalink
[CI:MACHINE]isolate machine e2e tests
Browse files Browse the repository at this point in the history
we need machine tests to run independent of each other as much as
possible.

Signed-off-by: Brent Baude <[email protected]>
  • Loading branch information
baude committed Dec 15, 2023
1 parent 0343ffe commit 44405b9
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/machine/e2e/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var _ = Describe("run basic podman commands", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var _ = Describe("podman machine info", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var _ = Describe("podman machine init", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var _ = Describe("podman inspect stop", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var _ = Describe("podman machine list", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
55 changes: 54 additions & 1 deletion pkg/machine/e2e/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func setup() (string, *machineTestBuilder) {
if err := os.MkdirAll(filepath.Join(homeDir, ".ssh"), 0700); err != nil {
Fail(fmt.Sprintf("failed to create ssh dir: %q", err))
}
cConfDir := filepath.Join(homeDir, "containers")
if err := os.MkdirAll(cConfDir, 0755); err != nil {
Fail(fmt.Sprintf("failed to create %q: %s", cConfDir, err.Error()))
}

sshConfig, err := os.Create(filepath.Join(homeDir, ".ssh", "config"))
if err != nil {
Fail(fmt.Sprintf("failed to create ssh config: %q", err))
Expand All @@ -115,12 +120,44 @@ func setup() (string, *machineTestBuilder) {
if err := os.Setenv("HOME", homeDir); err != nil {
Fail("failed to set home dir")
}

fmt.Println("Set HOME to:", homeDir)
if err := os.Setenv("USERPROFILE", homeDir); err != nil {
Fail("failed to set USERPROFILE dir")
}

fmt.Println("Set USERPROFILE to:", homeDir)

if err := os.Setenv("XDG_RUNTIME_DIR", homeDir); err != nil {
Fail("failed to set xdg_runtime dir")
Fail("failed to set xdg_runtime_dir")
}

if err := os.Setenv("XDG_CONFIG_HOME", homeDir); err != nil {
Fail("failed to set xdg_CONFIG_HOME")
}

fmt.Println("Set XDG_CONFIG_HOME to ", homeDir)

cConf := filepath.Join(cConfDir, "containers.conf")
cc, err := os.Create(cConf)
if err != nil {
Fail("failed to create test container.conf")
}

if err := cc.Close(); err != nil {
Fail(fmt.Sprintf("unable to close file %q: %s", cConf, err.Error()))
}

if err := os.Setenv("CONTAINERS_CONF", cConf); err != nil {
Fail("failed to set CONTAINERS_CONF environment var")
}

fmt.Println("set CONTAINERS_CONF to ", cConf)

if err := os.Unsetenv("SSH_AUTH_SOCK"); err != nil {
Fail("unable to unset SSH_AUTH_SOCK")
}

mb, err := newMB()
if err != nil {
Fail(fmt.Sprintf("failed to create machine test: %q", err))
Expand All @@ -140,6 +177,7 @@ func setup() (string, *machineTestBuilder) {
if err := n.Close(); err != nil {
Fail(fmt.Sprintf("failed to close image copy handler: %q", err))
}

return homeDir, mb
}

Expand All @@ -158,3 +196,18 @@ func teardown(origHomeDir string, testDir string, mb *machineTestBuilder) {
Fail("failed to set home dir")
}
}

// dumpDebug is called after each test and can be used to display useful debug information
// about the environment
func dumpDebug(mb *machineTestBuilder, testDir string, sr SpecReport) {
if !sr.Failed() {
return
}
fmt.Println("///////// DEBUG FOR FAILURE")
fmt.Println("test dir was: ", testDir)
debugMachine := basicMachine{}
// List connections
_, _ = mb.setCmd(debugMachine.withPodmanCommand([]string{"system", "connection", "ls"})).run()
// List machines
_, _ = mb.setCmd(debugMachine.withPodmanCommand([]string{"machine", "ls"})).run()
}
1 change: 1 addition & 0 deletions pkg/machine/e2e/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var _ = Describe("podman machine proxy settings propagation", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var _ = Describe("podman machine rm", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var _ = Describe("podman machine set", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var _ = Describe("podman machine ssh", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var _ = Describe("podman machine start", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down
1 change: 1 addition & 0 deletions pkg/machine/e2e/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var _ = Describe("podman machine stop", func() {
testDir, mb = setup()
})
AfterEach(func() {
dumpDebug(mb, testDir, CurrentSpecReport())
teardown(originalHomeDir, testDir, mb)
})

Expand Down

0 comments on commit 44405b9

Please sign in to comment.