github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/test/e2e/runlabel_test.go (about)

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