This repository was archived by the owner on Jan 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathproc_test.go
107 lines (97 loc) · 2.52 KB
/
proc_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
package processor
import (
"encoding/json"
"github.com/TykTechnologies/tyk/apidef"
"testing"
)
var js = `
{
"name": "MyGateway #myTag",
"slug": "mygateway",
"org_id": "1",
"use_keyless": true,
"definition": {
"location": "header",
"key": "x-api-version",
"strip_path": true
},
"version_data": {
"not_versioned": true,
"versions": {
"Default": {
"name": "Default",
"use_extended_paths": true,
"paths": {
"ignored": [],
"white_list": [],
"black_list": []
}
}
}
},
"proxy": {
"listen_path": "/",
"target_url": "http://app.service:1234",
"strip_listen_path": true
},
"domain": "",
"response_processors": [],
"custom_middleware": {
"pre": [],
"post": [],
"post_key_auth": [],
"auth_check": {
"name": "",
"path": "",
"require_session": false
},
"response": [],
"driver": "",
"id_extractor": {
"extract_from": "",
"extract_with": "",
"extractor_config": {}
}
},
"config_data": {},
"allowed_ips": [],
"disable_rate_limit": true,
"disable_quota": true,
"cache_options": {
"cache_timeout": 60,
"enable_cache": true
},
"active": true,
"tags": ["ingress"],
"enable_context_vars": true
}
`
func TestProc(t *testing.T) {
testAnnotations := map[string]string{
"bool.service.tyk.io/use-keyless": "false",
"string.service.tyk.io/proxy.target-url": "http://foo.bar/bazington",
"num.service.tyk.io/cache_options.cache-timeout": "20",
"object.service.tyk.io/version_data.versions.Default.extended-paths": `{"hard_timeouts":[{"path":"{all}","method":"GET","timeout":60,"fromDashboard":true}]}`,
}
def, err := Process(testAnnotations, js)
if err != nil {
t.Fatal(err)
}
asDefObj := &apidef.APIDefinition{}
err = json.Unmarshal([]byte(def), asDefObj)
if err != nil {
t.Fatal(err)
}
if asDefObj.UseKeylessAccess != false {
t.Fatal("bool not set")
}
if asDefObj.Proxy.TargetURL != "http://foo.bar/bazington" {
t.Fatal("string not set")
}
if asDefObj.CacheOptions.CacheTimeout != 20 {
t.Fatal("num not set")
}
if asDefObj.VersionData.Versions["Default"].ExtendedPaths.HardTimeouts[0].Path != "{all}" {
t.Fatal("object not set")
}
}