Skip to content

Commit

Permalink
Merge pull request containers#14038 from baude/exited
Browse files Browse the repository at this point in the history
Produce better test error messages
  • Loading branch information
openshift-merge-robot authored Apr 27, 2022
2 parents 5b8db20 + 83a75d2 commit 78c66fb
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 55 deletions.
6 changes: 3 additions & 3 deletions pkg/machine/e2e/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ var _ = Describe("podman machine init", func() {
reallyLongName := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
session, err := mb.setName(reallyLongName).setCmd(&i).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(125))
Expect(session).To(Exit(125))
})
It("simple init", func() {
i := new(initMachine)
session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))
Expect(session).To(Exit(0))

inspectBefore, ec, err := mb.toQemuInspectInfo()
Expect(err).To(BeNil())
Expand All @@ -52,7 +52,7 @@ var _ = Describe("podman machine init", func() {
i := initMachine{}
session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))
Expect(session).To(Exit(0))

inspectBefore, ec, err := mb.toQemuInspectInfo()
Expect(ec).To(BeZero())
Expand Down
9 changes: 5 additions & 4 deletions pkg/machine/e2e/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("podman machine stop", func() {
Expand All @@ -27,24 +28,24 @@ var _ = Describe("podman machine stop", func() {
reallyLongName := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
session, err := mb.setName(reallyLongName).setCmd(&i).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(125))
Expect(session).To(Exit(125))
})

It("inspect two machines", func() {
i := new(initMachine)
foo1, err := mb.setName("foo1").setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(foo1.ExitCode()).To(Equal(0))
Expect(foo1).To(Exit(0))

ii := new(initMachine)
foo2, err := mb.setName("foo2").setCmd(ii.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(foo2.ExitCode()).To(Equal(0))
Expect(foo2).To(Exit(0))

inspect := new(inspectMachine)
inspectSession, err := mb.setName("foo1").setCmd(inspect).run()
Expect(err).To(BeNil())
Expect(inspectSession.ExitCode()).To(Equal(0))
Expect(inspectSession).To(Exit(0))

type fakeInfos struct {
Status string
Expand Down
11 changes: 6 additions & 5 deletions pkg/machine/e2e/rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("podman machine rm", func() {
Expand All @@ -23,14 +24,14 @@ var _ = Describe("podman machine rm", func() {
reallyLongName := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
session, err := mb.setName(reallyLongName).setCmd(&i).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(125))
Expect(session).To(Exit(125))
})

It("Remove machine", func() {
i := new(initMachine)
session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))
Expect(session).To(Exit(0))
rm := rmMachine{}
_, err = mb.setCmd(rm.withForce()).run()
Expect(err).To(BeNil())
Expand All @@ -46,18 +47,18 @@ var _ = Describe("podman machine rm", func() {
i := new(initMachine)
session, err := mb.setCmd(i.withImagePath(mb.imagePath).withNow()).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))
Expect(session).To(Exit(0))
rm := new(rmMachine)

// Removing a running machine should fail
stop, err := mb.setCmd(rm).run()
Expect(err).To(BeNil())
Expect(stop.ExitCode()).To(Equal(125))
Expect(stop).To(Exit(125))

// Removing again with force
stopAgain, err := mb.setCmd(rm.withForce()).run()
Expect(err).To(BeNil())
Expect(stopAgain.ExitCode()).To(BeZero())
Expect(stopAgain).To(Exit(0))

// Inspect to be dead sure
_, ec, err := mb.toQemuInspectInfo()
Expand Down
59 changes: 27 additions & 32 deletions pkg/machine/e2e/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("podman machine set", func() {
Expand All @@ -23,86 +24,80 @@ var _ = Describe("podman machine set", func() {
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))
Expect(session).To(Exit(0))

set := setMachine{}
setSession, err := mb.setName(name).setCmd(set.withCPUs(2)).run()
Expect(err).To(BeNil())
Expect(setSession.ExitCode()).To(Equal(0))
Expect(setSession).To(Exit(0))

s := new(startMachine)
startSession, err := mb.setCmd(s).run()
Expect(err).To(BeNil())
Expect(startSession.ExitCode()).To(Equal(0))
Expect(startSession).To(Exit(0))

ssh2 := sshMachine{}
sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"lscpu", "|", "grep", "\"CPU(s):\"", "|", "head", "-1"})).run()
Expect(err).To(BeNil())
Expect(sshSession2.ExitCode()).To(Equal(0))
Expect(sshSession2).To(Exit(0))
Expect(sshSession2.outputToString()).To(ContainSubstring("2"))

// Setting a running machine results in 125
runner, err := mb.setName(name).setCmd(set.withCPUs(4)).run()
Expect(err).To(BeNil())
Expect(runner).To(Exit(125))
})

It("increase machine disk size", func() {
name := randomString(12)
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))
Expect(session).To(Exit(0))

set := setMachine{}
setSession, err := mb.setName(name).setCmd(set.withDiskSize(102)).run()
Expect(err).To(BeNil())
Expect(setSession.ExitCode()).To(Equal(0))
Expect(setSession).To(Exit(0))

// shrinking disk size iss verboten
shrink, err := mb.setName(name).setCmd(set.withDiskSize(5)).run()
Expect(err).To(BeNil())
Expect(shrink).To(Exit(125))

s := new(startMachine)
startSession, err := mb.setCmd(s).run()
Expect(err).To(BeNil())
Expect(startSession.ExitCode()).To(Equal(0))
Expect(startSession).To(Exit(0))

ssh2 := sshMachine{}
sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run()
Expect(err).To(BeNil())
Expect(sshSession2.ExitCode()).To(Equal(0))
Expect(sshSession2).To(Exit(0))
Expect(sshSession2.outputToString()).To(ContainSubstring("102 GiB"))
})

It("decrease machine disk size should fail", func() {
name := randomString(12)
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))

set := setMachine{}
setSession, _ := mb.setName(name).setCmd(set.withDiskSize(50)).run()
// TODO seems like stderr is not being returned; re-enabled when fixed
// Expect(err).To(BeNil())
Expect(setSession.ExitCode()).To(Not(Equal(0)))
})

