-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathutils_test.go
More file actions
89 lines (81 loc) · 1.98 KB
/
Copy pathutils_test.go
File metadata and controls
89 lines (81 loc) · 1.98 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package overlay_test
import (
"testing"
"github.com/speakeasy-api/openapi/overlay"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
func TestNewTargetSelector_Success(t *testing.T) {
t.Parallel()
tests := []struct {
name string
path string
method string
expected string
}{
{
name: "simple path and method",
path: "/users",
method: "get",
expected: `$["paths"]["/users"]["get"]`,
},
{
name: "path with parameter",
path: "/users/{id}",
method: "patch",
expected: `$["paths"]["/users/{id}"]["patch"]`,
},
{
name: "root path",
path: "/",
method: "post",
expected: `$["paths"]["/"]["post"]`,
},
{
name: "nested path",
path: "/users/{userId}/orders/{orderId}",
method: "delete",
expected: `$["paths"]["/users/{userId}/orders/{orderId}"]["delete"]`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := overlay.NewTargetSelector(tt.path, tt.method)
assert.Equal(t, tt.expected, result)
})
}
}
func TestNewUpdateAction_Success(t *testing.T) {
t.Parallel()
tests := []struct {
name string
path string
method string
update yaml.Node
expectedTarget string
}{
{
name: "simple update action",
path: "/users",
method: "get",
update: yaml.Node{Kind: yaml.ScalarNode, Value: "test"},
expectedTarget: `$["paths"]["/users"]["get"]`,
},
{
name: "update action with path parameter",
path: "/users/{id}",
method: "put",
update: yaml.Node{Kind: yaml.MappingNode},
expectedTarget: `$["paths"]["/users/{id}"]["put"]`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := overlay.NewUpdateAction(tt.path, tt.method, tt.update)
assert.Equal(t, tt.expectedTarget, result.Target)
assert.Equal(t, tt.update.Kind, result.Update.Kind)
})
}
}