Skip to content

Commit 92a7ac1

Browse files
thaJeztahglours
authored andcommitted
fix mixed assertion libraries in tests
Before this, assertion libraries were mixed, sometimes even in the same file. git grep -l '"gotest.tools/v3/' | wc -l 75 git grep -l '"github.com/stretchr/testify' | wc -l 24 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent a97738d commit 92a7ac1

31 files changed

Lines changed: 274 additions & 268 deletions

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ linters:
3939
desc: use stdlib slices package
4040
- pkg: gopkg.in/yaml.v2
4141
desc: compose-go uses yaml.v3
42+
- pkg: github.com/stretchr/testify/assert
43+
desc: Use "gotest.tools/v3/assert" instead
44+
- pkg: github.com/stretchr/testify/require
45+
desc: Use "gotest.tools/v3/assert" instead
46+
- pkg: github.com/stretchr/testify/suite
47+
desc: Do not use
4248
forbidigo:
4349
analyze-types: true
4450
forbid:

cmd/compose/options_test.go

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727

2828
"github.com/compose-spec/compose-go/v2/types"
2929
"github.com/docker/cli/cli/streams"
30-
"github.com/stretchr/testify/require"
3130
"go.uber.org/mock/gomock"
31+
"gotest.tools/v3/assert"
3232

3333
"github.com/docker/compose/v5/pkg/mocks"
3434
)
@@ -56,15 +56,14 @@ func TestApplyPlatforms_InferFromRuntime(t *testing.T) {
5656

5757
t.Run("SinglePlatform", func(t *testing.T) {
5858
project := makeProject()
59-
require.NoError(t, applyPlatforms(project, true))
60-
require.EqualValues(t, []string{"alice/32"}, project.Services["test"].Build.Platforms)
59+
assert.NilError(t, applyPlatforms(project, true))
60+
assert.DeepEqual(t, types.StringList{"alice/32"}, project.Services["test"].Build.Platforms)
6161
})
6262

6363
t.Run("MultiPlatform", func(t *testing.T) {
6464
project := makeProject()
65-
require.NoError(t, applyPlatforms(project, false))
66-
require.EqualValues(t, []string{"linux/amd64", "linux/arm64", "alice/32"},
67-
project.Services["test"].Build.Platforms)
65+
assert.NilError(t, applyPlatforms(project, false))
66+
assert.DeepEqual(t, types.StringList{"linux/amd64", "linux/arm64", "alice/32"}, project.Services["test"].Build.Platforms)
6867
})
6968
}
7069

@@ -92,15 +91,14 @@ func TestApplyPlatforms_DockerDefaultPlatform(t *testing.T) {
9291

9392
t.Run("SinglePlatform", func(t *testing.T) {
9493
project := makeProject()
95-
require.NoError(t, applyPlatforms(project, true))
96-
require.EqualValues(t, []string{"linux/amd64"}, project.Services["test"].Build.Platforms)
94+
assert.NilError(t, applyPlatforms(project, true))
95+
assert.DeepEqual(t, types.StringList{"linux/amd64"}, project.Services["test"].Build.Platforms)
9796
})
9897

9998
t.Run("MultiPlatform", func(t *testing.T) {
10099
project := makeProject()
101-
require.NoError(t, applyPlatforms(project, false))
102-
require.EqualValues(t, []string{"linux/amd64", "linux/arm64"},
103-
project.Services["test"].Build.Platforms)
100+
assert.NilError(t, applyPlatforms(project, false))
101+
assert.DeepEqual(t, types.StringList{"linux/amd64", "linux/arm64"}, project.Services["test"].Build.Platforms)
104102
})
105103
}
106104

