|
| 1 | +package e2e_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "go.podman.io/podman/v6/pkg/machine/define" |
| 7 | + |
| 8 | + . "github.com/onsi/ginkgo/v2" |
| 9 | + . "github.com/onsi/gomega" |
| 10 | + . "github.com/onsi/gomega/gexec" |
| 11 | +) |
| 12 | + |
| 13 | +var _ = Describe("podman machine restart", func() { |
| 14 | + It("should tell you when trying to restart a machine that doesn't exist", func() { |
| 15 | + r := restartMachine{} |
| 16 | + name := "aVMThatDoesntExist" |
| 17 | + session, err := mb.setName(name).setCmd(r).run() |
| 18 | + Expect(err).ToNot(HaveOccurred()) |
| 19 | + Expect(session).To(Exit(125)) |
| 20 | + Expect(session.errorToString()).To(ContainSubstring("VM does not exist")) |
| 21 | + }) |
| 22 | + |
| 23 | + It("should restart a running machine", func() { |
| 24 | + name := randomString() |
| 25 | + i := new(initMachine) |
| 26 | + session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withNow().withVolume("")).run() |
| 27 | + Expect(err).ToNot(HaveOccurred()) |
| 28 | + Expect(session).To(Exit(0)) |
| 29 | + |
| 30 | + r := restartMachine{} |
| 31 | + restartSession, err := mb.setName(name).setCmd(r).run() |
| 32 | + Expect(err).ToNot(HaveOccurred()) |
| 33 | + Expect(restartSession).To(Exit(0)) |
| 34 | + Expect(restartSession.outputToString()).To(ContainSubstring(fmt.Sprintf("Machine %q restarted successfully", name))) |
| 35 | + |
| 36 | + inspect := new(inspectMachine) |
| 37 | + inspectSession, err := mb.setName(name).setCmd(inspect.withFormat("{{.State}}")).run() |
| 38 | + Expect(err).ToNot(HaveOccurred()) |
| 39 | + Expect(inspectSession).To(Exit(0)) |
| 40 | + Expect(inspectSession.outputToString()).To(Equal(define.Running)) |
| 41 | + }) |
| 42 | + |
| 43 | + It("should start a stopped machine", func() { |
| 44 | + name := randomString() |
| 45 | + i := new(initMachine) |
| 46 | + session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withVolume("")).run() |
| 47 | + Expect(err).ToNot(HaveOccurred()) |
| 48 | + Expect(session).To(Exit(0)) |
| 49 | + |
| 50 | + inspect := new(inspectMachine) |
| 51 | + inspectSession, err := mb.setName(name).setCmd(inspect.withFormat("{{.State}}")).run() |
| 52 | + Expect(err).ToNot(HaveOccurred()) |
| 53 | + Expect(inspectSession).To(Exit(0)) |
| 54 | + Expect(inspectSession.outputToString()).To(Equal(define.Stopped)) |
| 55 | + |
| 56 | + r := restartMachine{} |
| 57 | + restartSession, err := mb.setName(name).setCmd(r).run() |
| 58 | + Expect(err).ToNot(HaveOccurred()) |
| 59 | + Expect(restartSession).To(Exit(0)) |
| 60 | + |
| 61 | + inspectSession, err = mb.setName(name).setCmd(inspect.withFormat("{{.State}}")).run() |
| 62 | + Expect(err).ToNot(HaveOccurred()) |
| 63 | + Expect(inspectSession).To(Exit(0)) |
| 64 | + Expect(inspectSession.outputToString()).To(Equal(define.Running)) |
| 65 | + }) |
| 66 | +}) |
0 commit comments