Skip to content

Commit 589beea

Browse files
committed
tests: replaced stretchr/testify by go-openapi/testify
Signed-off-by: Frederic BIDON <[email protected]>
1 parent 0daf9a4 commit 589beea

28 files changed

+117
-150
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ linters:
1616
- godox
1717
- gosmopolitan
1818
- inamedparam
19-
#- intrange # disabled while < go1.22
19+
- intrange
2020
- ireturn
2121
- lll
2222
- musttag

analysis_test/helpers_spec_test.go

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

1212
"github.com/go-openapi/spec"
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
var (

analysis_test/spec_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
"github.com/go-openapi/loads"
1616
"github.com/go-openapi/spec"
1717
"github.com/go-openapi/swag/loading"
18-
"github.com/stretchr/testify/assert"
19-
"github.com/stretchr/testify/require"
18+
"github.com/go-openapi/testify/v2/assert"
19+
"github.com/go-openapi/testify/v2/require"
2020
)
2121

2222
func skipNotify(t *testing.T) {

analyzer.go

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package analysis
55

66
import (
77
"fmt"
8+
"maps"
89
slashpath "path"
910
"strconv"
1011
"strings"
@@ -100,33 +101,33 @@ func (p *patternAnalysis) addSchemaPattern(key, pattern string) {
100101
}
101102

102103
type enumAnalysis struct {
103-
parameters map[string][]interface{}
104-
headers map[string][]interface{}
105-
items map[string][]interface{}
106-
schemas map[string][]interface{}
107-
allEnums map[string][]interface{}
104+
parameters map[string][]any
105+
headers map[string][]any
106+
items map[string][]any
107+
schemas map[string][]any
108+
allEnums map[string][]any
108109
}
109110

110-
func (p *enumAnalysis) addEnum(key string, enum []interface{}) {
111+
func (p *enumAnalysis) addEnum(key string, enum []any) {
111112
p.allEnums["#"+key] = enum
112113
}
113114

114-
func (p *enumAnalysis) addParameterEnum(key string, enum []interface{}) {
115+
func (p *enumAnalysis) addParameterEnum(key string, enum []any) {
115116
p.parameters["#"+key] = enum
116117
p.addEnum(key, enum)
117118
}
118119

119-
func (p *enumAnalysis) addHeaderEnum(key string, enum []interface{}) {
120+
func (p *enumAnalysis) addHeaderEnum(key string, enum []any) {
120121
p.headers["#"+key] = enum
121122
p.addEnum(key, enum)
122123
}
123124

124-
func (p *enumAnalysis) addItemsEnum(key string, enum []interface{}) {
125+
func (p *enumAnalysis) addItemsEnum(key string, enum []any) {
125126
p.items["#"+key] = enum
126127
p.addEnum(key, enum)
127128
}
128129

129-
func (p *enumAnalysis) addSchemaEnum(key string, enum []interface{}) {
130+
func (p *enumAnalysis) addSchemaEnum(key string, enum []any) {
130131
p.schemas["#"+key] = enum
131132
p.addEnum(key, enum)
132133
}
@@ -622,31 +623,31 @@ func (s *Spec) AllPatterns() map[string]string {
622623

623624
// ParameterEnums returns all the enums found in parameters
624625
// the map is cloned to avoid accidental changes
625-
func (s *Spec) ParameterEnums() map[string][]interface{} {
626+
func (s *Spec) ParameterEnums() map[string][]any {
626627
return cloneEnumMap(s.enums.parameters)
627628
}
628629

629630
// HeaderEnums returns all the enums found in response headers
630631
// the map is cloned to avoid accidental changes
631-
func (s *Spec) HeaderEnums() map[string][]interface{} {
632+
func (s *Spec) HeaderEnums() map[string][]any {
632633
return cloneEnumMap(s.enums.headers)
633634
}
634635

635636
// ItemsEnums returns all the enums found in simple array items
636637
// the map is cloned to avoid accidental changes
637-
func (s *Spec) ItemsEnums() map[string][]interface{} {
638+
func (s *Spec) ItemsEnums() map[string][]any {
638639
return cloneEnumMap(s.enums.items)
639640
}
640641

641642
// SchemaEnums returns all the enums found in schemas
642643
// the map is cloned to avoid accidental changes
643-
func (s *Spec) SchemaEnums() map[string][]interface{} {
644+
func (s *Spec) SchemaEnums() map[string][]any {
644645
return cloneEnumMap(s.enums.schemas)
645646
}
646647

647648
// AllEnums returns all the enums found in the spec
648649
// the map is cloned to avoid accidental changes
649-
func (s *Spec) AllEnums() map[string][]interface{} {
650+
func (s *Spec) AllEnums() map[string][]any {
650651
return cloneEnumMap(s.enums.allEnums)
651652
}
652653

@@ -722,11 +723,11 @@ func (s *Spec) reset() {
722723
s.patterns.items = make(map[string]string, allocLargeMap)
723724
s.patterns.schemas = make(map[string]string, allocLargeMap)
724725
s.patterns.allPatterns = make(map[string]string, allocLargeMap)
725-
s.enums.parameters = make(map[string][]interface{}, allocLargeMap)
726-
s.enums.headers = make(map[string][]interface{}, allocLargeMap)
727-
s.enums.items = make(map[string][]interface{}, allocLargeMap)
728-
s.enums.schemas = make(map[string][]interface{}, allocLargeMap)
729-
s.enums.allEnums = make(map[string][]interface{}, allocLargeMap)
726+
s.enums.parameters = make(map[string][]any, allocLargeMap)
727+
s.enums.headers = make(map[string][]any, allocLargeMap)
728+
s.enums.items = make(map[string][]any, allocLargeMap)
729+
s.enums.schemas = make(map[string][]any, allocLargeMap)
730+
s.enums.allEnums = make(map[string][]any, allocLargeMap)
730731
}
731732

732733
func (s *Spec) reload() {
@@ -1040,18 +1041,14 @@ func (s *Spec) analyzeSchema(name string, schema *spec.Schema, prefix string) {
10401041

10411042
func cloneStringMap(source map[string]string) map[string]string {
10421043
res := make(map[string]string, len(source))
1043-
for k, v := range source {
1044-
res[k] = v
1045-
}
1044+
maps.Copy(res, source)
10461045

10471046
return res
10481047
}
10491048

1050-
func cloneEnumMap(source map[string][]interface{}) map[string][]interface{} {
1051-
res := make(map[string][]interface{}, len(source))
1052-
for k, v := range source {
1053-
res[k] = v
1054-
}
1049+
func cloneEnumMap(source map[string][]any) map[string][]any {
1050+
res := make(map[string][]any, len(source))
1051+
maps.Copy(res, source)
10551052

10561053
return res
10571054
}

analyzer_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313

1414
"github.com/go-openapi/analysis/internal/antest"
1515
"github.com/go-openapi/spec"
16-
"github.com/stretchr/testify/assert"
17-
"github.com/stretchr/testify/require"
16+
"github.com/go-openapi/testify/v2/assert"
17+
"github.com/go-openapi/testify/v2/require"
1818
)
1919

2020
const (
@@ -28,7 +28,7 @@ func TestAnalyzer_All(t *testing.T) {
2828
formatParam := spec.QueryParam("format").Typed("string", "")
2929

3030
limitParam := spec.QueryParam("limit").Typed("integer", "int32")
31-
limitParam.Extensions = spec.Extensions(map[string]interface{}{})
31+
limitParam.Extensions = spec.Extensions(map[string]any{})
3232
limitParam.Extensions.Add("go-name", "Limit")
3333

3434
skipParam := spec.QueryParam("skip").Typed("integer", "int32")
@@ -803,33 +803,33 @@ func TestAnalyzer_EnumAnalysis(t *testing.T) {
803803
en := an.enums
804804

805805
// parameters
806-
assertEnum(t, en.parameters, "#/parameters/idParam", []interface{}{"aA", "b9", "c3"})
807-
assertEnum(t, en.parameters, "#/paths/~1some~1where~1{id}/parameters/1", []interface{}{"bA", "ba", "b9"})
808-
assertEnum(t, en.parameters, "#/paths/~1some~1where~1{id}/get/parameters/0", []interface{}{"a0", "b1", "c2"})
806+
assertEnum(t, en.parameters, "#/parameters/idParam", []any{"aA", "b9", "c3"})
807+
assertEnum(t, en.parameters, "#/paths/~1some~1where~1{id}/parameters/1", []any{"bA", "ba", "b9"})
808+
assertEnum(t, en.parameters, "#/paths/~1some~1where~1{id}/get/parameters/0", []any{"a0", "b1", "c2"})
809809

810810
// responses
811-
assertEnum(t, en.headers, "#/responses/notFound/headers/ContentLength", []interface{}{"1234", "123"})
811+
assertEnum(t, en.headers, "#/responses/notFound/headers/ContentLength", []any{"1234", "123"})
812812
assertEnum(t, en.headers,
813-
"#/paths/~1some~1where~1{id}/get/responses/200/headers/X-Request-Id", []interface{}{"dA", "d9"})
813+
"#/paths/~1some~1where~1{id}/get/responses/200/headers/X-Request-Id", []any{"dA", "d9"})
814814

815815
// definitions
816816
assertEnum(t, en.schemas,
817-
"#/paths/~1other~1place/post/parameters/0/schema/properties/value", []interface{}{"eA", "e9"})
817+
"#/paths/~1other~1place/post/parameters/0/schema/properties/value", []any{"eA", "e9"})
818818
assertEnum(t, en.schemas, "#/paths/~1other~1place/post/responses/200/schema/properties/data",
819-
[]interface{}{"123a", "123b", "123d"})
820-
assertEnum(t, en.schemas, "#/definitions/named", []interface{}{"fA", "f9"})
821-
assertEnum(t, en.schemas, "#/definitions/tag/properties/value", []interface{}{"gA", "ga", "g9"})
819+
[]any{"123a", "123b", "123d"})
820+
assertEnum(t, en.schemas, "#/definitions/named", []any{"fA", "f9"})
821+
assertEnum(t, en.schemas, "#/definitions/tag/properties/value", []any{"gA", "ga", "g9"})
822822
assertEnum(t, en.schemas, "#/definitions/record",
823-
[]interface{}{`{"createdAt": "2018-08-31"}`, `{"createdAt": "2018-09-30"}`})
823+
[]any{`{"createdAt": "2018-08-31"}`, `{"createdAt": "2018-09-30"}`})
824824

825825
// array enum
826826
assertEnum(t, en.parameters, "#/paths/~1some~1where~1{id}/get/parameters/1",
827-
[]interface{}{[]interface{}{"cA", "cz", "c9"}, []interface{}{"cA", "cz"}, []interface{}{"cz", "c9"}})
827+
[]any{[]any{"cA", "cz", "c9"}, []any{"cA", "cz"}, []any{"cz", "c9"}})
828828

829829
// items
830-
assertEnum(t, en.items, "#/paths/~1some~1where~1{id}/get/parameters/1/items", []interface{}{"cA", "cz", "c9"})
830+
assertEnum(t, en.items, "#/paths/~1some~1where~1{id}/get/parameters/1/items", []any{"cA", "cz", "c9"})
831831
assertEnum(t, en.items, "#/paths/~1other~1place/post/responses/default/headers/Via/items",
832-
[]interface{}{"AA", "Ab"})
832+
[]any{"AA", "Ab"})
833833

834834
res := an.AllEnums()
835835
assert.Lenf(t, res, 14, "Expected 14 enums in this spec, but got %d", len(res))
@@ -885,7 +885,7 @@ func makeFixturepec(pi, pi2 spec.PathItem, formatParam *spec.Parameter) *spec.Sw
885885
}
886886
}
887887

888-
func assertEnum(t testing.TB, data map[string][]interface{}, key string, enum []interface{}) {
888+
func assertEnum(t testing.TB, data map[string][]any, key string, enum []any) {
889889
require.Contains(t, data, key)
890890
assert.Equal(t, enum, data[key])
891891
}
@@ -914,7 +914,7 @@ func prepareTestParamsAuth() *Spec {
914914
formatParam := spec.QueryParam("format").Typed("string", "")
915915

916916
limitParam := spec.QueryParam("limit").Typed("integer", "int32")
917-
limitParam.Extensions = spec.Extensions(map[string]interface{}{})
917+
limitParam.Extensions = spec.Extensions(map[string]any{})
918918
limitParam.Extensions.Add("go-name", "Limit")
919919

920920
skipParam := spec.QueryParam("skip").Typed("integer", "int32")
@@ -979,7 +979,7 @@ func prepareTestParamsValid() *Spec {
979979
formatParam := spec.QueryParam("format").Typed("string", "")
980980

981981
limitParam := spec.QueryParam("limit").Typed("integer", "int32")
982-
limitParam.Extensions = spec.Extensions(map[string]interface{}{})
982+
limitParam.Extensions = spec.Extensions(map[string]any{})
983983
limitParam.Extensions.Add("go-name", "Limit")
984984

985985
skipParam := spec.QueryParam("skip").Typed("integer", "int32")

fixer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010

1111
"github.com/go-openapi/analysis/internal/antest"
1212
"github.com/go-openapi/spec"
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 TestFixer_EmptyResponseDescriptions(t *testing.T) {

flatten.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package analysis
66
import (
77
"log"
88
"path"
9+
"slices"
910
"sort"
1011
"strings"
1112

@@ -530,14 +531,7 @@ func updateRefParents(allRefs map[string]spec.Ref, r *newRef) {
530531
continue
531532
}
532533

533-
found := false
534-
for _, p := range r.parents {
535-
if p == k {
536-
found = true
537-
538-
break
539-
}
540-
}
534+
found := slices.Contains(r.parents, k)
541535
if !found {
542536
r.parents = append(r.parents, k)
543537
}

flatten_name_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"github.com/go-openapi/analysis/internal/flatten/sortref"
1414
"github.com/go-openapi/jsonpointer"
1515
"github.com/go-openapi/spec"
16-
"github.com/stretchr/testify/assert"
17-
"github.com/stretchr/testify/require"
16+
"github.com/go-openapi/testify/v2/assert"
17+
"github.com/go-openapi/testify/v2/require"
1818
)
1919

2020
func TestName_FromRef(t *testing.T) {

flatten_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"github.com/go-openapi/analysis/internal/flatten/operations"
2121
"github.com/go-openapi/jsonpointer"
2222
"github.com/go-openapi/spec"
23-
"github.com/stretchr/testify/assert"
24-
"github.com/stretchr/testify/require"
23+
"github.com/go-openapi/testify/v2/assert"
24+
"github.com/go-openapi/testify/v2/require"
2525
)
2626

2727
var (
@@ -33,7 +33,7 @@ type refFixture struct {
3333
Key string
3434
Ref spec.Ref
3535
Location string
36-
Expected interface{}
36+
Expected any
3737
}
3838

3939
func makeRefFixtures() []refFixture {

go.mod

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ module github.com/go-openapi/analysis
22

33
require (
44
github.com/go-openapi/jsonpointer v0.22.1
5-
github.com/go-openapi/spec v0.22.0
6-
github.com/go-openapi/strfmt v0.24.0
5+
github.com/go-openapi/spec v0.22.1
6+
github.com/go-openapi/strfmt v0.25.0
77
github.com/go-openapi/swag/jsonutils v0.25.1
88
github.com/go-openapi/swag/loading v0.25.1
99
github.com/go-openapi/swag/mangling v0.25.1
10-
github.com/stretchr/testify v1.11.1
10+
github.com/go-openapi/testify/v2 v2.0.2
1111
)
1212

1313
require (
14-
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
15-
github.com/davecgh/go-spew v1.1.1 // indirect
16-
github.com/go-openapi/errors v0.22.3 // indirect
17-
github.com/go-openapi/jsonreference v0.21.2 // indirect
14+
github.com/go-openapi/errors v0.22.4 // indirect
15+
github.com/go-openapi/jsonreference v0.21.3 // indirect
1816
github.com/go-openapi/swag/conv v0.25.1 // indirect
1917
github.com/go-openapi/swag/jsonname v0.25.1 // indirect
2018
github.com/go-openapi/swag/stringutils v0.25.1 // indirect
@@ -23,12 +21,10 @@ require (
2321
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
2422
github.com/google/uuid v1.6.0 // indirect
2523
github.com/oklog/ulid v1.3.1 // indirect
26-
github.com/pmezard/go-difflib v1.0.0 // indirect
27-
go.mongodb.org/mongo-driver v1.17.4 // indirect
24+
go.mongodb.org/mongo-driver v1.17.6 // indirect
2825
go.yaml.in/yaml/v3 v3.0.4 // indirect
29-
golang.org/x/net v0.44.0 // indirect
30-
golang.org/x/text v0.29.0 // indirect
31-
gopkg.in/yaml.v3 v3.0.1 // indirect
26+
golang.org/x/net v0.46.0 // indirect
27+
golang.org/x/text v0.30.0 // indirect
3228
)
3329

3430
go 1.24.0

0 commit comments

Comments
 (0)