@@ -128,13 +126,13 @@ func TestApplyPlatforms_UnsupportedPlatform(t *testing.T) {
128126

129127
t.Run("SinglePlatform", func(t *testing.T) {
130128
project := makeProject()
131-
require.EqualError(t, applyPlatforms(project, true),
129+
assert.Error(t, applyPlatforms(project, true),
132130
`service "test" build.platforms does not support value set by DOCKER_DEFAULT_PLATFORM: commodore/64`)
133131
})
134132

135133
t.Run("MultiPlatform", func(t *testing.T) {
136134
project := makeProject()
137-
require.EqualError(t, applyPlatforms(project, false),
135+
assert.Error(t, applyPlatforms(project, false),
138136
`service "test" build.platforms does not support value set by DOCKER_DEFAULT_PLATFORM: commodore/64`)
139137
})
140138
}
@@ -179,7 +177,7 @@ func TestIsRemoteConfig(t *testing.T) {
179177
},
180178
}
181179
got := isRemoteConfig(cli, opts)
182-
require.Equal(t, tt.want, got)
180+
assert.Equal(t, tt.want, got)
183181
})
184182
}
185183
}
@@ -206,7 +204,7 @@ func TestDisplayLocationRemoteStack(t *testing.T) {
206204
displayLocationRemoteStack(cli, project, options)
207205

208206
output := buf.String()
209-
require.Equal(t, output, fmt.Sprintf("Your compose stack %q is stored in %q\n", "oci://registry.example.com/stack:latest", "/tmp/test"))
207+
assert.Equal(t, output, fmt.Sprintf("Your compose stack %q is stored in %q\n", "oci://registry.example.com/stack:latest", "/tmp/test"))
210208
}
211209

