github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/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/containers/podman/v2/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.ExitCode()).To(Equal(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.ExitCode()).To(Equal(0)) 77 Expect(session.OutputToString()).To(ContainSubstring("registry")) 78 }) 79 80 It("podman info rootless storage path", func() { 81 SkipIfNotRootless("test of rootless_storage_path is only meaningful as rootless") 82 SkipIfRemote("Only tests storage on local client") 83 configPath := filepath.Join(podmanTest.TempDir, ".config", "containers", "storage.conf") 84 os.Setenv("CONTAINERS_STORAGE_CONF", configPath) 85 defer func() { 86 os.Unsetenv("CONTAINERS_STORAGE_CONF") 87 }() 88 err := os.RemoveAll(filepath.Dir(configPath)) 89 Expect(err).To(BeNil()) 90 91 err = os.MkdirAll(filepath.Dir(configPath), os.ModePerm) 92 Expect(err).To(BeNil()) 93 94 rootlessStoragePath := `"/tmp/$HOME/$USER/$UID/storage"` 95 driver := `"overlay"` 96 storageOpt := `"/usr/bin/fuse-overlayfs"` 97 storageConf := []byte(fmt.Sprintf("[storage]\ndriver=%s\nrootless_storage_path=%s\n[storage.options]\nmount_program=%s", driver, rootlessStoragePath, storageOpt)) 98 err = ioutil.WriteFile(configPath, storageConf, os.ModePerm) 99 Expect(err).To(BeNil()) 100 101 u, err := user.Current() 102 Expect(err).To(BeNil()) 103 104 expect := filepath.Join("/tmp", os.Getenv("HOME"), u.Username, u.Uid, "storage") 105 podmanPath := podmanTest.PodmanTest.PodmanBinary 106 cmd := exec.Command(podmanPath, "info", "--format", "{{.Store.GraphRoot}}") 107 out, err := cmd.CombinedOutput() 108 fmt.Println(string(out)) 109 Expect(err).To(BeNil()) 110 Expect(string(out)).To(Equal(expect)) 111 }) 112 })