-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpath_item_test.go
67 lines (62 loc) · 1.82 KB
/
path_item_test.go
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
package openapi_test
import (
"strconv"
"testing"
openapi "github.com/nasa9084/go-openapi"
)
func TestPathItem_GetOperationByMethod(t *testing.T) {
pathItem := openapi.PathItem{
Get: &openapi.Operation{OperationID: "get"},
Put: &openapi.Operation{OperationID: "put"},
Post: &openapi.Operation{OperationID: "post"},
Delete: &openapi.Operation{OperationID: "delete"},
Options: &openapi.Operation{OperationID: "options"},
Head: &openapi.Operation{OperationID: "head"},
Patch: &openapi.Operation{OperationID: "patch"},
Trace: &openapi.Operation{OperationID: "trace"},
}
candidates := []struct {
method string
opID string
isNil bool
}{
{"", "", true},
{"0", "", true},
{"foobar", "", true},
{"get", "get", false},
{"put", "put", false},
{"POST", "post", false},
{"Delete", "delete", false},
}
for i, c := range candidates {
t.Run(strconv.Itoa(i)+"/"+c.method+"."+c.opID, func(t *testing.T) {
op := pathItem.GetOperationByMethod(c.method)
if !c.isNil && op == nil {
t.Errorf("operation should be returned: %s", c.method)
return
}
if c.isNil {
return
}
if op.OperationID != c.opID {
t.Errorf("%s != %s", op.OperationID, c.opID)
}
})
}
}
func TestPathItem_Operations(t *testing.T) {
pathItem := openapi.PathItem{
Get: &openapi.Operation{OperationID: "get"},
Put: &openapi.Operation{OperationID: "put"},
Post: &openapi.Operation{OperationID: "post"},
Delete: &openapi.Operation{OperationID: "delete"},
Options: &openapi.Operation{OperationID: "options"},
Head: &openapi.Operation{OperationID: "head"},
Patch: &openapi.Operation{OperationID: "patch"},
Trace: &openapi.Operation{OperationID: "trace"},
}
ops := pathItem.Operations()
if len(ops) != 8 {
t.Errorf("size of operations is invalid: %d != 8", len(ops))
}
}