It("set machine ram", func() {

name := randomString(12)
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))
Expect(session).To(Exit(0))

set := setMachine{}
setSession, err := mb.setName(name).setCmd(set.withMemory(4000)).run()
Expect(err).To(BeNil())
Expect(setSession.ExitCode()).To(Equal(0))
Expect(setSession).To(Exit(0))

s := new(startMachine)
startSession, err := mb.setCmd(s).run()
Expect(err).To(BeNil())
Expect(startSession.ExitCode()).To(Equal(0))
Expect(startSession).To(Exit(0))

ssh2 := sshMachine{}
sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"cat", "/proc/meminfo", "|", "numfmt", "--field", "2", "--from-unit=Ki", "--to-unit=Mi", "|", "sed", "'s/ kB/M/g'", "|", "grep", "MemTotal"})).run()
Expect(err).To(BeNil())
Expect(sshSession2.ExitCode()).To(Equal(0))
Expect(sshSession2).To(Exit(0))
Expect(sshSession2.outputToString()).To(ContainSubstring("3824"))
})

Expand All @@ -111,28 +106,28 @@ var _ = Describe("podman machine set", func() {
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))
Expect(session).To(Exit(0))

set := setMachine{}
setSession, err := mb.setName(name).setCmd(&set).run()
Expect(err).To(BeNil())
Expect(setSession.ExitCode()).To(Equal(0))
Expect(setSession).To(Exit(0))

s := new(startMachine)
startSession, err := mb.setCmd(s).run()
Expect(err).To(BeNil())
Expect(startSession.ExitCode()).To(Equal(0))
Expect(startSession).To(Exit(0))

