diff --git a/pkg/machine/e2e/start_test.go b/pkg/machine/e2e/start_test.go index 6832c39415..c1660ca2c4 100644 --- a/pkg/machine/e2e/start_test.go +++ b/pkg/machine/e2e/start_test.go @@ -28,7 +28,7 @@ var _ = Describe("podman machine start", func() { Expect(session.errorToString()).To(ContainSubstring("VM does not exist")) }) - It("start machine already started", func() { + It("start machine already started and stop machine already stopped", func() { name := randomString() i := new(initMachine) machineTestBuilderInit := mb.setName(name).setCmd(i.withImage(mb.imagePath)) @@ -36,6 +36,7 @@ var _ = Describe("podman machine start", func() { Expect(err).ToNot(HaveOccurred()) Expect(session).To(Exit(0)) + starttime := time.Now() s := new(startMachine) // suppress output with no info and check for that. startSession, err := mb.setCmd(s.withNoInfo()).run() @@ -52,6 +53,26 @@ var _ = Describe("podman machine start", func() { Expect(err).ToNot(HaveOccurred()) Expect(startSession).To(Exit(125)) Expect(startSession.errorToString()).To(ContainSubstring(fmt.Sprintf("Error: unable to start %q: already running", machineTestBuilderInit.name))) + + stop := new(stopMachine) + stopSession, err := mb.setCmd(stop).run() + Expect(err).ToNot(HaveOccurred()) + Expect(stopSession).To(Exit(0)) + + // Stopping it again should not result in an error + stopAgain, err := mb.setCmd(stop).run() + Expect(err).ToNot(HaveOccurred()) + Expect(stopAgain).To(Exit(0)) + Expect(stopAgain.outputToString()).To(ContainSubstring(fmt.Sprintf("Machine \"%s\" stopped successfully", name))) + + // Stopping a machine should update the last up time + inspect := new(inspectMachine) + inspectSession, err := mb.setName(name).setCmd(inspect.withFormat("{{.LastUp.Format \"2006-01-02T15:04:05Z07:00\"}}")).run() + Expect(err).ToNot(HaveOccurred()) + Expect(inspectSession).To(Exit(0)) + lastupTime, err := time.Parse(time.RFC3339, inspectSession.outputToString()) + Expect(err).ToNot(HaveOccurred()) + Expect(lastupTime).To(BeTemporally(">", starttime)) }) It("start machine with conflict on SSH port", func() { diff --git a/pkg/machine/e2e/stop_test.go b/pkg/machine/e2e/stop_test.go index e026386622..6269e60f35 100644 --- a/pkg/machine/e2e/stop_test.go +++ b/pkg/machine/e2e/stop_test.go @@ -1,9 +1,6 @@ package e2e_test import ( - "fmt" - "time" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" @@ -17,33 +14,4 @@ var _ = Describe("podman machine stop", func() { Expect(err).ToNot(HaveOccurred()) Expect(session).To(Exit(125)) }) - - It("Stop running machine", func() { - name := randomString() - i := new(initMachine) - starttime := time.Now() - session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withNow()).run() - Expect(err).ToNot(HaveOccurred()) - Expect(session).To(Exit(0)) - - stop := new(stopMachine) - stopSession, err := mb.setCmd(stop).run() - Expect(err).ToNot(HaveOccurred()) - Expect(stopSession).To(Exit(0)) - - // Stopping it again should not result in an error - stopAgain, err := mb.setCmd(stop).run() - Expect(err).ToNot(HaveOccurred()) - Expect(stopAgain).To(Exit(0)) - Expect(stopAgain.outputToString()).To(ContainSubstring(fmt.Sprintf("Machine \"%s\" stopped successfully", name))) - - // Stopping a machine should update the last up time - inspect := new(inspectMachine) - inspectSession, err := mb.setName(name).setCmd(inspect.withFormat("{{.LastUp.Format \"2006-01-02T15:04:05Z07:00\"}}")).run() - Expect(err).ToNot(HaveOccurred()) - Expect(inspectSession).To(Exit(0)) - lastupTime, err := time.Parse(time.RFC3339, inspectSession.outputToString()) - Expect(err).ToNot(HaveOccurred()) - Expect(lastupTime).To(BeTemporally(">", starttime)) - }) })