@@ -12,11 +12,10 @@ import (
1212 "strings"
1313 "testing"
1414
15- "github.com/go-openapi/testify/v2/require"
16-
17- "github.com/go-openapi/loads"
15+ "github.com/go-openapi/analysis/internal/antest"
1816
19- "github.com/go-swagger/go-swagger/cmd/swagger/commands/internal/cmdtest"
17+ "github.com/go-openapi/testify/v2/assert"
18+ "github.com/go-openapi/testify/v2/require"
2019)
2120
2221// TestDiffForVariousCombinations - computes the diffs for a number
@@ -48,7 +47,7 @@ func TestDiffForVariousCombinations(t *testing.T) {
4847 out , err , warn := diffs .ReportAllDiffs (false )
4948 require .NoError (t , err )
5049
51- if ! cmdtest . AssertReadersContent (t , true , tc .expectedLines , out ) {
50+ if ! assertReadersContent (t , true , tc .expectedLines , out ) {
5251 t .Logf ("unexpected content for fixture %q[%d] (file: %s)" , tc .name , i , tc .expectedFile )
5352 }
5453
@@ -66,19 +65,17 @@ func TestDiffForVariousCombinations(t *testing.T) {
6665}
6766
6867func getDiffs (oldSpecPath , newSpecPath string ) (SpecDifferences , error ) {
69- swaggerDoc1 := oldSpecPath
70- specDoc1 , err := loads .Spec (swaggerDoc1 )
68+ spec1 , err := antest .LoadSpec (oldSpecPath )
7169 if err != nil {
7270 return nil , err
7371 }
7472
75- swaggerDoc2 := newSpecPath
76- specDoc2 , err := loads .Spec (swaggerDoc2 )
73+ spec2 , err := antest .LoadSpec (newSpecPath )
7774 if err != nil {
7875 return nil , err
7976 }
8077
81- return Compare (specDoc1 . Spec (), specDoc2 . Spec () )
78+ return Compare (spec1 , spec2 )
8279}
8380
8481func makeTestCases (t testing.TB , matches []string ) []testCaseData {
@@ -113,8 +110,8 @@ func makeTestCases(t testing.TB, matches []string) []testCaseData {
113110}
114111
115112func TestIssue2962 (t * testing.T ) {
116- oldSpec := filepath .Join (".." , ".." , ".." , ".." , " fixtures" , "bugs" , "2962" , "old.json" )
117- newSpec := filepath .Join (".." , ".." , ".." , ".." , " fixtures" , "bugs" , "2962" , "new.json" )
113+ oldSpec := filepath .Join ("fixtures" , "bugs" , "2962" , "old.json" )
114+ newSpec := filepath .Join ("fixtures" , "bugs" , "2962" , "new.json" )
118115
119116 t .Run ("should diff" , func (t * testing.T ) {
120117 diffs , err := getDiffs (oldSpec , newSpec )
@@ -133,7 +130,7 @@ func TestIssue2962(t *testing.T) {
133130}
134131
135132func fixturePath (file string , parts ... string ) string {
136- return filepath .Join (".." , ".." , ".." , ".." , " fixtures" , "diff " , strings .Join (append ([]string {file }, parts ... ), "" ))
133+ return filepath .Join ("fixtures" , strings .Join (append ([]string {file }, parts ... ), "" ))
137134}
138135
139136type testCaseData struct {
@@ -159,3 +156,24 @@ func linesInFile(t testing.TB, fileName string) io.Reader {
159156 // consumes a bit of extra memory, but no longer leaks open files
160157 return bytes .NewBuffer (file )
161158}
159+
160+ func assertReadersContent (t testing.TB , noBlanks bool , expected , actual io.Reader ) bool {
161+ t .Helper ()
162+
163+ e , err := io .ReadAll (expected )
164+ require .NoError (t , err )
165+
166+ a , err := io .ReadAll (actual )
167+ require .NoError (t , err )
168+
169+ var wants , got strings.Builder
170+ _ , _ = wants .Write (e )
171+ _ , _ = got .Write (a )
172+
173+ if noBlanks {
174+ r := strings .NewReplacer (" " , "" , "\t " , "" , "\n " , "" , "\r " , "" )
175+ return assert .EqualTf (t , r .Replace (wants .String ()), r .Replace (got .String ()), "expected:\n %s\n got:\n %s" , wants .String (), got .String ())
176+ }
177+
178+ return assert .EqualT (t , wants .String (), got .String ())
179+ }
0 commit comments