ssh2 := sshMachine{}
sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"lscpu", "|", "grep", "\"CPU(s):\"", "|", "head", "-1"})).run()
Expect(err).To(BeNil())
Expect(sshSession2.ExitCode()).To(Equal(0))
Expect(sshSession2).To(Exit(0))
Expect(sshSession2.outputToString()).To(ContainSubstring("1"))

ssh3 := sshMachine{}
sshSession3, err := mb.setName(name).setCmd(ssh3.withSSHComand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run()
Expect(err).To(BeNil())
Expect(sshSession3.ExitCode()).To(Equal(0))
Expect(sshSession3).To(Exit(0))
Expect(sshSession3.outputToString()).To(ContainSubstring("100 GiB"))
})

Expand Down
11 changes: 6 additions & 5 deletions pkg/machine/e2e/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("podman machine ssh", func() {
Expand All @@ -23,7 +24,7 @@ var _ = Describe("podman machine ssh", func() {
ssh := sshMachine{}
session, err := mb.setName(name).setCmd(ssh).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(125))
Expect(session).To(Exit(125))
// TODO seems like stderr is not being returned; re-enabled when fixed
//Expect(session.outputToString()).To(ContainSubstring("not exist"))
})
Expand All @@ -33,27 +34,27 @@ var _ = Describe("podman machine ssh", func() {
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))
Expect(session).To(Exit(0))

ssh := sshMachine{}
sshSession, err := mb.setName(name).setCmd(ssh).run()
Expect(err).To(BeNil())
// TODO seems like stderr is not being returned; re-enabled when fixed
//Expect(sshSession.outputToString()).To(ContainSubstring("is not running"))
Expect(sshSession.ExitCode()).To(Equal(125))
Expect(sshSession).To(Exit(125))
})

It("ssh to running machine and check os-type", func() {
name := randomString(12)
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withNow()).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))
Expect(session).To(Exit(0))

ssh := sshMachine{}
sshSession, err := mb.setName(name).setCmd(ssh.withSSHComand([]string{"cat", "/etc/os-release"})).run()
Expect(err).To(BeNil())
Expect(sshSession.ExitCode()).To(Equal(0))
Expect(sshSession).To(Exit(0))
Expect(sshSession.outputToString()).To(ContainSubstring("Fedora CoreOS"))
})
})
5 changes: 3 additions & 2 deletions pkg/machine/e2e/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/containers/podman/v4/pkg/machine"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("podman machine start", func() {
Expand All @@ -22,11 +23,11 @@ var _ = Describe("podman machine start", func() {
i := new(initMachine)
session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))
Expect(session).To(Exit(0))
s := new(startMachine)
startSession, err := mb.setCmd(s).run()
Expect(err).To(BeNil())
Expect(startSession.ExitCode()).To(Equal(0))
Expect(startSession).To(Exit(0))

info, ec, err := mb.toQemuInspectInfo()
Expect(err).To(BeNil())
Expand Down
9 changes: 5 additions & 4 deletions pkg/machine/e2e/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("podman machine stop", func() {
Expand All @@ -23,24 +24,24 @@ var _ = Describe("podman machine stop", func() {
reallyLongName := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
session, err := mb.setName(reallyLongName).setCmd(&i).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(125))
Expect(session).To(Exit(125))
})

It("Stop running machine", func() {
i := new(initMachine)
session, err := mb.setCmd(i.withImagePath(mb.imagePath).withNow()).run()
Expect(err).To(BeNil())
Expect(session.ExitCode()).To(Equal(0))
Expect(session).To(Exit(0))

stop := new(stopMachine)
// Removing a running machine should fail
stopSession, err := mb.setCmd(stop).run()
Expect(err).To(BeNil())
Expect(stopSession.ExitCode()).To(Equal(0))
Expect(stopSession).To(Exit(0))

// Stopping it again should not result in an error
stopAgain, err := mb.setCmd(stop).run()
Expect(err).To(BeNil())
Expect(stopAgain.ExitCode()).To(BeZero())
Expect(stopAgain).To(Exit((0)))
})
})

0 comments on commit 78c66fb

Please sign in to comment.