-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathpaths_test.go
More file actions
62 lines (50 loc) · 1.55 KB
/
Copy pathpaths_test.go
File metadata and controls
62 lines (50 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0
package spec
import (
"testing"
"github.com/go-openapi/testify/v2/assert"
"github.com/go-openapi/testify/v2/require"
)
var paths = Paths{ //nolint:gochecknoglobals // test fixture
VendorExtensible: VendorExtensible{Extensions: map[string]any{"x-framework": "go-swagger"}},
Paths: map[string]PathItem{
"/": {
Refable: Refable{Ref: MustCreateRef("cats")},
},
},
}
const pathsJSON = `{"x-framework":"go-swagger","/":{"$ref":"cats"}}`
func TestIntegrationPaths(t *testing.T) {
assert.JSONUnmarshalAsT(t, paths, pathsJSON)
}
func TestJSONLookupPaths(t *testing.T) {
p := Paths{
VendorExtensible: VendorExtensible{Extensions: map[string]any{"x-framework": "go-swagger"}},
Paths: map[string]PathItem{
"/pets": {PathItemProps: PathItemProps{
Get: &Operation{OperationProps: OperationProps{ID: "listPets"}},
}},
},
}
t.Run("lookup should find a path", func(t *testing.T) {
res, err := p.JSONLookup("/pets")
require.NoError(t, err)
pi, ok := res.(*PathItem)
require.TrueT(t, ok)
require.NotNil(t, pi.Get)
assert.EqualT(t, "listPets", pi.Get.ID)
})
t.Run("lookup should find an extension", func(t *testing.T) {
res, err := p.JSONLookup("x-framework")
require.NoError(t, err)
ext, ok := res.(*any)
require.TrueT(t, ok)
assert.Equal(t, "go-swagger", *ext)
})
t.Run(`lookup should fail on "unknown"`, func(t *testing.T) {
res, err := p.JSONLookup("/unknown")
require.ErrorIs(t, err, ErrSpec)
require.Nil(t, res)
})
}