github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/test/e2e/runlabel_test.go (about)

     1  // +build !remoteclient
     2  
     3  package integration
     4  
     5  import (
     6  	"os"
     7  
     8  	. "github.com/containers/libpod/test/utils"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var PodmanDockerfile = `
    14  FROM  alpine:latest
    15  LABEL RUN podman --version`
    16  
    17  var LsDockerfile = `
    18  FROM  alpine:latest
    19  LABEL RUN ls -la`
    20  
    21  var GlobalDockerfile = `
    22  FROM alpine:latest
    23  LABEL RUN echo \$GLOBAL_OPTS
    24  `
    25  
    26  var _ = Describe("podman container runlabel", func() {
    27  	var (
    28  		tempdir    string
    29  		err        error
    30  		podmanTest *PodmanTestIntegration
    31  	)
    32  
    33  	BeforeEach(func() {
    34  		tempdir, err = CreateTempDirInTempDir()
    35  		if err != nil {
    36  			os.Exit(1)
    37  		}
    38  		podmanTest = PodmanTestCreate(tempdir)
    39  		podmanTest.Setup()
    40  		podmanTest.SeedImages()
    41  	})
    42  
    43  	AfterEach(func() {
    44  		podmanTest.Cleanup()
    45  		f := CurrentGinkgoTestDescription()
    46  		processTestResult(f)
    47  
    48  	})
    49  
    50  	It("podman container runlabel (podman --version)", func() {
    51  		image := "podman-runlabel-test:podman"
    52  		podmanTest.BuildImage(PodmanDockerfile, image, "false")
    53  
    54  		result := podmanTest.Podman([]string{"container", "runlabel", "RUN", image})
    55  		result.WaitWithDefaultTimeout()
    56  		Expect(result.ExitCode()).To(Equal(0))
    57  
    58  		result = podmanTest.Podman([]string{"rmi", image})
    59  		result.WaitWithDefaultTimeout()
    60  		Expect(result.ExitCode()).To(Equal(0))
    61  	})
    62  
    63  	It("podman container runlabel (ls -la)", func() {
    64  		image := "podman-runlabel-test:ls"
    65  		podmanTest.BuildImage(LsDockerfile, image, "false")
    66  
    67  		result := podmanTest.Podman([]string{"container", "runlabel", "RUN", image})
    68  		result.WaitWithDefaultTimeout()
    69  		Expect(result.ExitCode()).To(Equal(0))
    70  
    71  		result = podmanTest.Podman([]string{"rmi", image})
    72  		result.WaitWithDefaultTimeout()
    73  		Expect(result.ExitCode()).To(Equal(0))
    74  	})
    75  	It("podman container runlabel bogus label should result in non-zero exit code", func() {
    76  		result := podmanTest.Podman([]string{"container", "runlabel", "RUN", ALPINE})
    77  		result.WaitWithDefaultTimeout()
    78  		Expect(result).To(ExitWithError())
    79  	})
    80  	It("podman container runlabel bogus label in remote image should result in non-zero exit", func() {
    81  		result := podmanTest.Podman([]string{"container", "runlabel", "RUN", "docker.io/library/ubuntu:latest"})
    82  		result.WaitWithDefaultTimeout()
    83  		Expect(result).To(ExitWithError())
    84  
    85  	})
    86  
    87  	It("podman container runlabel global options", func() {
    88  		Skip("Test nonfunctional for podman-in-podman testing")
    89  		image := "podman-global-test:ls"
    90  		podmanTest.BuildImage(GlobalDockerfile, image, "false")
    91  		result := podmanTest.Podman([]string{"--syslog", "--log-level", "debug", "container", "runlabel", "RUN", image})
    92  		result.WaitWithDefaultTimeout()
    93  		Expect(result.ExitCode()).To(Equal(0))
    94  
    95  		Expect(result.OutputToString()).To(ContainSubstring("--syslog true"))
    96  		Expect(result.OutputToString()).To(ContainSubstring("--log-level debug"))
    97  		result = podmanTest.Podman([]string{"rmi", image})
    98  		result.WaitWithDefaultTimeout()
    99  		Expect(result.ExitCode()).To(Equal(0))
   100  	})
   101  
   102  	It("runlabel should fail with nonexist authfile", func() {
   103  		SkipIfRemote()
   104  		image := "podman-runlabel-test:podman"
   105  		podmanTest.BuildImage(PodmanDockerfile, image, "false")
   106  
   107  		// runlabel should fail with nonexist authfile
   108  		result := podmanTest.Podman([]string{"container", "runlabel", "--authfile", "/tmp/nonexist", "RUN", image})
   109  		result.WaitWithDefaultTimeout()
   110  		Expect(result.ExitCode()).To(Not(Equal(0)))
   111  
   112  		result = podmanTest.Podman([]string{"rmi", image})
   113  		result.WaitWithDefaultTimeout()
   114  		Expect(result.ExitCode()).To(Equal(0))
   115  	})
   116  })