212210
func TestDisplayInterpolationVariables(t *testing.T) {
@@ -227,7 +225,7 @@ services:
227225
- UNSET_VAR # optional without default
228226
`
229227
composePath := filepath.Join(tmpDir, "docker-compose.yml")
230-
require.NoError(t, os.WriteFile(composePath, []byte(composeContent), 0o644))
228+
assert.NilError(t, os.WriteFile(composePath, []byte(composeContent), 0o644))
231229

232230
buf := new(bytes.Buffer)
233231
cli := mocks.NewMockCli(ctrl)
@@ -244,8 +242,8 @@ services:
244242

245243
// Extract variables from the model
246244
info, noVariables, err := extractInterpolationVariablesFromModel(t.Context(), cli, projectOptions, []string{})
247-
require.NoError(t, err)
248-
require.False(t, noVariables)
245+
assert.NilError(t, err)
246+
assert.Assert(t, noVariables == false)
249247

250248
// Display the variables
251249
displayInterpolationVariables(cli.Out(), info)
@@ -267,7 +265,7 @@ services:
267265
actualOutput := buf.String()
268266

269267
// Compare normalized strings
270-
require.Equal(t,
268+
assert.Equal(t,
271269
normalizeSpaces(expected),
272270
normalizeSpaces(actualOutput),
273271
"\nExpected:\n%s\nGot:\n%s", expected, actualOutput)
@@ -370,14 +368,13 @@ func TestConfirmRemoteIncludes(t *testing.T) {
370368
err := confirmRemoteIncludes(cli, tt.opts, tt.assumeYes)
371369

372370
if tt.wantErr {
373-
require.Error(t, err)
374-
require.Equal(t, tt.errMessage, err.Error())
371+
assert.Error(t, err, tt.errMessage)
375372
} else {
376-
require.NoError(t, err)
373+
assert.NilError(t, err)
377374
}
378375

379376
if tt.wantOutput != "" {
380-
require.Equal(t, tt.wantOutput, buf.String())
377+
assert.Equal(t, tt.wantOutput, buf.String())
381378
}
382379
buf.Reset()
383380
})

cmd/compose/top_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import (
2121
"strings"
2222
"testing"
2323

24-
"github.com/stretchr/testify/assert"
25-
"github.com/stretchr/testify/require"
24+
"gotest.tools/v3/assert"
2625

2726
"github.com/docker/compose/v5/pkg/api"
2827
)
@@ -221,20 +220,20 @@ func TestRunTopCore(t *testing.T) {
221220

222221
t.Run(tc.name, func(t *testing.T) {
223222
header, entries := collectTop([]api.ContainerProcSummary{summary})
224-
assert.Equal(t, tc.header, header)
225-
assert.Equal(t, tc.entries, entries)
223+
assert.DeepEqual(t, tc.header, header)
224+
assert.DeepEqual(t, tc.entries, entries)
226225

227226
var buf bytes.Buffer
228227
err := topPrint(&buf, header, entries)
229228

230-
require.NoError(t, err)
229+
assert.NilError(t, err)
231230
assert.Equal(t, tc.output, buf.String())
232231
})
233232
}
234233

235234
t.Run("all", func(t *testing.T) {
236235
header, entries := collectTop(all)
237-
assert.Equal(t, topHeader{
236+
assert.DeepEqual(t, topHeader{
238237
"SERVICE": 0,
239238
"#": 1,
240239
"UID": 2,
@@ -247,7 +246,7 @@ func TestRunTopCore(t *testing.T) {
247246
"GID": 9,
248247
"CMD": 10,
249248
}, header)
250-
assert.Equal(t, []topEntries{
249+
assert.DeepEqual(t, []topEntries{
251250
{
252251
"SERVICE": "simple",
253252
"#": "1",
@@ -308,7 +307,7 @@ func TestRunTopCore(t *testing.T) {
308307

309308
var buf bytes.Buffer
310309
err := topPrint(&buf, header, entries)
311-
require.NoError(t, err)
310+
assert.NilError(t, err)
312311
assert.Equal(t, trim(`
313312
SERVICE # UID PID PPID C STIME TTY TIME GID CMD
314313
simple 1 root 1 1 0 12:00 ? 00:00:01 - /entrypoint

cmd/compose/viz_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ package compose
1919
import (
2020
"testing"
2121

22-
"github.com/stretchr/testify/assert"
23-
"github.com/stretchr/testify/require"
22+
"gotest.tools/v3/assert"
2423
)
2524

2625
func TestPreferredIndentationStr(t *testing.T) {
@@ -84,10 +83,10 @@ func TestPreferredIndentationStr(t *testing.T) {
8483
t.Run(tt.name, func(t *testing.T) {
8584
got, err := preferredIndentationStr(tt.args.size, tt.args.useSpace)
8685
if tt.wantErr {
87-
require.Errorf(t, err, "preferredIndentationStr(%v, %v)", tt.args.size, tt.args.useSpace)
86+
assert.ErrorContains(t, err, "invalid indentation size", "preferredIndentationStr(%v,%v)", tt.args.size, tt.args.useSpace)
8887
} else {
89-
require.NoError(t, err)
90-
assert.Equalf(t, tt.want, got, "preferredIndentationStr(%v, %v)", tt.args.size, tt.args.useSpace)
88+
assert.NilError(t, err)
89+
assert.Equal(t, tt.want, got)
9190
}
9291
})
9392
}

go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ require (
4343
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
4444
github.com/spf13/cobra v1.10.2
4545
github.com/spf13/pflag v1.0.10
46-
github.com/stretchr/testify v1.11.1
4746
github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375
4847
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0
4948
go.opentelemetry.io/otel v1.42.0
@@ -73,7 +72,6 @@ require (
7372
github.com/containerd/ttrpc v1.2.7 // indirect
7473
github.com/containerd/typeurl/v2 v2.2.3 // indirect
7574
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
76-
github.com/davecgh/go-spew v1.1.1 // indirect
7775
github.com/docker/distribution v2.8.3+incompatible // indirect
7876
github.com/docker/docker-credential-helpers v0.9.5 // indirect
7977
github.com/docker/go-connections v0.6.0 // indirect
@@ -113,7 +111,6 @@ require (
113111
github.com/pelletier/go-toml v1.9.5 // indirect
114112
github.com/pkg/errors v0.9.1 // indirect
115113
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
116-
github.com/pmezard/go-difflib v1.0.0 // indirect
117114
github.com/rivo/uniseg v0.4.7 // indirect
118115
github.com/russross/blackfriday/v2 v2.1.0 // indirect
119116
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 // indirect

internal/desktop/client_test.go

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

24-
"github.com/stretchr/testify/require"
24+
"gotest.tools/v3/assert"
2525
)
2626

2727
func TestClientPing(t *testing.T) {
@@ -41,8 +41,8 @@ func TestClientPing(t *testing.T) {
4141
now := time.Now()
4242

4343
ret, err := client.Ping(t.Context())
44-
require.NoError(t, err)
44+
assert.NilError(t, err)
4545

4646
serverTime := time.Unix(0, ret.ServerTime)
47-
require.True(t, now.Before(serverTime))
47+
assert.Assert(t, now.Before(serverTime))
4848
}

internal/tracing/attributes_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"testing"
2121

2222
"github.com/compose-spec/compose-go/v2/types"
23-
"github.com/stretchr/testify/require"
23+
"gotest.tools/v3/assert"
2424
)
2525

2626
func TestProjectHash(t *testing.T) {
@@ -53,15 +53,15 @@ func TestProjectHash(t *testing.T) {
5353
}
5454

5555
hashA, ok := projectHash(projA)
56-
require.True(t, ok)
57-
require.NotEmpty(t, hashA)
56+
assert.Assert(t, ok)
57+
assert.Assert(t, hashA != "")
5858
hashB, ok := projectHash(projB)
59-
require.True(t, ok)
60-
require.NotEmpty(t, hashB)
61-
require.Equal(t, hashA, hashB)
59+
assert.Assert(t, ok)
60+
assert.Assert(t, hashB != "")
61+
assert.Equal(t, hashA, hashB)
6262

6363
hashC, ok := projectHash(projC)
64-
require.True(t, ok)
65-
require.NotEmpty(t, hashC)
66-
require.NotEqual(t, hashC, hashA)
64+
assert.Assert(t, ok)
65+
assert.Assert(t, hashC != "")
66+
assert.Assert(t, hashC != hashA)
6767
}

internal/tracing/tracing_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
"github.com/docker/cli/cli/command"
2323
"github.com/docker/cli/cli/context/store"
24-
"github.com/stretchr/testify/require"
24+
"gotest.tools/v3/assert"
2525

2626
"github.com/docker/compose/v5/internal/tracing"
2727
)
@@ -52,9 +52,9 @@ func TestExtractOtelFromContext(t *testing.T) {
5252
},
5353
Endpoints: make(map[string]any),
5454
})
55-
require.NoError(t, err)
55+
assert.NilError(t, err)
5656

5757
cfg, err := tracing.ConfigFromDockerContext(st, "test")
58-
require.NoError(t, err)
59-
require.Equal(t, "localhost:1234", cfg.Endpoint)
58+
assert.NilError(t, err)
59+
assert.Equal(t, "localhost:1234", cfg.Endpoint)
6060
}

