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