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

fix: Fix tests to match nerdctl 1.2.1 outputs #50

Merged
merged 2 commits into from
Mar 16, 2023
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
9 changes: 5 additions & 4 deletions tests/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ func Exec(o *option.Option) {
for _, user := range []string{"-u", "--user"} {
user := user
ginkgo.It(fmt.Sprintf("should output user id according to user name specified by %s flag", user), func() {
testCases := map[string]string{
"1000": "uid=1000 gid=0(root)",
"1000:users": "uid=1000 gid=100(users)",
testCases := map[string][]string{
"1000": {"uid=1000 gid=0(root)", "uid=1000 gid=0(root) groups=0(root)"},
"1000:users": {"uid=1000 gid=100(users)", "uid=1000 gid=100(users) groups=100(users)"},
}

for name, want := range testCases {
output := command.StdoutStr(o, "exec", user, name, testContainerName, "id")
gomega.Expect(output).Should(gomega.Equal(want))
// TODO: Remove the Or operator after upgrading the nerdctl dependency to 1.2.1 to only match want[1]
gomega.Expect(output).Should(gomega.Or(gomega.Equal(want[0]), gomega.Equal(want[1])))
}
})
}
Expand Down
4 changes: 3 additions & 1 deletion tests/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func Images(o *option.Option) {
ginkgo.It("should list truncated IMAGE IDs", func() {
images := command.StdoutAsLines(o, "images", "--quiet")
gomega.Expect(images).ShouldNot(gomega.BeEmpty())
gomega.Expect(images).Should(gomega.HaveEach(gomega.MatchRegexp(sha256RegexTruncated)))
// TODO: Remove the Or operator after upgrading the nerdctl dependency to 1.2.1 to only match sha256RegexFull
gomega.Expect(images).To(gomega.Or(gomega.HaveEach(gomega.MatchRegexp(sha256RegexFull)),
gomega.HaveEach(gomega.MatchRegexp(sha256RegexTruncated))))
})
ginkgo.It("should list full IMAGE IDs", func() {
images := command.StdoutAsLines(o, "images", "--quiet", "--no-trunc")
Expand Down
39 changes: 25 additions & 14 deletions tests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,34 +575,44 @@ func Run(o *RunOption) {
user := user
ginkgo.It(fmt.Sprintf("should set the user of a container with %s flag", user), func() {
// Ref: https://wiki.gentoo.org/wiki/UID_GID_Assignment_Table
testCases := map[string]string{
"65534": "uid=65534(nobody) gid=65534(nobody)",
"nobody": "uid=65534(nobody) gid=65534(nobody)",
"nobody:users": "uid=65534(nobody) gid=100(users)",
"nobody:100": "uid=65534(nobody) gid=100(users)",
testCases := map[string][]string{
"65534": {"uid=65534(nobody) gid=65534(nobody)", "uid=65534(nobody) gid=65534(nobody) groups=65534(nobody)"},
"nobody": {"uid=65534(nobody) gid=65534(nobody)", "uid=65534(nobody) gid=65534(nobody) groups=65534(nobody)"},
"nobody:users": {"uid=65534(nobody) gid=100(users)", "uid=65534(nobody) gid=100(users) groups=100(users)"},
"nobody:100": {"uid=65534(nobody) gid=100(users)", "uid=65534(nobody) gid=100(users) groups=100(users)"},
}
for userStr, expected := range testCases {
output := command.StdoutStr(o.BaseOpt, "run", user, userStr, defaultImage, "id")
gomega.Expect(output).To(gomega.Equal(expected))
// TODO: Remove the Or operator after upgrading the nerdctl dependency to 1.2.1 to only match expected[1]
gomega.Expect(output).Should(gomega.Or(gomega.Equal(expected[0]), gomega.Equal(expected[1])))
}
})

ginkgo.It("should add additional groups for a specific user with --group-add flag", func() {
testCases := []struct {
groups []string
expected string
expected []string
}{
{
groups: []string{"users"},
expected: "uid=65534(nobody) gid=65534(nobody) groups=100(users)",
groups: []string{"users"},
expected: []string{
"uid=65534(nobody) gid=65534(nobody) groups=100(users)",
"uid=65534(nobody) gid=65534(nobody) groups=100(users),65534(nobody)",
},
},
{
groups: []string{"100"},
expected: "uid=65534(nobody) gid=65534(nobody) groups=100(users)",
groups: []string{"100"},
expected: []string{
"uid=65534(nobody) gid=65534(nobody) groups=100(users)",
"uid=65534(nobody) gid=65534(nobody) groups=100(users),65534(nobody)",
},
},
{
groups: []string{"users", "nogroup"},
expected: "uid=65534(nobody) gid=65534(nobody) groups=100(users),65533(nogroup)",
groups: []string{"users", "nogroup"},
expected: []string{
"uid=65534(nobody) gid=65534(nobody) groups=100(users),65533(nogroup)",
"uid=65534(nobody) gid=65534(nobody) groups=100(users),65533(nogroup),65534(nobody)",
},
},
}

Expand All @@ -613,7 +623,8 @@ func Run(o *RunOption) {
}
args = append(args, defaultImage, "id")
output := command.StdoutStr(o.BaseOpt, args...)
gomega.Expect(output).To(gomega.Equal(tc.expected))
// TODO: Remove the Or operator after upgrading the nerdctl dependency to 1.2.1 to only match tc.expected[1]
gomega.Expect(output).Should(gomega.Or(gomega.Equal(tc.expected[0]), gomega.Equal(tc.expected[1])))
}
})
}
Expand Down