Skip to content

Commit 5d92fda

Browse files
committed
More
Signed-off-by: apostasie <spam_blackhole@farcloser.world>
1 parent ae4905e commit 5d92fda

File tree

18 files changed

+177
-181
lines changed

18 files changed

+177
-181
lines changed

cmd/nerdctl/ipfs/ipfs_compose_linux_test.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestIPFSCompNoBuild(t *testing.T) {
5757

5858
testCase.Setup = func(data test.Data, helpers test.Helpers) {
5959
// Start Kubo
60-
ipfsRegistry = registry.NewKuboRegistry(data, helpers, t, nil, 0, nil)
60+
ipfsRegistry = registry.NewKuboRegistry(data, helpers, nil, 0, nil)
6161
ipfsRegistry.Setup(data, helpers)
6262
data.Labels().Set(ipfsAddrKey, fmt.Sprintf("/ip4/%s/tcp/%d", ipfsRegistry.IP, ipfsRegistry.Port))
6363

@@ -270,6 +270,7 @@ COPY index.html /usr/share/nginx/html/index.html
270270
}
271271

272272
func composeUP(data test.Data, helpers test.Helpers, dockerComposeYAML string, opts string) {
273+
// FIXME: get rid of ComposeDir and remove the typecast
273274
comp := testutil.NewComposeDir(helpers.T(), dockerComposeYAML)
274275
// defer comp.CleanUp()
275276

@@ -319,9 +320,13 @@ func composeUP(data test.Data, helpers test.Helpers, dockerComposeYAML string, o
319320

320321
if !wordpressWorking {
321322
ccc := helpers.Capture("ps", "-a")
323+
stdout := helpers.Capture("logs", projectName+"-wordpress-1")
324+
stderr := helpers.Err("logs", projectName+"-wordpress-1")
322325
helpers.T().Log(ccc)
323-
helpers.T().Error(helpers.Err("logs", projectName+"-wordpress-1"))
324-
helpers.T().Fatalf("wordpress is not working %v", err)
326+
helpers.T().Log(stdout)
327+
helpers.T().Log(stderr)
328+
helpers.T().Log(fmt.Sprintf("wordpress is not working %v", err))
329+
helpers.T().FailNow()
325330
}
326331

327332
helpers.Ensure("compose", "-f", comp.YAMLFullPath(), "down", "-v")

cmd/nerdctl/ipfs/ipfs_kubo_linux_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestIPFSAddrWithKubo(t *testing.T) {
4848
testCase.Setup = func(data test.Data, helpers test.Helpers) {
4949
helpers.Ensure("pull", "--quiet", testutil.CommonImage)
5050

51-
ipfsRegistry = registry.NewKuboRegistry(data, helpers, t, nil, 0, nil)
51+
ipfsRegistry = registry.NewKuboRegistry(data, helpers, nil, 0, nil)
5252
ipfsRegistry.Setup(data, helpers)
5353
ipfsAddr := fmt.Sprintf("/ip4/%s/tcp/%d", ipfsRegistry.IP, ipfsRegistry.Port)
5454
data.Labels().Set(ipfsAddrKey, ipfsAddr)

mod/tigron/internal/mocks/t.go

+9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ type (
4848

4949
TTempDirIn struct{}
5050
TTempDirOut = string
51+
52+
TSkipIn []any
53+
TSkipOut struct{}
5154
)
5255

5356
type MockT struct {
@@ -93,3 +96,9 @@ func (m *MockT) TempDir() string {
9396

9497
return ""
9598
}
99+
100+
func (m *MockT) Skip(args ...any) {
101+
if handler := m.Retrieve(); handler != nil {
102+
handler.(mimicry.Function[TSkipIn, TSkipOut])(args)
103+
}
104+
}

mod/tigron/test/case.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
2828
"github.com/containerd/nerdctl/mod/tigron/internal/formatter"
29+
"github.com/containerd/nerdctl/mod/tigron/tig"
2930
)
3031

3132
// Case describes an entire test-case, including data, setup and cleanup routines, command and
@@ -63,7 +64,7 @@ type Case struct {
6364

6465
// Private
6566
helpers Helpers
66-
t *testing.T
67+
t tig.T
6768
parent *Case
6869
}
6970

@@ -151,7 +152,7 @@ func (test *Case) Run(t *testing.T) {
151152
if test.Require != nil {
152153
shouldRun, message := test.Require.Check(test.Data, test.helpers)
153154
if !shouldRun {
154-
test.t.Skipf("test skipped as: %s", message)
155+
test.t.Skip("test skipped as: " + message)
155156
}
156157

157158
if test.Require.Setup != nil {
@@ -180,7 +181,7 @@ func (test *Case) Run(t *testing.T) {
180181

181182
// Set parallel unless asked not to
182183
if !test.NoParallel {
183-
test.t.Parallel()
184+
subT.Parallel()
184185
}
185186

186187
// Execute cleanups now
@@ -197,7 +198,7 @@ func (test *Case) Run(t *testing.T) {
197198
}
198199

199200
// Register the cleanups, in reverse
200-
test.t.Cleanup(func() {
201+
subT.Cleanup(func() {
201202
test.t.Helper()
202203
test.t.Log(
203204
"\n\n" + formatter.Table(
@@ -263,14 +264,14 @@ func (test *Case) Run(t *testing.T) {
263264

264265
if len(test.SubTests) > 0 {
265266
// Now go for the subtests
266-
test.t.Logf("\n%s️ %q: into subtests prep", subinDecorator, test.t.Name())
267+
test.t.Log(fmt.Sprintf("\n%s️ %q: into subtests prep", subinDecorator, test.t.Name()))
267268

268269
for _, subTest := range test.SubTests {
269270
subTest.parent = test
270-
subTest.Run(test.t)
271+
subTest.Run(subT)
271272
}
272273

273-
test.t.Logf("\n%s️ %q: done with subtests prep", suboutDecorator, test.t.Name())
274+
test.t.Log(fmt.Sprintf("\n%s️ %q: done with subtests prep", suboutDecorator, test.t.Name()))
274275
}
275276
}
276277

mod/tigron/test/command.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import (
2323
"os"
2424
"strconv"
2525
"strings"
26-
"testing"
2726
"time"
2827

2928
"github.com/containerd/nerdctl/mod/tigron/internal"
3029
"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
3130
"github.com/containerd/nerdctl/mod/tigron/internal/com"
3231
"github.com/containerd/nerdctl/mod/tigron/internal/formatter"
32+
"github.com/containerd/nerdctl/mod/tigron/tig"
3333
)
3434

3535
const (
@@ -59,7 +59,7 @@ type CustomizableCommand interface {
5959
// default it pass any that is defined by WithEnv
6060
WithBlacklist(env []string)
6161
// T returns the current testing object
62-
T() *testing.T
62+
T() tig.T
6363

6464
// withEnv *copies* the passed map to the environment of the command to be executed
6565
// Note that this will override any variable defined in the embedding environment
@@ -69,7 +69,7 @@ type CustomizableCommand interface {
6969
withTempDir(path string)
7070
// WithConfig allows passing custom config properties from the test to the base command
7171
withConfig(config Config)
72-
withT(t *testing.T)
72+
withT(t tig.T)
7373
// Clear does a clone, but will clear binary and arguments while retaining the env, or any other
7474
// custom properties Gotcha: if genericCommand is embedded with a custom Run and an overridden
7575
// clear to return the embedding type the result will be the embedding command, no longer the
@@ -102,7 +102,7 @@ type GenericCommand struct {
102102
TempDir string
103103
Env map[string]string
104104

105-
t *testing.T
105+
t tig.T
106106

107107
cmd *com.Command
108108
async bool
@@ -337,7 +337,7 @@ func (gc *GenericCommand) Clone() TestableCommand {
337337
return &clone
338338
}
339339

340-
func (gc *GenericCommand) T() *testing.T {
340+
func (gc *GenericCommand) T() tig.T {
341341
return gc.t
342342
}
343343

@@ -361,7 +361,7 @@ func (gc *GenericCommand) clear() TestableCommand {
361361
return &comcopy
362362
}
363363

364-
func (gc *GenericCommand) withT(t *testing.T) {
364+
func (gc *GenericCommand) withT(t tig.T) {
365365
t.Helper()
366366
gc.t = t
367367
}

mod/tigron/test/helpers.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package test
1818

1919
import (
20-
"testing"
21-
2220
"github.com/containerd/nerdctl/mod/tigron/internal"
2321
"github.com/containerd/nerdctl/mod/tigron/tig"
2422
)
@@ -28,7 +26,7 @@ import (
2826
type helpersInternal struct {
2927
cmdInternal CustomizableCommand
3028

31-
t *testing.T
29+
t tig.T
3230
}
3331

3432
// Ensure will run a command and make sure it is successful.
@@ -104,6 +102,6 @@ func (help *helpersInternal) Write(key ConfigKey, value ConfigValue) {
104102
help.cmdInternal.write(key, value)
105103
}
106104

107-
func (help *helpersInternal) T() *testing.T {
105+
func (help *helpersInternal) T() tig.T {
108106
return help.t
109107
}

mod/tigron/test/interfaces.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ package test
1919
import (
2020
"io"
2121
"os"
22-
"testing"
2322
"time"
23+
24+
"github.com/containerd/nerdctl/mod/tigron/tig"
2425
)
2526

2627
// DataLabels holds key-value test information set by the test authors.
@@ -93,7 +94,7 @@ type Helpers interface {
9394
Write(key ConfigKey, value ConfigValue)
9495

9596
// T returns the current testing object.
96-
T() *testing.T
97+
T() tig.T
9798
}
9899

99100
// The TestableCommand interface represents a low-level command to execute, typically to be compared

mod/tigron/test/test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
package test
1818

1919
import (
20-
"testing"
20+
"github.com/containerd/nerdctl/mod/tigron/tig"
2121
)
2222

2323
// Testable TODO.
2424
type Testable interface {
25-
CustomCommand(testCase *Case, t *testing.T) CustomizableCommand
26-
AmbientRequirements(testCase *Case, t *testing.T)
25+
CustomCommand(testCase *Case, t tig.T) CustomizableCommand
26+
AmbientRequirements(testCase *Case, t tig.T)
2727
}
2828

2929
// FIXME

mod/tigron/tig/t.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ type T interface {
3737
Log(args ...any)
3838
Name() string
3939
TempDir() string
40+
Skip(args ...any)
4041
}

pkg/testutil/compose.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,26 @@ package testutil
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"os"
2223
"path/filepath"
23-
"testing"
2424

2525
"github.com/compose-spec/compose-go/v2/loader"
2626
compose "github.com/compose-spec/compose-go/v2/types"
27+
28+
"github.com/containerd/nerdctl/mod/tigron/tig"
2729
)
2830

2931
type ComposeDir struct {
30-
t testing.TB
32+
t tig.T
3133
dir string
3234
yamlBasePath string
3335
}
3436

3537
func (cd *ComposeDir) WriteFile(name, content string) {
3638
if err := os.WriteFile(filepath.Join(cd.dir, name), []byte(content), 0644); err != nil {
37-
cd.t.Fatal(err)
39+
cd.t.Log(fmt.Sprintf("Failed to create file %s", err))
40+
cd.t.FailNow()
3841
}
3942
}
4043

@@ -54,10 +57,11 @@ func (cd *ComposeDir) CleanUp() {
5457
os.RemoveAll(cd.dir)
5558
}
5659

57-
func NewComposeDir(t testing.TB, dockerComposeYAML string) *ComposeDir {
60+
func NewComposeDir(t tig.T, dockerComposeYAML string) *ComposeDir {
5861
tmpDir, err := os.MkdirTemp("", "nerdctl-compose-test")
5962
if err != nil {
60-
t.Fatal(err)
63+
t.Log(fmt.Sprintf("Failed to create temp dir: %s", err))
64+
t.FailNow()
6165
}
6266
cd := &ComposeDir{
6367
t: t,

pkg/testutil/nerdtest/command.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
package nerdtest
1818

1919
import (
20+
"fmt"
2021
"os"
2122
"os/exec"
2223
"path/filepath"
23-
"testing"
2424

2525
"gotest.tools/v3/assert"
2626

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

2930
"github.com/containerd/nerdctl/v2/pkg/rootlessutil"
3031
"github.com/containerd/nerdctl/v2/pkg/testutil"
@@ -49,7 +50,7 @@ func getTarget() string {
4950
return testutil.GetTarget()
5051
}
5152

52-
func newNerdCommand(conf test.Config, t *testing.T) *nerdCommand {
53+
func newNerdCommand(conf test.Config, t tig.T) *nerdCommand {
5354
// Decide what binary we are running
5455
var err error
5556
var binary string
@@ -58,7 +59,8 @@ func newNerdCommand(conf test.Config, t *testing.T) *nerdCommand {
5859
case targetNerdctl:
5960
binary, err = exec.LookPath(trgt)
6061
if err != nil {
61-
t.Fatalf("unable to find binary %q: %v", trgt, err)
62+
t.Log(fmt.Sprintf("unable to find binary %q: %v", trgt, err))
63+
t.FailNow()
6264
}
6365
// Set the default namespace if we do not have something already
6466
if conf.Read(Namespace) == "" {
@@ -67,13 +69,16 @@ func newNerdCommand(conf test.Config, t *testing.T) *nerdCommand {
6769
case targetDocker:
6870
binary, err = exec.LookPath(trgt)
6971
if err != nil {
70-
t.Fatalf("unable to find binary %q: %v", trgt, err)
72+
t.Log(fmt.Sprintf("unable to find binary %q: %v", trgt, err))
73+
t.FailNow()
7174
}
7275
if err = exec.Command("docker", "compose", "version").Run(); err != nil {
73-
t.Fatalf("docker does not support compose: %v", err)
76+
t.Log(fmt.Sprintf("docker does not support compose: %v", err))
77+
t.FailNow()
7478
}
7579
default:
76-
t.Fatalf("unknown target %q", getTarget())
80+
t.Log(fmt.Sprintf("unknown target %q", getTarget()))
81+
t.FailNow()
7782
}
7883

7984
// Create the base command, with the right binary, t

0 commit comments

Comments
 (0)