Skip to content

Commit ee5cabe

Browse files
authored
test: migrated from stretchr/testify to go-openapi/testify/v2 (#3285)
* upgraded test assertions to their generic version * added nolint directives on changed lines that already held linting issues (for follow-up relinting) Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent c1ef11c commit ee5cabe

File tree

7 files changed

+57
-57
lines changed

7 files changed

+57
-57
lines changed

diff/array_diff_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ package diff
66
import (
77
"testing"
88

9-
"github.com/stretchr/testify/require"
9+
"github.com/go-openapi/testify/v2/require"
1010
)
1111

1212
func TestArrayDiff(t *testing.T) {
1313
listA := []string{"abc", "def", "ghi", "jkl"}
1414
added, deleted, common := fromStringArray(listA).DiffsTo(listA)
1515
require.Equal(t, []string{}, added)
1616
require.Equal(t, []string{}, deleted)
17-
require.ElementsMatch(t, listA, common)
17+
require.ElementsMatchT(t, listA, common)
1818

1919
listB := []string{"abc", "ghi", "jkl", "xyz", "fgh"}
2020
added, deleted, common = fromStringArray(listA).DiffsTo(listB)
21-
require.ElementsMatch(t, []string{"xyz", "fgh"}, added)
22-
require.ElementsMatch(t, []string{"def"}, deleted)
23-
require.ElementsMatch(t, []string{"abc", "ghi", "jkl"}, common)
21+
require.ElementsMatchT(t, []string{"xyz", "fgh"}, added)
22+
require.ElementsMatchT(t, []string{"def"}, deleted)
23+
require.ElementsMatchT(t, []string{"abc", "ghi", "jkl"}, common)
2424
}
2525

2626
func TestMapDiff(t *testing.T) {

diff/checks_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"testing"
99
"time"
1010

11-
"github.com/stretchr/testify/assert"
11+
"github.com/go-openapi/testify/v2/assert"
1212

1313
"github.com/go-openapi/spec"
1414
)
@@ -166,17 +166,17 @@ func Test_isRef(t *testing.T) {
166166
r := spec.RefSchema("#/definitions/Bob")
167167
p := spec.Int16Property()
168168

169-
assert.True(t, isRefType(r))
170-
assert.False(t, isRefType(p))
169+
assert.TrueT(t, isRefType(r))
170+
assert.FalseT(t, isRefType(p))
171171

172172
refb := spec.Refable{Ref: r.Ref}
173-
assert.True(t, isRefType(refb))
173+
assert.TrueT(t, isRefType(refb))
174174

175175
ss := spec.SimpleSchema{}
176-
assert.False(t, isRefType(&ss))
176+
assert.FalseT(t, isRefType(&ss))
177177

178178
ro := time.Timer{}
179-
assert.False(t, isRefType(ro))
179+
assert.FalseT(t, isRefType(ro))
180180
}
181181

182182
func Test_compareEnums(t *testing.T) {

diff/difference_location_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ package diff
66
import (
77
"testing"
88

9-
"github.com/stretchr/testify/assert"
9+
"github.com/go-openapi/testify/v2/assert"
1010
)
1111

1212
func TestDifferenceLocation_AddNode(t *testing.T) {
1313
parentLocation := DifferenceLocation{URL: "http://bob", Method: "meth", Node: &Node{Field: "Parent", TypeName: "bobtype"}}
1414

1515
newLocation := parentLocation.AddNode(&Node{Field: "child1"})
16-
assert.Equal(t, "child1", newLocation.Node.ChildNode.Field)
16+
assert.EqualT(t, "child1", newLocation.Node.ChildNode.Field)
1717

1818
newLocation2 := parentLocation.AddNode(&Node{Field: "child2"})
19-
assert.Equal(t, "child2", newLocation2.Node.ChildNode.Field)
19+
assert.EqualT(t, "child2", newLocation2.Node.ChildNode.Field)
2020
}

diff/difftypes_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"os"
1111
"testing"
1212

13-
"github.com/stretchr/testify/assert"
14-
"github.com/stretchr/testify/require"
13+
"github.com/go-openapi/testify/v2/assert"
14+
"github.com/go-openapi/testify/v2/require"
1515
)
1616

1717
func TestSpecChangeCode(t *testing.T) {
@@ -21,28 +21,28 @@ func TestSpecChangeCode(t *testing.T) {
2121
}()
2222

2323
c := NoChangeDetected
24-
assert.Equal(t, toLongStringSpecChangeCode[NoChangeDetected], c.Description())
25-
assert.Equal(t, "UNDEFINED", SpecChangeCode(9999999999999).Description())
24+
assert.EqualT(t, toLongStringSpecChangeCode[NoChangeDetected], c.Description())
25+
assert.EqualT(t, "UNDEFINED", SpecChangeCode(9999999999999).Description())
2626

2727
res, err := json.Marshal(c)
2828
require.NoError(t, err)
29-
assert.JSONEq(t, `"NoChangeDetected"`, string(res))
29+
assert.JSONEqT(t, `"NoChangeDetected"`, string(res))
3030

3131
var d SpecChangeCode
3232
in := []byte(`"NoChangeDetected"`)
3333
err = json.Unmarshal(in, &d)
3434
require.NoError(t, err)
35-
assert.Equal(t, NoChangeDetected, d)
35+
assert.EqualT(t, NoChangeDetected, d)
3636

3737
in = []byte(`"dummy"`) // invalid enum
3838
err = json.Unmarshal(in, &d)
3939
require.Error(t, err)
40-
assert.Contains(t, err.Error(), "unknown enum value")
40+
assert.StringContainsT(t, err.Error(), "unknown enum value")
4141

4242
in = []byte(`{"dummy"`) // invalid json
4343
err = json.Unmarshal(in, &d)
4444
require.Error(t, err)
45-
assert.Contains(t, err.Error(), "JSON")
45+
assert.StringContainsT(t, err.Error(), "JSON")
4646
}
4747

4848
func TestCompatibiliyCode(t *testing.T) {
@@ -52,25 +52,25 @@ func TestCompatibiliyCode(t *testing.T) {
5252
}()
5353

5454
c := Breaking
55-
assert.Equal(t, toStringCompatibility[Breaking], c.String())
55+
assert.EqualT(t, toStringCompatibility[Breaking], c.String())
5656

5757
res, err := json.Marshal(c)
5858
require.NoError(t, err)
59-
assert.JSONEq(t, `"Breaking"`, string(res))
59+
assert.JSONEqT(t, `"Breaking"`, string(res))
6060

6161
var d Compatibility
6262
in := []byte(`"Breaking"`)
6363
err = json.Unmarshal(in, &d)
6464
require.NoError(t, err)
65-
assert.Equal(t, Breaking, d)
65+
assert.EqualT(t, Breaking, d)
6666

6767
in = []byte(`"dummy"`) // invalid enum
6868
err = json.Unmarshal(in, &d)
6969
require.Error(t, err)
70-
assert.Contains(t, err.Error(), "unknown enum value")
70+
assert.StringContainsT(t, err.Error(), "unknown enum value")
7171

7272
in = []byte(`{"dummy"`) // invalid json
7373
err = json.Unmarshal(in, &d)
7474
require.Error(t, err)
75-
assert.Contains(t, err.Error(), "JSON")
75+
assert.StringContainsT(t, err.Error(), "JSON")
7676
}

diff/schema_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,50 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/stretchr/testify/assert"
10+
"github.com/go-openapi/testify/v2/assert"
1111

1212
"github.com/go-openapi/spec"
1313
)
1414

