github.com/containers/podman/v4@v4.9.4/pkg/machine/e2e/stop_test.go (about)

     1  package e2e_test
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	. "github.com/onsi/ginkgo/v2"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("podman machine stop", func() {
    13  	var (
    14  		mb      *machineTestBuilder
    15  		testDir string
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		testDir, mb = setup()
    20  	})
    21  	AfterEach(func() {
    22  		teardown(originalHomeDir, testDir, mb)
    23  	})
    24  
    25  	It("stop bad name", func() {
    26  		i := stopMachine{}
    27  		reallyLongName := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    28  		session, err := mb.setName(reallyLongName).setCmd(&i).run()
    29  		Expect(err).ToNot(HaveOccurred())
    30  		Expect(session).To(Exit(125))
    31  	})
    32  
    33  	It("Stop running machine", func() {
    34  		name := randomString()
    35  		i := new(initMachine)
    36  		starttime := time.Now()
    37  		session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withNow()).run()
    38  		Expect(err).ToNot(HaveOccurred())
    39  		Expect(session).To(Exit(0))
    40  
    41  		stop := new(stopMachine)
    42  		stopSession, err := mb.setCmd(stop).run()
    43  		Expect(err).ToNot(HaveOccurred())
    44  		Expect(stopSession).To(Exit(0))
    45  
    46  		// Stopping it again should not result in an error
    47  		stopAgain, err := mb.setCmd(stop).run()
    48  		Expect(err).ToNot(HaveOccurred())
    49  		Expect(stopAgain).To(Exit(0))
    50  		Expect(stopAgain.outputToString()).To(ContainSubstring(fmt.Sprintf("Machine \"%s\" stopped successfully", name)))
    51  
    52  		// Stopping a machine should update the last up time
    53  		inspect := new(inspectMachine)
    54  		inspectSession, err := mb.setName(name).setCmd(inspect.withFormat("{{.LastUp.Format \"2006-01-02T15:04:05Z07:00\"}}")).run()
    55  		Expect(err).ToNot(HaveOccurred())
    56  		Expect(inspectSession).To(Exit(0))
    57  		lastupTime, err := time.Parse(time.RFC3339, inspectSession.outputToString())
    58  		Expect(err).ToNot(HaveOccurred())
    59  		Expect(lastupTime).To(BeTemporally(">", starttime))
    60  	})
    61  })