github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/version_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	. "github.com/hanks177/podman/v4/test/utils"
     8  	"github.com/hanks177/podman/v4/version"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("Podman version", 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  	})
    28  
    29  	AfterEach(func() {
    30  		podmanTest.Cleanup()
    31  		f := CurrentGinkgoTestDescription()
    32  		processTestResult(f)
    33  
    34  	})
    35  
    36  	It("podman version", func() {
    37  		session := podmanTest.Podman([]string{"version"})
    38  		session.WaitWithDefaultTimeout()
    39  		Expect(session).Should(Exit(0))
    40  		Expect(session.Out.Contents()).Should(ContainSubstring(version.Version.String()))
    41  	})
    42  
    43  	It("podman -v", func() {
    44  		session := podmanTest.Podman([]string{"-v"})
    45  		session.WaitWithDefaultTimeout()
    46  		Expect(session).Should(Exit(0))
    47  		Expect(session.Out.Contents()).Should(ContainSubstring(version.Version.String()))
    48  	})
    49  
    50  	It("podman --version", func() {
    51  		session := podmanTest.Podman([]string{"--version"})
    52  		session.WaitWithDefaultTimeout()
    53  		Expect(session).Should(Exit(0))
    54  		Expect(session.Out.Contents()).Should(ContainSubstring(version.Version.String()))
    55  	})
    56  
    57  	It("podman version --format json", func() {
    58  		tests := []struct {
    59  			input    string
    60  			success  bool
    61  			exitCode int
    62  		}{
    63  			{"json", true, 0},
    64  			{" json", true, 0},
    65  			{"json ", true, 0},
    66  			{"  json   ", true, 0},
    67  			{"{{json .}}", true, 0},
    68  			{"{{ json .}}", true, 0},
    69  			{"{{json .   }}", true, 0},
    70  			{"  {{  json .    }}   ", true, 0},
    71  			{"{{json }}", true, 0},
    72  			{"{{json .", false, 125},
    73  			{"json . }}", false, 0}, // without opening {{ template seen as string literal
    74  		}
    75  		for _, tt := range tests {
    76  			session := podmanTest.Podman([]string{"version", "--format", tt.input})
    77  			session.WaitWithDefaultTimeout()
    78  
    79  			desc := fmt.Sprintf("JSON test(%q)", tt.input)
    80  			Expect(session).Should(Exit(tt.exitCode), desc)
    81  			Expect(session.IsJSONOutputValid()).To(Equal(tt.success), desc)
    82  		}
    83  	})
    84  
    85  	It("podman version --format GO template", func() {
    86  		session := podmanTest.Podman([]string{"version", "--format", "{{ .Client.Version }}"})
    87  		session.WaitWithDefaultTimeout()
    88  		Expect(session).Should(Exit(0))
    89  
    90  		session = podmanTest.Podman([]string{"version", "--format", "{{ .Client.Os }}"})
    91  		session.WaitWithDefaultTimeout()
    92  		Expect(session).Should(Exit(0))
    93  
    94  		session = podmanTest.Podman([]string{"version", "--format", "{{ .Server.Version }}"})
    95  		session.WaitWithDefaultTimeout()
    96  		Expect(session).Should(Exit(0))
    97  
    98  		session = podmanTest.Podman([]string{"version", "--format", "{{ .Server.Os }}"})
    99  		session.WaitWithDefaultTimeout()
   100  		Expect(session).Should(Exit(0))
   101  
   102  		session = podmanTest.Podman([]string{"version", "--format", "{{ .Version }}"})
   103  		session.WaitWithDefaultTimeout()
   104  		Expect(session).Should(Exit(0))
   105  	})
   106  
   107  	It("podman help", func() {
   108  		session := podmanTest.Podman([]string{"help"})
   109  		session.WaitWithDefaultTimeout()
   110  		Expect(session).Should(Exit(0))
   111  		Expect(session.Out.Contents()).Should(
   112  			ContainSubstring("Display the Podman version information"),
   113  		)
   114  	})
   115  })