github.com/containers/podman/v4@v4.9.4/test/e2e/pod_inspect_test.go (about) 1 package integration 2 3 import ( 4 "encoding/json" 5 6 "github.com/containers/podman/v4/libpod/define" 7 . "github.com/containers/podman/v4/test/utils" 8 . "github.com/onsi/ginkgo/v2" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("Podman pod inspect", func() { 13 14 It("podman inspect bogus pod", func() { 15 session := podmanTest.Podman([]string{"pod", "inspect", "foobar"}) 16 session.WaitWithDefaultTimeout() 17 Expect(session).Should(ExitWithError()) 18 }) 19 20 It("podman inspect a pod", func() { 21 _, ec, podid := podmanTest.CreatePod(nil) 22 Expect(ec).To(Equal(0)) 23 24 session := podmanTest.RunTopContainerInPod("", podid) 25 session.WaitWithDefaultTimeout() 26 Expect(session).Should(ExitCleanly()) 27 28 session = podmanTest.RunTopContainerInPod("", podid) 29 session.WaitWithDefaultTimeout() 30 Expect(session).Should(ExitCleanly()) 31 32 inspect := podmanTest.Podman([]string{"pod", "inspect", podid}) 33 inspect.WaitWithDefaultTimeout() 34 Expect(inspect).Should(ExitCleanly()) 35 Expect(inspect.OutputToString()).To(BeValidJSON()) 36 podData := inspect.InspectPodToJSON() 37 Expect(podData).To(HaveField("ID", podid)) 38 }) 39 40 It("podman pod inspect (CreateCommand)", func() { 41 podName := "myTestPod" 42 createCommand := []string{"pod", "create", "--name", podName, "--hostname", "rudolph", "--share", "net"} 43 44 // Create the pod. 45 session := podmanTest.Podman(createCommand) 46 session.WaitWithDefaultTimeout() 47 Expect(session).Should(ExitCleanly()) 48 49 // Inspect the pod and make sure that the create command is 50 // exactly how we created the pod. 51 inspect := podmanTest.Podman([]string{"pod", "inspect", podName}) 52 inspect.WaitWithDefaultTimeout() 53 Expect(inspect).Should(ExitCleanly()) 54 Expect(inspect.OutputToString()).To(BeValidJSON()) 55 podData := inspect.InspectPodToJSON() 56 // Let's get the last len(createCommand) items in the command. 57 inspectCreateCommand := podData.CreateCommand 58 index := len(inspectCreateCommand) - len(createCommand) 59 Expect(inspectCreateCommand[index:]).To(Equal(createCommand)) 60 }) 61 62 It("podman pod inspect outputs port bindings", func() { 63 podName := "testPod" 64 create := podmanTest.Podman([]string{"pod", "create", "--name", podName, "-p", "8383:80"}) 65 create.WaitWithDefaultTimeout() 66 Expect(create).Should(ExitCleanly()) 67 68 inspectOut := podmanTest.Podman([]string{"pod", "inspect", podName}) 69 inspectOut.WaitWithDefaultTimeout() 70 Expect(inspectOut).Should(ExitCleanly()) 71 72 inspectJSON := new(define.InspectPodData) 73 err := json.Unmarshal(inspectOut.Out.Contents(), inspectJSON) 74 Expect(err).ToNot(HaveOccurred()) 75 Expect(inspectJSON.InfraConfig).To(Not(BeNil())) 76 Expect(inspectJSON.InfraConfig.PortBindings["80/tcp"]).To(HaveLen(1)) 77 Expect(inspectJSON.InfraConfig.PortBindings["80/tcp"][0]).To(HaveField("HostPort", "8383")) 78 }) 79 80 It("podman pod inspect outputs show correct MAC", func() { 81 SkipIfRootless("--mac-address is not supported in rootless mode without network") 82 podName := "testPod" 83 macAddr := "42:43:44:00:00:01" 84 create := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--mac-address", macAddr}) 85 create.WaitWithDefaultTimeout() 86 Expect(create).Should(ExitCleanly()) 87 88 create = podmanTest.Podman([]string{"run", "-d", "--pod", podName, ALPINE, "top"}) 89 create.WaitWithDefaultTimeout() 90 Expect(create).Should(ExitCleanly()) 91 92 inspectOut := podmanTest.Podman([]string{"pod", "inspect", podName}) 93 inspectOut.WaitWithDefaultTimeout() 94 Expect(inspectOut).Should(ExitCleanly()) 95 96 Expect(inspectOut.OutputToString()).To(ContainSubstring(macAddr)) 97 }) 98 99 It("podman inspect two pods", func() { 100 _, ec, podid1 := podmanTest.CreatePod(nil) 101 Expect(ec).To(Equal(0)) 102 103 _, ec, podid2 := podmanTest.CreatePod(nil) 104 Expect(ec).To(Equal(0)) 105 106 inspect := podmanTest.Podman([]string{"pod", "inspect", podid1, podid2}) 107 inspect.WaitWithDefaultTimeout() 108 Expect(inspect).Should(ExitCleanly()) 109 Expect(inspect.OutputToString()).To(BeValidJSON()) 110 podData := inspect.InspectPodArrToJSON() 111 Expect(podData).To(HaveLen(2)) 112 Expect(podData[0]).To(HaveField("ID", podid1)) 113 Expect(podData[1]).To(HaveField("ID", podid2)) 114 }) 115 })