github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/info_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "os/exec" 8 "os/user" 9 "path/filepath" 10 11 . "github.com/hanks177/podman/v4/test/utils" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 . "github.com/onsi/gomega/gexec" 15 ) 16 17 var _ = Describe("Podman Info", func() { 18 var ( 19 tempdir string 20 err error 21 podmanTest *PodmanTestIntegration 22 ) 23 24 BeforeEach(func() { 25 tempdir, err = CreateTempDirInTempDir() 26 if err != nil { 27 os.Exit(1) 28 } 29 podmanTest = PodmanTestCreate(tempdir) 30 podmanTest.Setup() 31 }) 32 33 AfterEach(func() { 34 podmanTest.Cleanup() 35 f := CurrentGinkgoTestDescription() 36 processTestResult(f) 37 }) 38 39 It("podman info --format json", func() { 40 tests := []struct { 41 input string 42 success bool 43 exitCode int 44 }{ 45 {"json", true, 0}, 46 {" json", true, 0}, 47 {"json ", true, 0}, 48 {" json ", true, 0}, 49 {"{{json .}}", true, 0}, 50 {"{{ json .}}", true, 0}, 51 {"{{json . }}", true, 0}, 52 {" {{ json . }} ", true, 0}, 53 {"{{json }}", true, 0}, 54 {"{{json .", false, 125}, 55 {"json . }}", false, 0}, // without opening {{ template seen as string literal 56 } 57 for _, tt := range tests { 58 session := podmanTest.Podman([]string{"info", "--format", tt.input}) 59 session.WaitWithDefaultTimeout() 60 61 desc := fmt.Sprintf("JSON test(%q)", tt.input) 62 Expect(session).Should(Exit(tt.exitCode), desc) 63 Expect(session.IsJSONOutputValid()).To(Equal(tt.success), desc) 64 } 65 }) 66 67 It("podman info --format GO template", func() { 68 session := podmanTest.Podman([]string{"info", "--format", "{{.Store.GraphRoot}}"}) 69 session.WaitWithDefaultTimeout() 70 Expect(session).Should(Exit(0)) 71 }) 72 73 It("podman info --format GO template", func() { 74 session := podmanTest.Podman([]string{"info", "--format", "{{.Registries}}"}) 75 session.WaitWithDefaultTimeout() 76 Expect(session).Should(Exit(0)) 77 Expect(session.OutputToString()).To(ContainSubstring("registry")) 78 }) 79 80 It("podman info --format GO template plugins", func() { 81 session := podmanTest.Podman([]string{"info", "--format", "{{.Plugins}}"}) 82 session.WaitWithDefaultTimeout() 83 Expect(session).Should(Exit(0)) 84 Expect(session.OutputToString()).To(ContainSubstring("local")) 85 Expect(session.OutputToString()).To(ContainSubstring("journald")) 86 Expect(session.OutputToString()).To(ContainSubstring("bridge")) 87 }) 88 89 It("podman info rootless storage path", func() { 90 SkipIfNotRootless("test of rootless_storage_path is only meaningful as rootless") 91 SkipIfRemote("Only tests storage on local client") 92 configPath := filepath.Join(podmanTest.TempDir, ".config", "containers", "storage.conf") 93 os.Setenv("CONTAINERS_STORAGE_CONF", configPath) 94 defer func() { 95 os.Unsetenv("CONTAINERS_STORAGE_CONF") 96 }() 97 err := os.RemoveAll(filepath.Dir(configPath)) 98 Expect(err).To(BeNil()) 99 100 err = os.MkdirAll(filepath.Dir(configPath), os.ModePerm) 101 Expect(err).To(BeNil()) 102 103 rootlessStoragePath := `"/tmp/$HOME/$USER/$UID/storage"` 104 driver := `"overlay"` 105 storageOpt := `"/usr/bin/fuse-overlayfs"` 106 storageConf := []byte(fmt.Sprintf("[storage]\ndriver=%s\nrootless_storage_path=%s\n[storage.options]\nmount_program=%s", driver, rootlessStoragePath, storageOpt)) 107 err = ioutil.WriteFile(configPath, storageConf, os.ModePerm) 108 Expect(err).To(BeNil()) 109 110 u, err := user.Current() 111 Expect(err).To(BeNil()) 112 113 // Cannot use podmanTest.Podman() and test for storage path 114 expect := filepath.Join("/tmp", os.Getenv("HOME"), u.Username, u.Uid, "storage") 115 podmanPath := podmanTest.PodmanTest.PodmanBinary 116 cmd := exec.Command(podmanPath, "info", "--format", "{{.Store.GraphRoot -}}") 117 out, err := cmd.CombinedOutput() 118 Expect(err).To(BeNil()) 119 Expect(string(out)).To(Equal(expect)) 120 }) 121 122 It("check RemoteSocket ", func() { 123 session := podmanTest.Podman([]string{"info", "--format", "{{.Host.RemoteSocket.Path}}"}) 124 session.WaitWithDefaultTimeout() 125 Expect(session).Should(Exit(0)) 126 Expect(session.OutputToString()).To(MatchRegexp("/run/.*podman.*sock")) 127 128 session = podmanTest.Podman([]string{"info", "--format", "{{.Host.ServiceIsRemote}}"}) 129 session.WaitWithDefaultTimeout() 130 Expect(session).Should(Exit(0)) 131 if podmanTest.RemoteTest { 132 Expect(session.OutputToString()).To(Equal("true")) 133 } else { 134 Expect(session.OutputToString()).To(Equal("false")) 135 } 136 137 session = podmanTest.Podman([]string{"info", "--format", "{{.Host.RemoteSocket.Exists}}"}) 138 session.WaitWithDefaultTimeout() 139 Expect(session).Should(Exit(0)) 140 if IsRemote() { 141 Expect(session.OutputToString()).To(ContainSubstring("true")) 142 } 143 144 }) 145 146 It("Podman info must contain cgroupControllers with RelevantControllers", func() { 147 SkipIfRootless("Hard to tell which controllers are going to be enabled for rootless") 148 SkipIfRootlessCgroupsV1("Disable cgroups not supported on cgroupv1 for rootless users") 149 session := podmanTest.Podman([]string{"info", "--format", "{{.Host.CgroupControllers}}"}) 150 session.WaitWithDefaultTimeout() 151 Expect(session).To(Exit(0)) 152 Expect(session.OutputToString()).To(ContainSubstring("memory")) 153 Expect(session.OutputToString()).To(ContainSubstring("pids")) 154 }) 155 })