-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpoints_test.go
144 lines (136 loc) · 2.33 KB
/
endpoints_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package copper
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestEndpoints_MarkChecked(t *testing.T) {
e := &endpoints{
paths: map[string]methods{
"/study/my/{id}": {
methods: map[string]responses{
http.MethodPut: {responses: map[string]bool{
"200": true,
}},
},
},
"/study/other/{id}": {
methods: map[string]responses{
http.MethodGet: {responses: map[string]bool{
"200": false,
"404": false,
}},
},
},
},
}
tt := []struct {
name string
path string
method string
resCode string
expected bool
}{
{
"checked endpoint can be marked again",
"/study/my/{id}",
http.MethodPut,
"200",
true,
},
{
"missing endpoint will not be marked",
"/other/endpoint",
http.MethodPut,
"201",
false,
},
{
"inserted endpoint can be marked",
"/study/other/{id}",
http.MethodGet,
"200",
true,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
e.MarkChecked(tc.path, tc.method, tc.resCode)
assert.Equal(t, tc.expected, e.IsChecked(tc.path, tc.method, tc.resCode))
})
}
}
func TestIsChecked(t *testing.T) {
e := &endpoints{
paths: map[string]methods{
"/ping": {
methods: map[string]responses{
http.MethodPut: {responses: map[string]bool{
"200": false,
}},
},
},
"/ping/{thevalue}": {
methods: map[string]responses{
http.MethodGet: {responses: map[string]bool{
"200": false,
"404": false,
"401": true,
}},
http.MethodDelete: {responses: map[string]bool{
"204": false,
}},
},
},
},
}
tt := []struct {
name string
path string
method string
resCode string
expected bool
}{
{
"non-inserted path",
"/foo",
"GET",
"200",
false,
},
{
"checked path",
"/ping/{thevalue}",
"GET",
"401",
true,
},
{
"existing unchecked",
"/ping/{thevalue}",
"GET",
"404",
false,
},
{
"method is case insensitive",
"/ping/{thevalue}",
"get",
"401",
true,
},
{
"path is case sensitive",
"/Ping/{thevalue}",
http.MethodGet,
"401",
false,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
actual := e.IsChecked(tc.path, tc.method, tc.resCode)
assert.Equal(t, tc.expected, actual)
})
}
}