1515
func TestGetTypeFromSimpleSchema(t *testing.T) {
1616
s := spec.SimpleSchema{Type: "string"}
1717
ty, a := getTypeFromSimpleSchema(&s)
18-
assert.Equal(t, "string", ty)
19-
assert.False(t, a)
18+
assert.EqualT(t, "string", ty)
19+
assert.FalseT(t, a)
2020

2121
arr := spec.SimpleSchema{Type: "array", Items: spec.NewItems().Typed("integer", "int32")}
2222
ty, a = getTypeFromSimpleSchema(&arr)
23-
assert.Equal(t, "integer.int32", ty)
24-
assert.True(t, a)
23+
assert.EqualT(t, "integer.int32", ty)
24+
assert.TrueT(t, a)
2525
}
2626

2727
func TestIsArray(t *testing.T) {
2828
arr := spec.SimpleSchema{Type: "array", Items: spec.NewItems().Typed("integer", "int32")}
29-
assert.True(t, isArray(&arr))
30-
assert.False(t, isArray(&time.Time{}))
29+
assert.TrueT(t, isArray(&arr))
30+
assert.FalseT(t, isArray(&time.Time{}))
3131
}
3232

3333
func TestIsPrimitive(t *testing.T) {
3434
sa := spec.StringOrArray{"string"}
35-
assert.True(t, isPrimitive(sa))
35+
assert.TrueT(t, isPrimitive(sa))
3636

3737
s := spec.Schema{SchemaProps: spec.SchemaProps{Type: sa}}
38-
assert.True(t, isPrimitive(&s))
39-
assert.False(t, isPrimitive(&time.Time{}))
38+
assert.TrueT(t, isPrimitive(&s))
39+
assert.FalseT(t, isPrimitive(&time.Time{}))
4040

4141
sc := spec.Schema{}
42-
assert.False(t, isPrimitive(&sc))
42+
assert.FalseT(t, isPrimitive(&sc))
4343
}
4444

4545
func TestGetSchemaType(t *testing.T) {
4646
tt, a := getSchemaType(time.Time{})
47-
assert.False(t, a)
48-
assert.Equal(t, "unknown", tt)
47+
assert.FalseT(t, a)
48+
assert.EqualT(t, "unknown", tt)
4949

5050
s := spec.SimpleSchema{Type: "string"}
5151
tt, a = getSchemaType(s)
52-
assert.False(t, a)
53-
assert.Equal(t, "string", tt)
52+
assert.FalseT(t, a)
53+
assert.EqualT(t, "string", tt)
5454
}
5555

