diff --git a/tests/exec.go b/tests/exec.go index 43256a5..30c6ea6 100644 --- a/tests/exec.go +++ b/tests/exec.go @@ -38,7 +38,7 @@ func Exec(o *option.Option) { gomega.Expect(output).Should(gomega.Equal(strEchoed)) }) - for _, interactive := range []string{"-i", "--interactive"} { + for _, interactive := range []string{"-i", "--interactive", "-i=true", "--interactive=true"} { interactive := interactive ginkgo.It(fmt.Sprintf("should output string by piping if %s flag keeps STDIN open", interactive), func() { want := []byte("hello") @@ -48,7 +48,7 @@ func Exec(o *option.Option) { }) } - for _, detach := range []string{"-d", "--detach"} { + for _, detach := range []string{"-d", "--detach", "-d=true", "--detach=true"} { detach := detach ginkgo.It(fmt.Sprintf("should execute command in detached mode with %s flag", detach), func() { command.Run(o, "exec", detach, testContainerName, "nc", "-l") @@ -84,12 +84,15 @@ func Exec(o *option.Option) { gomega.Expect(envOutput).Should(gomega.ContainElement(envPair)) }) - ginkgo.It("should execute command in privileged mode with --privileged flag", func() { - command.RunWithoutSuccessfulExit(o, "exec", testContainerName, "ip", "link", "add", "dummy1", "type", "dummy") - command.Run(o, "exec", "--privileged", testContainerName, "ip", "link", "add", "dummy1", "type", "dummy") - output := command.StdoutStr(o, "exec", "--privileged", testContainerName, "ip", "link") - gomega.Expect(output).Should(gomega.ContainSubstring("dummy1")) - }) + for _, privilegedFlag := range []string{"--privileged", "--privileged=true"} { + privilegedFlag := privilegedFlag + ginkgo.It(fmt.Sprintf("should execute command in privileged mode with %s flag", privilegedFlag), func() { + command.RunWithoutSuccessfulExit(o, "exec", testContainerName, "ip", "link", "add", "dummy1", "type", "dummy") + command.Run(o, "exec", privilegedFlag, testContainerName, "ip", "link", "add", "dummy1", "type", "dummy") + output := command.StdoutStr(o, "exec", privilegedFlag, testContainerName, "ip", "link") + gomega.Expect(output).Should(gomega.ContainSubstring("dummy1")) + }) + } for _, user := range []string{"-u", "--user"} { user := user diff --git a/tests/start.go b/tests/start.go index eee930a..af97a02 100644 --- a/tests/start.go +++ b/tests/start.go @@ -5,6 +5,7 @@ package tests import ( "fmt" + "strings" "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" @@ -34,7 +35,7 @@ func Start(o *option.Option) { containerShouldBeRunning(o, testContainerName) }) - for _, attach := range []string{"--attach", "-a"} { + for _, attach := range []string{"--attach", "-a", "-a=true", "--attach=true"} { attach := attach ginkgo.It(fmt.Sprintf("with %s flag, should start the container with stdout", attach), func() { command.Run(o, "create", "--name", testContainerName, localImages[defaultImage], "echo", "foo") @@ -42,5 +43,24 @@ func Start(o *option.Option) { gomega.Expect(output).To(gomega.Equal("foo")) }) } + + ginkgo.It("should run a container without an init process when --init=false flag is used", func() { + command.Run(o, "run", "--name", testContainerName, "--init=false", localImages[defaultImage], "ps", "-ao", "pid,comm") + psOutput := command.StdoutStr(o, "logs", testContainerName) + + // Split the output into lines + lines := strings.Split(strings.TrimSpace(psOutput), "\n") + + processLine := lines[1] // Second line (after header) + fields := strings.Fields(processLine) + + pid := fields[0] + command := fields[3] + gomega.Expect(pid).To(gomega.Equal("1"), "The only process should have PID 1") + gomega.Expect(command).To(gomega.Equal("ps"), "The only process should be ps") + + // Verify there's no init process + gomega.Expect(psOutput).NotTo(gomega.ContainSubstring("tini"), "There should be no tini process") + }) }) }