Skip to content

Commit 8251646

Browse files
committed
Adapt nerdctl tests to tig.T signature
Signed-off-by: apostasie <spam_blackhole@farcloser.world>
1 parent 5a24932 commit 8251646

40 files changed

+187
-151
lines changed

cmd/nerdctl/builder/builder_build_oci_layout_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/containerd/nerdctl/mod/tigron/expect"
2828
"github.com/containerd/nerdctl/mod/tigron/require"
2929
"github.com/containerd/nerdctl/mod/tigron/test"
30+
"github.com/containerd/nerdctl/mod/tigron/tig"
3031

3132
"github.com/containerd/nerdctl/v2/pkg/testutil"
3233
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
@@ -100,7 +101,7 @@ CMD ["echo", "test-nerdctl-build-context-oci-layout"]`
100101
},
101102
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
102103
return &test.Expected{
103-
Output: func(stdout string, t *testing.T) {
104+
Output: func(stdout string, t tig.T) {
104105
assert.Assert(
105106
t,
106107
strings.Contains(

cmd/nerdctl/builder/builder_build_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/containerd/nerdctl/mod/tigron/expect"
2929
"github.com/containerd/nerdctl/mod/tigron/require"
3030
"github.com/containerd/nerdctl/mod/tigron/test"
31+
"github.com/containerd/nerdctl/mod/tigron/tig"
3132

3233
"github.com/containerd/nerdctl/v2/pkg/platformutil"
3334
"github.com/containerd/nerdctl/v2/pkg/testutil"
@@ -337,7 +338,7 @@ COPY %s /`, testFileName)
337338
},
338339
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
339340
return &test.Expected{
340-
Output: func(stdout string, t *testing.T) {
341+
Output: func(stdout string, t tig.T) {
341342
// Expecting testFileName to exist inside the output target directory
342343
assert.Equal(t, data.Temp().Load(testFileName), testContent, "file content is identical")
343344
},
@@ -351,7 +352,7 @@ COPY %s /`, testFileName)
351352
},
352353
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
353354
return &test.Expected{
354-
Output: func(stdout string, t *testing.T) {
355+
Output: func(stdout string, t tig.T) {
355356
assert.Equal(t, data.Temp().Load(testFileName), testContent, "file content is identical")
356357
},
357358
}
@@ -888,7 +889,7 @@ func TestBuildAttestation(t *testing.T) {
888889
},
889890
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
890891
return &test.Expected{
891-
Output: func(stdout string, t *testing.T) {
892+
Output: func(stdout string, t tig.T) {
892893
data.Temp().Exists("dir-for-bom", testSBOMFileName)
893894
},
894895
}
@@ -910,7 +911,7 @@ func TestBuildAttestation(t *testing.T) {
910911
},
911912
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
912913
return &test.Expected{
913-
Output: func(stdout string, t *testing.T) {
914+
Output: func(stdout string, t tig.T) {
914915
data.Temp().Exists("dir-for-prov", testProvenanceFileName)
915916
},
916917
}
@@ -933,7 +934,7 @@ func TestBuildAttestation(t *testing.T) {
933934
},
934935
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
935936
return &test.Expected{
936-
Output: func(stdout string, t *testing.T) {
937+
Output: func(stdout string, t tig.T) {
937938
data.Temp().Exists("dir-for-attest", testSBOMFileName)
938939
data.Temp().Exists("dir-for-attest", testProvenanceFileName)
939940
},

cmd/nerdctl/compose/compose_config_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/containerd/nerdctl/mod/tigron/expect"
2626
"github.com/containerd/nerdctl/mod/tigron/test"
27+
"github.com/containerd/nerdctl/mod/tigron/tig"
2728

2829
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
2930
)
@@ -111,7 +112,7 @@ services:
111112
testCase.Expected = func(data test.Data, helpers test.Helpers) *test.Expected {
112113
return &test.Expected{
113114
ExitCode: 0,
114-
Output: func(stdout string, t *testing.T) {
115+
Output: func(stdout string, t tig.T) {
115116
assert.Assert(t, data.Labels().Get("hash") != stdout, "hash should be different")
116117
},
117118
}

cmd/nerdctl/compose/compose_cp_linux_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/containerd/nerdctl/mod/tigron/expect"
2626
"github.com/containerd/nerdctl/mod/tigron/test"
27+
"github.com/containerd/nerdctl/mod/tigron/tig"
2728

2829
"github.com/containerd/nerdctl/v2/pkg/testutil"
2930
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
@@ -79,7 +80,7 @@ services:
7980
},
8081
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
8182
return &test.Expected{
82-
Output: func(stdout string, t *testing.T) {
83+
Output: func(stdout string, t tig.T) {
8384
copied := data.Temp().Load("test-file2")
8485
assert.Equal(t, copied, testFileContent)
8586
},

cmd/nerdctl/compose/compose_create_linux_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/containerd/nerdctl/mod/tigron/expect"
2727
"github.com/containerd/nerdctl/mod/tigron/test"
28+
"github.com/containerd/nerdctl/mod/tigron/tig"
2829

2930
"github.com/containerd/nerdctl/v2/pkg/testutil"
3031
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
@@ -66,7 +67,7 @@ services:
6667
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
6768
return helpers.Command("compose", "-f", data.Labels().Get("composeYaml"), "ps", "svc0", "-a")
6869
},
69-
Expected: test.Expects(expect.ExitCodeSuccess, nil, func(stdout string, t *testing.T) {
70+
Expected: test.Expects(expect.ExitCodeSuccess, nil, func(stdout string, t tig.T) {
7071
assert.Assert(t,
7172
strings.Contains(stdout, "created") || strings.Contains(stdout, "Created"),
7273
"stdout should contain `created`")
@@ -125,7 +126,7 @@ services:
125126
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
126127
return helpers.Command("compose", "-f", data.Labels().Get("composeYaml"), "ps", "svc0", "-a")
127128
},
128-
Expected: test.Expects(expect.ExitCodeSuccess, nil, func(stdout string, t *testing.T) {
129+
Expected: test.Expects(expect.ExitCodeSuccess, nil, func(stdout string, t tig.T) {
129130
assert.Assert(t,
130131
strings.Contains(stdout, "created") || strings.Contains(stdout, "Created"),
131132
"stdout should contain `created`")
@@ -137,7 +138,7 @@ services:
137138
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
138139
return helpers.Command("compose", "-f", data.Labels().Get("composeYaml"), "ps", "svc1", "-a")
139140
},
140-
Expected: test.Expects(expect.ExitCodeSuccess, nil, func(stdout string, t *testing.T) {
141+
Expected: test.Expects(expect.ExitCodeSuccess, nil, func(stdout string, t tig.T) {
141142
assert.Assert(t,
142143
strings.Contains(stdout, "created") || strings.Contains(stdout, "Created"),
143144
"stdout should contain `created`")

cmd/nerdctl/container/container_attach_linux_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/containerd/nerdctl/mod/tigron/expect"
3030
"github.com/containerd/nerdctl/mod/tigron/test"
31+
"github.com/containerd/nerdctl/mod/tigron/tig"
3132

3233
"github.com/containerd/nerdctl/v2/pkg/testutil"
3334
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
@@ -64,7 +65,7 @@ func TestAttach(t *testing.T) {
6465
cmd.Run(&test.Expected{
6566
ExitCode: 0,
6667
Errors: []error{errors.New("read detach keys")},
67-
Output: func(stdout string, t *testing.T) {
68+
Output: func(stdout string, t tig.T) {
6869
assert.Assert(t, strings.Contains(helpers.Capture("inspect", "--format", "json", data.Identifier()), "\"Running\":true"))
6970
},
7071
})
@@ -93,7 +94,7 @@ func TestAttach(t *testing.T) {
9394
Errors: []error{errors.New("read detach keys")},
9495
Output: expect.All(
9596
expect.Contains("markmark"),
96-
func(stdout string, t *testing.T) {
97+
func(stdout string, t tig.T) {
9798
assert.Assert(t, strings.Contains(helpers.Capture("inspect", "--format", "json", data.Identifier()), "\"Running\":true"))
9899
},
99100
),
@@ -125,7 +126,7 @@ func TestAttachDetachKeys(t *testing.T) {
125126
cmd.Run(&test.Expected{
126127
ExitCode: 0,
127128
Errors: []error{errors.New("read detach keys")},
128-
Output: func(stdout string, t *testing.T) {
129+
Output: func(stdout string, t tig.T) {
129130
assert.Assert(t, strings.Contains(helpers.Capture("inspect", "--format", "json", data.Identifier()), "\"Running\":true"))
130131
},
131132
})
@@ -153,7 +154,7 @@ func TestAttachDetachKeys(t *testing.T) {
153154
Errors: []error{errors.New("read detach keys")},
154155
Output: expect.All(
155156
expect.Contains("markmark"),
156-
func(stdout string, t *testing.T) {
157+
func(stdout string, t tig.T) {
157158
assert.Assert(t, strings.Contains(helpers.Capture("inspect", "--format", "json", data.Identifier()), "\"Running\":true"))
158159
},
159160
),
@@ -182,7 +183,7 @@ func TestAttachForAutoRemovedContainer(t *testing.T) {
182183
cmd.Run(&test.Expected{
183184
ExitCode: 0,
184185
Errors: []error{errors.New("read detach keys")},
185-
Output: func(stdout string, t *testing.T) {
186+
Output: func(stdout string, t tig.T) {
186187
assert.Assert(t, strings.Contains(helpers.Capture("inspect", "--format", "json", data.Identifier()), "\"Running\":true"))
187188
},
188189
})
@@ -202,7 +203,7 @@ func TestAttachForAutoRemovedContainer(t *testing.T) {
202203
ExitCode: 42,
203204
Output: expect.All(
204205
expect.Contains("markmark"),
205-
func(stdout string, t *testing.T) {
206+
func(stdout string, t tig.T) {
206207
assert.Assert(t, !strings.Contains(helpers.Capture("ps", "-a"), data.Identifier()))
207208
},
208209
),

cmd/nerdctl/container/container_commit_linux_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/containerd/nerdctl/mod/tigron/test"
24+
"github.com/containerd/nerdctl/mod/tigron/tig"
2425

2526
"github.com/containerd/nerdctl/v2/pkg/testutil"
2627
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
@@ -41,7 +42,7 @@ func TestKubeCommitSave(t *testing.T) {
4142
nerdtest.KubeCtlCommand(helpers, "wait", "pod", identifier, "--for=condition=ready", "--timeout=1m").Run(&test.Expected{})
4243
nerdtest.KubeCtlCommand(helpers, "exec", identifier, "--", "mkdir", "-p", "/tmp/whatever").Run(&test.Expected{})
4344
nerdtest.KubeCtlCommand(helpers, "get", "pods", identifier, "-o", "jsonpath={ .status.containerStatuses[0].containerID }").Run(&test.Expected{
44-
Output: func(stdout string, t *testing.T) {
45+
Output: func(stdout string, t tig.T) {
4546
containerID = strings.TrimPrefix(stdout, "containerd://")
4647
},
4748
})
@@ -73,7 +74,7 @@ func TestKubeCommitSave(t *testing.T) {
7374
7475
cmd = nerdtest.KubeCtlCommand(helpers, "get", "pods", tID, "-o", "jsonpath={ .status.hostIPs[0].ip }")
7576
cmd.Run(&test.Expected{
76-
Output: func(stdout string, t *testing.T) {
77+
Output: func(stdout string, t tig.T) {
7778
registryIP = stdout
7879
},
7980
})

cmd/nerdctl/container/container_create_linux_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/containerd/containerd/v2/defaults"
3131
"github.com/containerd/nerdctl/mod/tigron/require"
3232
"github.com/containerd/nerdctl/mod/tigron/test"
33+
"github.com/containerd/nerdctl/mod/tigron/tig"
3334

3435
"github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
3536
"github.com/containerd/nerdctl/v2/pkg/testutil"
@@ -231,7 +232,7 @@ func TestIssue2993(t *testing.T) {
231232
return &test.Expected{
232233
ExitCode: 1,
233234
Errors: []error{errors.New("is already used by ID")},
234-
Output: func(stdout string, t *testing.T) {
235+
Output: func(stdout string, t tig.T) {
235236
containersDirs, err := os.ReadDir(data.Labels().Get(containersPathKey))
236237
assert.NilError(t, err)
237238
assert.Equal(t, len(containersDirs), 1)
@@ -278,7 +279,7 @@ func TestIssue2993(t *testing.T) {
278279
return &test.Expected{
279280
ExitCode: 0,
280281
Errors: []error{},
281-
Output: func(stdout string, t *testing.T) {
282+
Output: func(stdout string, t tig.T) {
282283
containersDirs, err := os.ReadDir(data.Labels().Get(containersPathKey))
283284
assert.NilError(t, err)
284285
assert.Equal(t, len(containersDirs), 0)

cmd/nerdctl/container/container_create_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/containerd/nerdctl/mod/tigron/expect"
2727
"github.com/containerd/nerdctl/mod/tigron/test"
28+
"github.com/containerd/nerdctl/mod/tigron/tig"
2829

2930
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat"
3031
"github.com/containerd/nerdctl/v2/pkg/testutil"
@@ -104,7 +105,7 @@ func TestCreateHyperVContainer(t *testing.T) {
104105
helpers.Command("container", "inspect", data.Labels().Get("cID")).
105106
Run(&test.Expected{
106107
ExitCode: expect.ExitCodeNoCheck,
107-
Output: func(stdout string, t *testing.T) {
108+
Output: func(stdout string, t tig.T) {
108109
var dc []dockercompat.Container
109110
err := json.Unmarshal([]byte(stdout), &dc)
110111
if err != nil || len(dc) == 0 {

cmd/nerdctl/container/container_restart_linux_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"github.com/containerd/nerdctl/mod/tigron/expect"
2929
"github.com/containerd/nerdctl/mod/tigron/test"
30+
"github.com/containerd/nerdctl/mod/tigron/tig"
3031

3132
"github.com/containerd/nerdctl/v2/pkg/testutil"
3233
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
@@ -149,7 +150,7 @@ func TestRestartWithSignal(t *testing.T) {
149150
Output: expect.All(
150151
// Check that we saw SIGUSR1 inside the container
151152
expect.Contains(nerdtest.SignalCaught),
152-
func(stdout string, t *testing.T) {
153+
func(stdout string, t tig.T) {
153154
// Ensure the container was restarted
154155
nerdtest.EnsureContainerStarted(helpers, data.Identifier())
155156
// Check the new pid is different

cmd/nerdctl/container/container_run_cgroup_linux_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/containerd/nerdctl/mod/tigron/expect"
3636
"github.com/containerd/nerdctl/mod/tigron/require"
3737
"github.com/containerd/nerdctl/mod/tigron/test"
38+
"github.com/containerd/nerdctl/mod/tigron/tig"
3839

3940
"github.com/containerd/nerdctl/v2/pkg/cmd/container"
4041
"github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker"
@@ -310,7 +311,7 @@ func TestRunDevice(t *testing.T) {
310311
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
311312
return helpers.Command("exec", data.Labels().Get("id"), "sh", "-ec", "echo -n \"overwritten-lo1-content\">"+lo[1].Device)
312313
},
313-
Expected: test.Expects(expect.ExitCodeSuccess, nil, func(stdout string, t *testing.T) {
314+
Expected: test.Expects(expect.ExitCodeSuccess, nil, func(stdout string, t tig.T) {
314315
lo1Read, err := os.ReadFile(lo[1].Device)
315316
assert.NilError(t, err)
316317
assert.Equal(t, string(bytes.Trim(lo1Read, "\x00")), "overwritten-lo1-content")
@@ -518,7 +519,7 @@ func TestRunBlkioSettingCgroupV2(t *testing.T) {
518519
return &test.Expected{
519520
ExitCode: 0,
520521
Output: expect.All(
521-
func(stdout string, t *testing.T) {
522+
func(stdout string, t tig.T) {
522523
assert.Assert(t, strings.Contains(helpers.Capture("inspect", "--format", "{{.HostConfig.BlkioWeight}}", data.Identifier()), "150"))
523524
},
524525
),
@@ -540,7 +541,7 @@ func TestRunBlkioSettingCgroupV2(t *testing.T) {
540541
return &test.Expected{
541542
ExitCode: 0,
542543
Output: expect.All(
543-
func(stdout string, t *testing.T) {
544+
func(stdout string, t tig.T) {
544545
inspectOut := helpers.Capture("inspect", "--format", "{{range .HostConfig.BlkioWeightDevice}}{{.Weight}}{{end}}", data.Identifier())
545546
assert.Assert(t, strings.Contains(inspectOut, "100"))
546547
},
@@ -569,7 +570,7 @@ func TestRunBlkioSettingCgroupV2(t *testing.T) {
569570
return &test.Expected{
570571
ExitCode: 0,
571572
Output: expect.All(
572-
func(stdout string, t *testing.T) {
573+
func(stdout string, t tig.T) {
573574
inspectOut := helpers.Capture("inspect", "--format", "{{range .HostConfig.BlkioDeviceReadBps}}{{.Rate}}{{end}}", data.Identifier())
574575
assert.Assert(t, strings.Contains(inspectOut, "1048576"))
575576
},
@@ -598,7 +599,7 @@ func TestRunBlkioSettingCgroupV2(t *testing.T) {
598599
return &test.Expected{
599600
ExitCode: 0,
600601
Output: expect.All(
601-
func(stdout string, t *testing.T) {
602+
func(stdout string, t tig.T) {
602603
inspectOut := helpers.Capture("inspect", "--format", "{{range .HostConfig.BlkioDeviceWriteBps}}{{.Rate}}{{end}}", data.Identifier())
603604
assert.Assert(t, strings.Contains(inspectOut, "2097152"))
604605
},
@@ -627,7 +628,7 @@ func TestRunBlkioSettingCgroupV2(t *testing.T) {
627628
return &test.Expected{
628629
ExitCode: 0,
629630
Output: expect.All(
630-
func(stdout string, t *testing.T) {
631+
func(stdout string, t tig.T) {
631632
inspectOut := helpers.Capture("inspect", "--format", "{{range .HostConfig.BlkioDeviceReadIOps}}{{.Rate}}{{end}}", data.Identifier())
632633
assert.Assert(t, strings.Contains(inspectOut, "1000"))
633634
},
@@ -656,7 +657,7 @@ func TestRunBlkioSettingCgroupV2(t *testing.T) {
656657
return &test.Expected{
657658
ExitCode: 0,
658659
Output: expect.All(
659-
func(stdout string, t *testing.T) {
660+
func(stdout string, t tig.T) {
660661
inspectOut := helpers.Capture("inspect", "--format", "{{range .HostConfig.BlkioDeviceWriteIOps}}{{.Rate}}{{end}}", data.Identifier())
661662
assert.Assert(t, strings.Contains(inspectOut, "2000"))
662663
},
@@ -691,7 +692,7 @@ func TestRunCPURealTimeSettingCgroupV1(t *testing.T) {
691692
return &test.Expected{
692693
ExitCode: 0,
693694
Output: expect.All(
694-
func(stdout string, t *testing.T) {
695+
func(stdout string, t tig.T) {
695696
rtRuntime := helpers.Capture("inspect", "--format", "{{.HostConfig.CPURealtimeRuntime}}", data.Identifier())
696697
rtPeriod := helpers.Capture("inspect", "--format", "{{.HostConfig.CPURealtimePeriod}}", data.Identifier())
697698
assert.Assert(t, strings.Contains(rtRuntime, "950000"))

0 commit comments

Comments
 (0)