5656
func TestDefinitionFromRef(t *testing.T) {

diff/spec_analyser_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"strings"
1313
"testing"
1414

15-
"github.com/stretchr/testify/require"
15+
"github.com/go-openapi/testify/v2/require"
1616

1717
"github.com/go-openapi/loads"
1818

@@ -127,7 +127,7 @@ func TestIssue2962(t *testing.T) {
127127

128128
t.Run(fmt.Sprintf("should find %d breaking changes", expectedBreaking), func(t *testing.T) {
129129
require.Len(t, diffs, expectedChanges)
130-
require.Equal(t, expectedBreaking, diffs.BreakingChangeCount())
130+
require.EqualT(t, expectedBreaking, diffs.BreakingChangeCount())
131131
})
132132
})
133133
}

diff/spec_difference_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package diff_test
66
import (
77
"testing"
88

9-
"github.com/stretchr/testify/require"
9+
"github.com/go-openapi/testify/v2/require"
1010

1111
"github.com/go-swagger/go-swagger/cmd/swagger/commands/diff"
1212
)
@@ -16,26 +16,26 @@ func TestMatches(t *testing.T) {
1616
urlOnlyDiff := diff.SpecDifference{DifferenceLocation: diff.DifferenceLocation{URL: "notbob"}}
1717
urlOnlySame := diff.SpecDifference{DifferenceLocation: diff.DifferenceLocation{URL: "bob"}}
1818

19-
require.True(t, urlOnly.Matches(urlOnlySame))
20-
require.False(t, urlOnly.Matches(urlOnlyDiff))
19+
require.TrueT(t, urlOnly.Matches(urlOnlySame))
20+
require.FalseT(t, urlOnly.Matches(urlOnlyDiff))
2121

2222
withMethod := urlOnly
2323
withMethod.DifferenceLocation.Method = "PUT"
2424
withMethodSame := withMethod
2525
withMethodDiff := withMethod
2626
withMethodDiff.DifferenceLocation.Method = "GET"
2727

28-
require.True(t, withMethod.Matches(withMethodSame))
29-
require.False(t, withMethod.Matches(withMethodDiff))
28+
require.TrueT(t, withMethod.Matches(withMethodSame))
29+
require.FalseT(t, withMethod.Matches(withMethodDiff))
3030

3131
withResponse := urlOnly
3232
withResponse.DifferenceLocation.Response = 0
3333
withResponseSame := withResponse
3434
withResponseDiff := withResponse
3535
withResponseDiff.DifferenceLocation.Response = 2
3636

37-
require.True(t, withResponse.Matches(withResponseSame))
38-
require.False(t, withResponse.Matches(withResponseDiff))
37+
require.TrueT(t, withResponse.Matches(withResponseSame))
38+
require.FalseT(t, withResponse.Matches(withResponseDiff))
3939

4040
withNode := urlOnly
4141
withNode.DifferenceLocation.Node = &diff.Node{Field: "FieldA", TypeName: "TypeA"}
@@ -45,13 +45,13 @@ func TestMatches(t *testing.T) {
4545
withNodeDiff := withNode
4646
withNodeDiff.DifferenceLocation.Node = &diff.Node{Field: "FieldA", TypeName: "TypeB"}
4747

48-
require.True(t, withNode.Matches(withNodeSame))
49-
require.False(t, withNode.Matches(withNodeDiff))
48+
require.TrueT(t, withNode.Matches(withNodeSame))
49+
require.FalseT(t, withNode.Matches(withNodeDiff))
5050

5151
withNodeDiff.DifferenceLocation.Node = &diff.Node{Field: "FieldB", TypeName: "TypeA"}
5252

53-
require.True(t, withNode.Matches(withNodeSame))
54-
require.False(t, withNode.Matches(withNodeDiff))
53+
require.TrueT(t, withNode.Matches(withNodeSame))
54+
require.FalseT(t, withNode.Matches(withNodeDiff))
5555

5656
withNestedNode := withNode
5757
withNestedNode.DifferenceLocation = withNestedNode.DifferenceLocation.AddNode(&diff.Node{Field: "ChildA", TypeName: "ChildA"})
@@ -60,6 +60,6 @@ func TestMatches(t *testing.T) {
6060
withNestedNodeDiff := withNode
6161
withNestedNodeDiff.DifferenceLocation = withNestedNodeDiff.DifferenceLocation.AddNode(&diff.Node{Field: "ChildB", TypeName: "ChildA"})
6262

63-
require.True(t, withNestedNode.Matches(withNestedNodeSame))
64-
require.False(t, withNestedNode.Matches(withNestedNodeDiff))
63+
require.TrueT(t, withNestedNode.Matches(withNestedNodeSame))
64+
require.FalseT(t, withNestedNode.Matches(withNestedNodeDiff))
6565
}

0 commit comments

Comments
 (0)