pkg/compose/dependencies_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ import (
2424
"testing"
2525

2626
"github.com/compose-spec/compose-go/v2/types"
27-
testify "github.com/stretchr/testify/assert"
28-
"github.com/stretchr/testify/require"
2927
"gotest.tools/v3/assert"
28+
is "gotest.tools/v3/assert/cmp"
3029

3130
"github.com/docker/compose/v5/pkg/utils"
3231
)
@@ -85,11 +84,11 @@ func TestTraversalWithMultipleParents(t *testing.T) {
8584
svc <- service
8685
return nil
8786
})
88-
require.NoError(t, err, "Error during iteration")
87+
assert.NilError(t, err, "Error during iteration")
8988
close(svc)
9089
<-done
9190

92-
testify.Len(t, seen, 101)
91+
assert.Check(t, is.Len(seen, 101))
9392
for svc, count := range seen {
9493
assert.Equal(t, 1, count, "Service: %s", svc)
9594
}
@@ -101,8 +100,8 @@ func TestInDependencyUpCommandOrder(t *testing.T) {
101100
order = append(order, service)
102101
return nil
103102
})
104-
require.NoError(t, err, "Error during iteration")
105-
require.Equal(t, []string{"test3", "test2", "test1"}, order)
103+
assert.NilError(t, err, "Error during iteration")
104+
assert.DeepEqual(t, []string{"test3", "test2", "test1"}, order)
106105
}
107106

108107
func TestInDependencyReverseDownCommandOrder(t *testing.T) {
@@ -111,8 +110,8 @@ func TestInDependencyReverseDownCommandOrder(t *testing.T) {
111110
order = append(order, service)
112111
return nil
113112
})
114-
require.NoError(t, err, "Error during iteration")
115-
require.Equal(t, []string{"test1", "test2", "test3"}, order)
113+
assert.NilError(t, err, "Error during iteration")
114+
assert.DeepEqual(t, []string{"test1", "test2", "test3"}, order)
116115
}
117116

118117
func TestBuildGraph(t *testing.T) {

0 commit comments

Comments
 (0)