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

     1  package integration
     2  
     3  import (
     4  	"os"
     5  
     6  	. "github.com/hanks177/podman/v4/test/utils"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("Podman run entrypoint", func() {
    13  	var (
    14  		tempdir    string
    15  		err        error
    16  		podmanTest *PodmanTestIntegration
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		tempdir, err = CreateTempDirInTempDir()
    21  		if err != nil {
    22  			os.Exit(1)
    23  		}
    24  		podmanTest = PodmanTestCreate(tempdir)
    25  		podmanTest.Setup()
    26  	})
    27  
    28  	AfterEach(func() {
    29  		podmanTest.Cleanup()
    30  		f := CurrentGinkgoTestDescription()
    31  		processTestResult(f)
    32  
    33  	})
    34  
    35  	It("podman run no command, entrypoint, or cmd", func() {
    36  		dockerfile := `FROM quay.io/libpod/alpine:latest
    37  ENTRYPOINT []
    38  CMD []
    39  `
    40  		podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
    41  		session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"})
    42  		session.WaitWithDefaultTimeout()
    43  		Expect(session).Should(Exit(125))
    44  	})
    45  
    46  	It("podman run entrypoint == [\"\"]", func() {
    47  		dockerfile := `FROM quay.io/libpod/alpine:latest
    48  ENTRYPOINT [""]
    49  CMD []
    50  `
    51  		podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
    52  		session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest", "echo", "hello"})
    53  		session.WaitWithDefaultTimeout()
    54  		Expect(session).Should(Exit(0))
    55  		Expect(session.OutputToString()).To(Equal("hello"))
    56  	})
    57  
    58  	It("podman run entrypoint", func() {
    59  		dockerfile := `FROM quay.io/libpod/alpine:latest
    60  ENTRYPOINT ["grep", "Alpine", "/etc/os-release"]
    61  `
    62  		podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
    63  		session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"})
    64  		session.WaitWithDefaultTimeout()
    65  		Expect(session).Should(Exit(0))
    66  		Expect(session.OutputToStringArray()).To(HaveLen(2))
    67  	})
    68  
    69  	It("podman run entrypoint with cmd", func() {
    70  		dockerfile := `FROM quay.io/libpod/alpine:latest
    71  CMD [ "-v"]
    72  ENTRYPOINT ["grep", "Alpine", "/etc/os-release"]
    73  `
    74  		podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
    75  		session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"})
    76  		session.WaitWithDefaultTimeout()
    77  		Expect(session).Should(Exit(0))
    78  		Expect(session.OutputToStringArray()).To(HaveLen(4))
    79  	})
    80  
    81  	It("podman run entrypoint with user cmd overrides image cmd", func() {
    82  		dockerfile := `FROM quay.io/libpod/alpine:latest
    83  CMD [ "-v"]
    84  ENTRYPOINT ["grep", "Alpine", "/etc/os-release"]
    85  `
    86  		podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
    87  		session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest", "-i"})
    88  		session.WaitWithDefaultTimeout()
    89  		Expect(session).Should(Exit(0))
    90  		Expect(session.OutputToStringArray()).To(HaveLen(5))
    91  	})
    92  
    93  	It("podman run entrypoint with user cmd no image cmd", func() {
    94  		dockerfile := `FROM quay.io/libpod/alpine:latest
    95  ENTRYPOINT ["grep", "Alpine", "/etc/os-release"]
    96  `
    97  		podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
    98  		session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest", "-i"})
    99  		session.WaitWithDefaultTimeout()
   100  		Expect(session).Should(Exit(0))
   101  		Expect(session.OutputToStringArray()).To(HaveLen(5))
   102  	})
   103  
   104  	It("podman run user entrypoint overrides image entrypoint and image cmd", func() {
   105  		dockerfile := `FROM quay.io/libpod/alpine:latest
   106  CMD ["-i"]
   107  ENTRYPOINT ["grep", "Alpine", "/etc/os-release"]
   108  `
   109  		podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
   110  		session := podmanTest.Podman([]string{"run", "--entrypoint=uname", "foobar.com/entrypoint:latest"})
   111  		session.WaitWithDefaultTimeout()
   112  		Expect(session).Should(Exit(0))
   113  		Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("Linux")))
   114  
   115  		session = podmanTest.Podman([]string{"run", "--entrypoint", "", "foobar.com/entrypoint:latest", "uname"})
   116  		session.WaitWithDefaultTimeout()
   117  		Expect(session).Should(Exit(0))
   118  		Expect(session.OutputToStringArray()).To(ContainElement(HavePrefix("Linux")))
   119  	})
   120  
   121  	It("podman run user entrypoint with command overrides image entrypoint and image cmd", func() {
   122  		dockerfile := `FROM quay.io/libpod/alpine:latest
   123  CMD ["-i"]
   124  ENTRYPOINT ["grep", "Alpine", "/etc/os-release"]
   125  `
   126  		podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
   127  		session := podmanTest.Podman([]string{"run", "--entrypoint=uname", "foobar.com/entrypoint:latest", "-r"})
   128  		session.WaitWithDefaultTimeout()
   129  		Expect(session).Should(Exit(0))
   130  		Expect(session.OutputToStringArray()).To(Not(ContainElement(HavePrefix("Linux"))))
   131  	})
   132  })