Skip to content

Commit

Permalink
chore: add longform bool flag coverage for e2e testing (#191)
Browse files Browse the repository at this point in the history
chore: add longform bool flag checks for e2e testing

Signed-off-by: Arjun Raja Yogidas <[email protected]>
  • Loading branch information
coderbirju authored Nov 25, 2024
1 parent ecbae8a commit 4f09830
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
19 changes: 11 additions & 8 deletions tests/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion tests/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package tests

import (
"fmt"
"strings"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
Expand Down Expand Up @@ -34,13 +35,32 @@ 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")
output := command.StdoutStr(o, "start", attach, testContainerName)
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[1]
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")
})
})
}

0 comments on commit 4f09830

Please sign in to comment.