-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_test.go
62 lines (59 loc) · 2.01 KB
/
parse_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
package main
import (
"testing"
)
func TestParseRoutes(t *testing.T) {
api, err := ParseRoutes("testapp")
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if len(api.Routes) != 3 {
t.Errorf("Expected to get 3 routes, but got %v", len(api.Routes))
}
if api.Routes[0].Name != "get_users" {
t.Errorf("Expected to get 'get_users' route name, but got: %v", api.Routes[0].Name)
}
if api.Routes[0].Path != "/users" {
t.Errorf("Expected to get /users path, but got: %v", api.Routes[0].Path)
}
if api.Routes[0].Collection != true {
t.Errorf("Expected to get path collection to be true, but got false")
}
if api.Routes[0].Versions[0].Schema != nil {
t.Errorf("Expected to get no route schema, but got")
}
if api.Routes[1].Versions[0].Schema == nil {
t.Errorf("Expected to get route schema, but got nil")
}
if api.Version != 5 {
t.Errorf("Expected to get api version 5, but got %v", api.Version)
}
if api.MinVersion != 3 {
t.Errorf("Expected to get api version 3, but got %v", api.MinVersion)
}
if len(api.DeprecatedVersions) != 3 {
t.Errorf("Expected to get 3 deprecated versions, but got %v", len(api.DeprecatedVersions))
}
if api.Routes[0].Versions[4] == nil {
t.Error("Expected to get version 4 of get_users route, but got nil")
}
if api.Routes[1].Versions[4] == nil || api.Routes[1].Versions[4].Schema == nil {
t.Errorf("Expected to get create_user route v4 schema, but got nil")
}
}
func TestParseRoute(t *testing.T) {
routeLine := "post /login, name: 'login' | jwt {\"success\": true}"
route, err := ParseRoute([]byte(routeLine))
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if len(route.PluginPipelines) != 1 {
t.Errorf("Expected to parse 1 plugin pipeline, but got: %v", len(route.PluginPipelines))
}
if route.PluginPipelines[0].Name != "jwt" {
t.Errorf("Expected plugin name to be 'jwt', but got: '%v'", route.PluginPipelines[0].Name)
}
if route.PluginPipelines[0].Argument["success"] == nil {
t.Errorf("Expected plugin argument to have success key, but got none")
}
}