Skip to content

[Tigron]: support multi-parameters for expect.Contains and expect.DoesNotContain #4136

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

Merged
merged 2 commits into from
Apr 21, 2025
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
15 changes: 3 additions & 12 deletions cmd/nerdctl/completion/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ func TestCompletion(t *testing.T) {
Command: test.Command("__complete", "run", "--net", ""),
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: expect.All(
expect.Contains("host\n"),
expect.Contains(data.Labels().Get("identifier")+"\n"),
),
Output: expect.Contains("host\n", data.Labels().Get("identifier")+"\n"),
}
},
},
Expand All @@ -103,10 +100,7 @@ func TestCompletion(t *testing.T) {
Command: test.Command("__complete", "run", "-it", "--net", ""),
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: expect.All(
expect.Contains("host\n"),
expect.Contains(data.Labels().Get("identifier")+"\n"),
),
Output: expect.Contains("host\n", data.Labels().Get("identifier")+"\n"),
}
},
},
Expand All @@ -115,10 +109,7 @@ func TestCompletion(t *testing.T) {
Command: test.Command("__complete", "run", "-it", "--rm", "--net", ""),
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: expect.All(
expect.Contains("host\n"),
expect.Contains(data.Labels().Get("identifier")+"\n"),
),
Output: expect.Contains("host\n", data.Labels().Get("identifier")+"\n"),
}
},
},
Expand Down
5 changes: 1 addition & 4 deletions cmd/nerdctl/compose/compose_build_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ services:

Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: expect.All(
expect.Contains(data.Labels().Get("imageSvc0")),
expect.Contains(data.Labels().Get("imageSvc1")),
),
Output: expect.Contains(data.Labels().Get("imageSvc0"), data.Labels().Get("imageSvc1")),
}
},
},
Expand Down
33 changes: 15 additions & 18 deletions cmd/nerdctl/compose/compose_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,11 @@ services:
"config",
)
},
Expected: test.Expects(expect.ExitCodeSuccess, nil, expect.All(
expect.Contains("alpine:3.13"),
expect.Contains("alpine:3.14"),
expect.Contains("hello1"),
expect.Contains("hello2"),
)),
Expected: test.Expects(
expect.ExitCodeSuccess,
nil,
expect.Contains("alpine:3.13", "alpine:3.14", "hello1", "hello2"),
),
},
{
Description: "project dir",
Expand Down Expand Up @@ -230,12 +229,11 @@ services:
cmd.Setenv("COMPOSE_PATH_SEPARATOR", ",")
return cmd
},
Expected: test.Expects(expect.ExitCodeSuccess, nil, expect.All(
expect.Contains("alpine:3.13"),
expect.Contains("alpine:3.14"),
expect.Contains("hello1"),
expect.Contains("hello2"),
)),
Expected: test.Expects(
expect.ExitCodeSuccess,
nil,
expect.Contains("alpine:3.13", "alpine:3.14", "hello1", "hello2"),
),
},
{
Description: "env with project dir",
Expand All @@ -249,12 +247,11 @@ services:
cmd.Setenv("COMPOSE_PATH_SEPARATOR", ",")
return cmd
},
Expected: test.Expects(expect.ExitCodeSuccess, nil, expect.All(
expect.Contains("alpine:3.13"),
expect.Contains("alpine:3.14"),
expect.Contains("hello1"),
expect.Contains("hello2"),
)),
Expected: test.Expects(
expect.ExitCodeSuccess,
nil,
expect.Contains("alpine:3.13", "alpine:3.14", "hello1", "hello2"),
),
},
}

Expand Down
17 changes: 9 additions & 8 deletions cmd/nerdctl/compose/compose_exec_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,16 @@ services:
"env")
},
Expected: test.Expects(expect.ExitCodeSuccess, nil, expect.All(
expect.Contains("\nFOO=foo1,foo2\n"),
expect.Contains("\nBAR=bar1 bar2\n"),
expect.Contains("\nBAZ=\n"),
expect.Contains(
"\nFOO=foo1,foo2\n",
"\nBAR=bar1 bar2\n",
"\nBAZ=\n",
"\nQUUX=quux2\n",
"\nCORGE=corge-value-in-host\n",
"\nGRAULT=grault_key=grault_value\n",
"\nGARPLY=\n",
"\nWALDO=\n"),
expect.DoesNotContain("QUX"),
expect.Contains("\nQUUX=quux2\n"),
expect.Contains("\nCORGE=corge-value-in-host\n"),
expect.Contains("\nGRAULT=grault_key=grault_value\n"),
expect.Contains("\nGARPLY=\n"),
expect.Contains("\nWALDO=\n"),
)),
},
}
Expand Down
15 changes: 9 additions & 6 deletions cmd/nerdctl/container/container_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ func TestDiff(t *testing.T) {
return helpers.Command("diff", data.Identifier())
}

testCase.Expected = test.Expects(0, nil, expect.All(
expect.Contains("A /a"),
expect.Contains("C /bin"),
expect.Contains("A /bin/b"),
expect.Contains("D /bin/base64"),
))
testCase.Expected = test.Expects(
0,
nil,
expect.Contains(
"A /a",
"C /bin",
"A /bin/b",
"D /bin/base64"),
)

