1package analysis 2 3import ( 4 "net/url" 5 "os" 6 "path/filepath" 7 goruntime "runtime" 8 "strings" 9 "testing" 10 11 "github.com/go-openapi/spec" 12 "github.com/stretchr/testify/require" 13) 14 15// wrapWindowsPath adapts path expectations for tests running on windows 16func wrapWindowsPath(p string) string { 17 if goruntime.GOOS != "windows" { 18 return p 19 } 20 pp := filepath.FromSlash(p) 21 if !filepath.IsAbs(p) && []rune(pp)[0] == '\\' { 22 pp, _ = filepath.Abs(p) 23 u, _ := url.Parse(pp) 24 return u.String() 25 } 26 return pp 27} 28 29func definitionPtr(key string) string { 30 if !strings.HasPrefix(key, "#/definitions") { 31 return key 32 } 33 return strings.Join(strings.Split(key, "/")[:3], "/") 34} 35 36func loadOrFail(t *testing.T, bp string) *spec.Swagger { 37 cwd, _ := os.Getwd() 38 sp, err := loadSpec(filepath.Join(cwd, bp)) 39 require.NoError(t, err) 40 41 return sp 42} 43