Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add longform bool flag coverage for e2e testing #191

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"} {
coderbirju marked this conversation as resolved.
Show resolved Hide resolved
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")
coderbirju marked this conversation as resolved.
Show resolved Hide resolved
})
})
}