testCase.Run(t)
}
12 changes: 4 additions & 8 deletions cmd/nerdctl/container/container_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ func TestLogsWithForegroundContainers(t *testing.T) {
return helpers.Command("logs", data.Identifier())
},
Expected: test.Expects(0, nil, expect.All(
expect.Contains("foo"),
expect.Contains("bar"),
expect.Contains("foo", "bar"),
expect.DoesNotContain("baz"),
)),
},
Expand All @@ -264,8 +263,7 @@ func TestLogsWithForegroundContainers(t *testing.T) {
return helpers.Command("logs", data.Identifier())
},
Expected: test.Expects(0, nil, expect.All(
expect.Contains("foo"),
expect.Contains("bar"),
expect.Contains("foo", "bar"),
expect.DoesNotContain("baz"),
)),
},
Expand All @@ -283,8 +281,7 @@ func TestLogsWithForegroundContainers(t *testing.T) {
return helpers.Command("logs", data.Identifier())
},
Expected: test.Expects(0, nil, expect.All(
expect.Contains("foo"),
expect.Contains("bar"),
expect.Contains("foo", "bar"),
expect.DoesNotContain("baz"),
)),
},
Expand All @@ -302,8 +299,7 @@ func TestLogsWithForegroundContainers(t *testing.T) {
return helpers.Command("logs", data.Identifier())
},
Expected: test.Expects(0, nil, expect.All(
expect.Contains("foo"),
expect.Contains("bar"),
expect.Contains("foo", "bar"),
expect.DoesNotContain("baz"),
)),
},
Expand Down
36 changes: 19 additions & 17 deletions cmd/nerdctl/container/container_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ CMD ["echo", "bar"]
},
Expected: test.Expects(expect.ExitCodeSuccess, nil, expect.All(
expect.Contains("blah"),
expect.DoesNotContain("foo"),
expect.DoesNotContain("bar"),
expect.DoesNotContain("foo", "bar"),
)),
},
{
Expand All @@ -98,8 +97,7 @@ CMD ["echo", "bar"]
},
Expected: test.Expects(expect.ExitCodeSuccess, nil, expect.All(
expect.Contains("blah"),
expect.DoesNotContain("foo"),
expect.DoesNotContain("bar"),
expect.DoesNotContain("foo", "bar"),
)),
},
},
Expand Down Expand Up @@ -207,11 +205,11 @@ func TestRunEnvFile(t *testing.T) {
testutil.CommonImage, "env")
}

testCase.Expected = test.Expects(expect.ExitCodeSuccess, nil, expect.All(
expect.Contains("TESTKEY1=TESTVAL1"),
expect.Contains("TESTKEY2=TESTVAL2"),
expect.Contains("HOST_ENV=ENV-IN-HOST"),
))
testCase.Expected = test.Expects(
expect.ExitCodeSuccess,
nil,
expect.Contains("TESTKEY1=TESTVAL1", "TESTKEY2=TESTVAL2", "HOST_ENV=ENV-IN-HOST"),
)

testCase.Run(t)
}
Expand Down Expand Up @@ -240,20 +238,24 @@ func TestRunEnv(t *testing.T) {
}

validate := []test.Comparator{
expect.Contains("\nFOO=foo1,foo2\n"),
expect.Contains("\nBAR=bar1 bar2\n"),
expect.Contains(
"\nFOO=foo1,foo2\n",
"\nBAR=bar1 bar2\n",
"\nQUUX=quux2\n",
"\nCORGE=corge-value-in-host\n",
"\nGRAULT=grault_key=grault_value\n",
),
expect.DoesNotContain("QUX"),
expect.Contains("\nQUUX=quux2\n"),
expect.Contains("\nCORGE=corge-value-in-host\n"),
expect.Contains("\nGRAULT=grault_key=grault_value\n"),
}

if runtime.GOOS != "windows" {
validate = append(
validate,
expect.Contains("\nBAZ=\n"),
expect.Contains("\nGARPLY=\n"),
expect.Contains("\nWALDO=\n"),
expect.Contains(
"\nBAZ=\n",
"\nGARPLY=\n",
"\nWALDO=\n",
),
)
}

