Skip to content

Commit e76d4e0

Browse files
committed
Add tests
1 parent 8644c19 commit e76d4e0

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package e2e_test
2+
3+
type restartMachine struct {
4+
}
5+
6+
func (r restartMachine) buildCmd(m *machineTestBuilder) []string {
7+
cmd := []string{"machine", "restart"}
8+
if len(m.name) > 0 {
9+
cmd = append(cmd, m.name)
10+
}
11+
return cmd
12+
}

pkg/machine/e2e/restart_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
67+
})

0 commit comments

Comments
 (0)