spiegel_podman/pkg/machine/e2e/restart_test.go
Paul Holzinger f4df65a859
pkg/machine/e2e: combine two restart machine tests
The restart tests are rather slow. On the linux CI 60 seconds for the
stopped case and almost 120 seconds for the restart running case.

Combine both cases into one so we only have to start a machine twice,
not three times and only need to init it once.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2026-09-08 12:16:43 +02:00

60 lines
2 KiB
Go

package e2e_test
import (
"fmt"
"go.podman.io/podman/v6/pkg/machine/define"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("podman machine restart", func() {
It("should tell you when trying to restart a machine that doesn't exist", func() {
r := restartMachine{}
name := "aVMThatDoesntExist"
session, err := mb.setName(name).setCmd(r).run()
Expect(err).ToNot(HaveOccurred())
Expect(session).To(Exit(125))
Expect(session.errorToString()).To(ContainSubstring("VM does not exist"))
})
It("should restart machine", func() {
name := randomString()
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withVolume("")).run()
Expect(err).ToNot(HaveOccurred())
Expect(session).To(Exit(0))
inspect := new(inspectMachine)
inspectSession, err := mb.setName(name).setCmd(inspect.withFormat("{{.State}}")).run()
Expect(err).ToNot(HaveOccurred())
Expect(inspectSession).To(Exit(0))
Expect(inspectSession.outputToString()).To(Equal(define.Stopped))
// Restart stopped machine
r := restartMachine{}
restartSession, err := mb.setName(name).setCmd(r).run()
Expect(err).ToNot(HaveOccurred())
Expect(restartSession).To(Exit(0))
inspectSession, err = mb.setName(name).setCmd(inspect.withFormat("{{.State}}")).run()
Expect(err).ToNot(HaveOccurred())
Expect(inspectSession).To(Exit(0))
Expect(inspectSession.outputToString()).To(Equal(define.Running))
// Now restart running machine
r = restartMachine{}
restartSession, err = mb.setName(name).setCmd(r).run()
Expect(err).ToNot(HaveOccurred())
Expect(restartSession).To(Exit(0))
Expect(restartSession.outputToString()).To(ContainSubstring(fmt.Sprintf("Machine %q restarted successfully", name)))
inspect = new(inspectMachine)
inspectSession, err = mb.setName(name).setCmd(inspect.withFormat("{{.State}}")).run()
Expect(err).ToNot(HaveOccurred())
Expect(inspectSession).To(Exit(0))
Expect(inspectSession.outputToString()).To(Equal(define.Running))
})
})