-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathroutes_test.go
87 lines (84 loc) · 2.51 KB
/
routes_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
package generator
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_extractOrderedEndpointRoutes(t *testing.T) {
type args struct {
specBytes []byte
}
tests := []struct {
name string
args args
want []string
wantErr bool
}{
{
name: "dummy case with three paths",
args: args{
[]byte(`{
"paths": {
"foo": {},
"bar": {},
"qux": {}
}
}`),
},
want: []string{"foo", "bar", "qux"},
wantErr: false,
},
{
name: "real case",
args: args{openAPIFixture},
want: []string{
"/api_keys",
"/api_keys/{key_id}",
"/projects/{project_id}/operations/{operation_id}",
"/projects",
"/projects/shared",
"/projects/{project_id}",
"/projects/{project_id}/operations",
"/projects/{project_id}/permissions",
"/projects/{project_id}/permissions/{permission_id}",
"/projects/{project_id}/connection_uri",
"/projects/{project_id}/branches",
"/projects/{project_id}/branches/{branch_id}",
"/projects/{project_id}/branches/{branch_id}/restore",
"/projects/{project_id}/branches/{branch_id}/schema",
"/projects/{project_id}/branches/{branch_id}/set_as_primary",
"/projects/{project_id}/branches/{branch_id}/set_as_default",
"/projects/{project_id}/branches/{branch_id}/endpoints",
"/projects/{project_id}/branches/{branch_id}/databases",
"/projects/{project_id}/branches/{branch_id}/databases/{database_name}",
"/projects/{project_id}/branches/{branch_id}/roles",
"/projects/{project_id}/branches/{branch_id}/roles/{role_name}",
"/projects/{project_id}/branches/{branch_id}/roles/{role_name}/reveal_password",
"/projects/{project_id}/branches/{branch_id}/roles/{role_name}/reset_password",
"/projects/{project_id}/endpoints",
"/projects/{project_id}/endpoints/{endpoint_id}",
"/projects/{project_id}/endpoints/{endpoint_id}/start",
"/projects/{project_id}/endpoints/{endpoint_id}/suspend",
"/projects/{project_id}/endpoints/{endpoint_id}/restart",
"/consumption_history/account",
"/consumption_history/projects",
"/consumption/projects",
"/users/me",
"/users/me/organizations",
"/users/me/projects/transfer",
},
wantErr: false,
},
}
t.Parallel()
for _, tt := range tests {
t.Run(
tt.name, func(t *testing.T) {
got, err := extractOrderedEndpointRoutes(tt.args.specBytes)
if tt.wantErr && err != nil {
t.Fatalf("unexpected error: %v", err)
}
assert.Equalf(t, tt.want, got, "extractOrderedEndpointRoutes(%v)", tt.args.specBytes)
},
)
}
}