Skip to content

Commit

Permalink
fix: Fix tests to match nerdctl 1.2.1 outputs (#50)
Browse files Browse the repository at this point in the history
Issue #, if available:

*Description of changes:*
After upgrading `nerdctl` dependency to 1.2.1, [7 e2e tests in finch
fail](/~https://github.com/runfinch/finch/actions/runs/4421068149/jobs/7751480288#step:6:12894)
due to failed assertions on output strings of finch commands.

#### nerdctl images --quiet
Output before 1.2.1
```
$ nerdctl images --quiet
69665d02cb32
```
Output in 1.2.1
```
$ nerdctl images --quiet
sha256:ff6bdca1701f3a8a67e328815ff2346b0e4067d32ec36b7992c1fdc001dc8517
```

#### nerdctl run/exec -u/--user
Output before 1.2.1
```
$ nerdctl run -u nobody:100 alpine id                                   
uid=65534(nobody) gid=100(users)
```

Output in 1.2.1
```
$ nerdctl run -u nobody:100 alpine id
uid=65534(nobody) gid=100(users) groups=100(users)
```

#### nerdctl run --group-add
Output before 1.2.1
```
$ nerdctl run -u nobody --group-add 100 alpine id
uid=65534(nobody) gid=65534(nobody) groups=100(users)
```

Output in 1.2.1

```
$ nerdctl run -u nobody --group-add 100 alpine id
 uid=65534(nobody) gid=65534(nobody) groups=100(users),65534(nobody) 
```

*Testing done:*
Yes, locally. 

- [X] I've reviewed the guidance in CONTRIBUTING.md


#### License Acceptance

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

---------

Signed-off-by: Vishwas Siravara <siravara@amazon.com>
  • Loading branch information
vsiravar authored Mar 16, 2023
1 parent e8fc71a commit 3d9b4f4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
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

0 comments on commit 3d9b4f4

Please sign in to comment.