github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/machine/e2e/inspect_test.go (about)

     1  package e2e
     2  
     3  import (
     4  	"encoding/json"
     5  	"strings"
     6  
     7  	"github.com/hanks177/podman/v4/pkg/machine"
     8  	"github.com/hanks177/podman/v4/pkg/machine/qemu"
     9  	jsoniter "github.com/json-iterator/go"
    10  
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var _ = Describe("podman machine stop", func() {
    17  	var (
    18  		mb      *machineTestBuilder
    19  		testDir string
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		testDir, mb = setup()
    24  	})
    25  	AfterEach(func() {
    26  		teardown(originalHomeDir, testDir, mb)
    27  	})
    28  
    29  	It("inspect bad name", func() {
    30  		i := inspectMachine{}
    31  		reallyLongName := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    32  		session, err := mb.setName(reallyLongName).setCmd(&i).run()
    33  		Expect(err).To(BeNil())
    34  		Expect(session).To(Exit(125))
    35  	})
    36  
    37  	It("inspect two machines", func() {
    38  		i := new(initMachine)
    39  		foo1, err := mb.setName("foo1").setCmd(i.withImagePath(mb.imagePath)).run()
    40  		Expect(err).To(BeNil())
    41  		Expect(foo1).To(Exit(0))
    42  
    43  		ii := new(initMachine)
    44  		foo2, err := mb.setName("foo2").setCmd(ii.withImagePath(mb.imagePath)).run()
    45  		Expect(err).To(BeNil())
    46  		Expect(foo2).To(Exit(0))
    47  
    48  		inspect := new(inspectMachine)
    49  		inspect = inspect.withFormat("{{.Name}}")
    50  		inspectSession, err := mb.setName("foo1").setCmd(inspect).run()
    51  		Expect(err).To(BeNil())
    52  		Expect(inspectSession).To(Exit(0))
    53  		Expect(inspectSession.Bytes()).To(ContainSubstring("foo1"))
    54  
    55  		type fakeInfos struct {
    56  			Status string
    57  			VM     qemu.MachineVM
    58  		}
    59  		infos := make([]fakeInfos, 0, 2)
    60  		err = json.Unmarshal(inspectSession.Bytes(), &infos)
    61  		Expect(err).ToNot(HaveOccurred())
    62  		Expect(len(infos)).To(Equal(2))
    63  
    64  		// rm := new(rmMachine)
    65  		// //	Must manually clean up due to multiple names
    66  		// for _, name := range []string{"foo1", "foo2"} {
    67  		//	mb.setName(name).setCmd(rm.withForce()).run()
    68  		//	mb.names = []string{}
    69  		// }
    70  		// mb.names = []string{}
    71  
    72  	})
    73  
    74  	It("inspect with go format", func() {
    75  		name := randomString(12)
    76  		i := new(initMachine)
    77  		session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
    78  		Expect(err).To(BeNil())
    79  		Expect(session).To(Exit(0))
    80  
    81  		// regular inspect should
    82  		inspectJson := new(inspectMachine)
    83  		inspectSession, err := mb.setName(name).setCmd(inspectJson).run()
    84  		Expect(err).To(BeNil())
    85  		Expect(inspectSession).To(Exit(0))
    86  
    87  		var inspectInfo []machine.InspectInfo
    88  		err = jsoniter.Unmarshal(inspectSession.Bytes(), &inspectInfo)
    89  		Expect(err).To(BeNil())
    90  		Expect(strings.HasSuffix(inspectInfo[0].ConnectionInfo.PodmanSocket.GetPath(), "podman.sock"))
    91  
    92  		inspect := new(inspectMachine)
    93  		inspect = inspect.withFormat("{{.Name}}")
    94  		inspectSession, err = mb.setName(name).setCmd(inspect).run()
    95  		Expect(err).To(BeNil())
    96  		Expect(inspectSession).To(Exit(0))
    97  		Expect(inspectSession.Bytes()).To(ContainSubstring(name))
    98  	})
    99  })