From f79919c7bcf0cd932f47087b81a01af0e8f09a50 Mon Sep 17 00:00:00 2001 From: Vishwas Siravara Date: Wed, 15 Mar 2023 12:17:07 -0700 Subject: [PATCH 1/2] Refactor tests to match nerdctl 1.2.1 outputs Signed-off-by: Vishwas Siravara --- tests/exec.go | 2 +- tests/images.go | 4 +++- tests/run.go | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/exec.go b/tests/exec.go index 660f508..c8b2c0b 100644 --- a/tests/exec.go +++ b/tests/exec.go @@ -101,7 +101,7 @@ func Exec(o *option.Option) { for name, want := range testCases { output := command.StdoutStr(o, "exec", user, name, testContainerName, "id") - gomega.Expect(output).Should(gomega.Equal(want)) + gomega.Expect(output).Should(gomega.ContainSubstring(want)) } }) } diff --git a/tests/images.go b/tests/images.go index 71f1575..302ad0e 100644 --- a/tests/images.go +++ b/tests/images.go @@ -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") diff --git a/tests/run.go b/tests/run.go index c8f3d5b..e5a50d4 100644 --- a/tests/run.go +++ b/tests/run.go @@ -583,7 +583,7 @@ func Run(o *RunOption) { } for userStr, expected := range testCases { output := command.StdoutStr(o.BaseOpt, "run", user, userStr, defaultImage, "id") - gomega.Expect(output).To(gomega.Equal(expected)) + gomega.Expect(output).To(gomega.ContainSubstring(expected)) } }) @@ -613,7 +613,7 @@ func Run(o *RunOption) { } args = append(args, defaultImage, "id") output := command.StdoutStr(o.BaseOpt, args...) - gomega.Expect(output).To(gomega.Equal(tc.expected)) + gomega.Expect(output).To(gomega.ContainSubstring(tc.expected)) } }) } From 9c719945d132c77af6f2ec65299b642220a95fb8 Mon Sep 17 00:00:00 2001 From: Vishwas Siravara Date: Wed, 15 Mar 2023 14:16:37 -0700 Subject: [PATCH 2/2] Code review changes Signed-off-by: Vishwas Siravara --- tests/exec.go | 9 +++++---- tests/run.go | 39 +++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/tests/exec.go b/tests/exec.go index c8b2c0b..ced01d6 100644 --- a/tests/exec.go +++ b/tests/exec.go @@ -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.ContainSubstring(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]))) } }) } diff --git a/tests/run.go b/tests/run.go index e5a50d4..2d066d0 100644 --- a/tests/run.go +++ b/tests/run.go @@ -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.ContainSubstring(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)", + }, }, } @@ -613,7 +623,8 @@ func Run(o *RunOption) { } args = append(args, defaultImage, "id") output := command.StdoutStr(o.BaseOpt, args...) - gomega.Expect(output).To(gomega.ContainSubstring(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]))) } }) }