Expand Down
15 changes: 8 additions & 7 deletions cmd/nerdctl/image/image_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,11 @@ RUN echo "actually creating a layer so that docker sets the createdAt time"
{
Description: "reference=tagged*:*fragment*",
Command: test.Command("images", "--filter", "reference=tagged*:*fragment*"),
Expected: test.Expects(0, nil, expect.All(
expect.Contains("one-"),
expect.Contains("two-"),
)),
Expected: test.Expects(
0,
nil,
expect.Contains("one-", "two-"),
),
},
{
Description: "before=ID:latest",
Expand Down Expand Up @@ -259,9 +260,9 @@ RUN echo "actually creating a layer so that docker sets the createdAt time"
Command: test.Command("images", "--filter", fmt.Sprintf("since=%s", testutil.CommonImage), testutil.CommonImage),
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: expect.All(
expect.DoesNotContain(data.Labels().Get("builtImageID")),
expect.DoesNotContain(testutil.ImageRepo(testutil.CommonImage)),
Output: expect.DoesNotContain(
data.Labels().Get("builtImageID"),
testutil.ImageRepo(testutil.CommonImage),
),
}
},
Expand Down
7 changes: 2 additions & 5 deletions cmd/nerdctl/image/image_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,8 @@ func TestRemove(t *testing.T) {
return &test.Expected{
Output: func(stdout string, info string, t *testing.T) {
helpers.Command("images").Run(&test.Expected{
Output: expect.All(
expect.DoesNotContain(repoName),
// a created container with removed image doesn't impact other `rmi` command
expect.DoesNotContain(nginxRepoName),
),
// a created container with removed image doesn't impact other `rmi` command
Output: expect.DoesNotContain(repoName, nginxRepoName),
})
},
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/nerdctl/volume/volume_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ func TestVolumeInspect(t *testing.T) {
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: expect.All(
expect.Contains(data.Labels().Get("vol1")),
expect.Contains(data.Labels().Get("vol2")),
expect.Contains(data.Labels().Get("vol1"), data.Labels().Get("vol2")),
expect.JSON([]native.Volume{}, func(dc []native.Volume, info string, t tig.T) {
assert.Assert(t, len(dc) == 2, fmt.Sprintf("two results, not %d", len(dc)))
assert.Assert(t, dc[0].Name == data.Labels().Get("vol1"), fmt.Sprintf("expected name to be %q (was %q)", data.Labels().Get("vol1"), dc[0].Name))
Expand Down
14 changes: 7 additions & 7 deletions cmd/nerdctl/volume/volume_prune_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ func TestVolumePrune(t *testing.T) {
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: expect.All(
expect.DoesNotContain(data.Labels().Get("anonIDBusy")),
expect.Contains(data.Labels().Get("anonIDDangling")),
expect.DoesNotContain(data.Labels().Get("namedBusy")),
expect.DoesNotContain(data.Labels().Get("namedDangling")),
expect.DoesNotContain(
data.Labels().Get("anonIDBusy"),
data.Labels().Get("namedBusy"),
data.Labels().Get("namedDangling"),
),
func(stdout string, info string, t *testing.T) {
helpers.Ensure("volume", "inspect", data.Labels().Get("anonIDBusy"))
helpers.Fail("volume", "inspect", data.Labels().Get("anonIDDangling"))
Expand All @@ -92,10 +94,8 @@ func TestVolumePrune(t *testing.T) {
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: expect.All(
expect.DoesNotContain(data.Labels().Get("anonIDBusy")),
expect.Contains(data.Labels().Get("anonIDDangling")),
expect.DoesNotContain(data.Labels().Get("namedBusy")),
expect.Contains(data.Labels().Get("namedDangling")),
expect.DoesNotContain(data.Labels().Get("anonIDBusy"), data.Labels().Get("namedBusy")),
expect.Contains(data.Labels().Get("anonIDDangling"), data.Labels().Get("namedDangling")),
func(stdout string, info string, t *testing.T) {
helpers.Ensure("volume", "inspect", data.Labels().Get("anonIDBusy"))
helpers.Fail("volume", "inspect", data.Labels().Get("anonIDDangling"))
Expand Down
14 changes: 12 additions & 2 deletions mod/tigron/expect/comparators.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,28 @@ func All(comparators ...test.Comparator) test.Comparator {

// Contains can be used as a parameter for expected.Output and ensures a comparison string is found contained in the
// output.
func Contains(compare string) test.Comparator {
func Contains(compare string, more ...string) test.Comparator {
return func(stdout, _ string, t *testing.T) {
t.Helper()

assertive.Contains(assertive.WithFailLater(t), stdout, compare, "Inspecting output (contains)")

for _, m := range more {
assertive.Contains(assertive.WithFailLater(t), stdout, m, "Inspecting output (contains)")
}
}
}

// DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in the output.
func DoesNotContain(compare string) test.Comparator {
func DoesNotContain(compare string, more ...string) test.Comparator {
return func(stdout, _ string, t *testing.T) {
t.Helper()

assertive.DoesNotContain(assertive.WithFailLater(t), stdout, compare, "Inspecting output (does not contain)")

for _, m := range more {
assertive.DoesNotContain(assertive.WithFailLater(t), stdout, m, "Inspecting output (does not contain)")
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions mod/tigron/expect/comparators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
)

func TestExpect(t *testing.T) {
// TODO: write more tests once we can mock t in Comparator signature
t.Parallel()

expect.Contains("b")("a b c", "contains works", t)
Expand All @@ -39,7 +40,9 @@ func TestExpect(t *testing.T) {

expect.All(
expect.Contains("b"),
expect.Contains("b", "c"),
expect.DoesNotContain("d"),
expect.DoesNotContain("d", "e"),
expect.Equals("a b c"),
expect.Match(regexp.MustCompile("[a-z ]+")),
)("a b c", "all", t)
Expand Down
Loading