summaryrefslogtreecommitdiff
path: root/pkg/machine/e2e/set_test.go
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2022-04-27 15:16:25 -0500
committerBrent Baude <bbaude@redhat.com>2022-04-27 15:44:02 -0500
commit83a75d2a3d6a6dd0661f1f44aff13639412c390b (patch)
tree530f5907adac30a42e5eac1f584d13d90f994d5e /pkg/machine/e2e/set_test.go
parent60d6cc8e1eb33be2f9822e227a7cadf0dceb5543 (diff)
downloadpodman-83a75d2a3d6a6dd0661f1f44aff13639412c390b.tar.gz
podman-83a75d2a3d6a6dd0661f1f44aff13639412c390b.tar.bz2
podman-83a75d2a3d6a6dd0661f1f44aff13639412c390b.zip
Produce better test error messages
As Ed has pointed out, the form of Expect(session).To(Exit(0)) provides much better error messages. Let's make Ed happy. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/machine/e2e/set_test.go')
-rw-r--r--pkg/machine/e2e/set_test.go59
1 files changed, 27 insertions, 32 deletions
diff --git a/pkg/machine/e2e/set_test.go b/pkg/machine/e2e/set_test.go
index 4b95bde8e..9af29c560 100644
--- a/pkg/machine/e2e/set_test.go
+++ b/pkg/machine/e2e/set_test.go
@@ -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() {
@@ -23,24 +24,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.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() {
@@ -48,61 +53,51 @@ 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.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"))
})
@@ -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"))
})