@@ -14,6 +14,91 @@ import (
14
14
"github.com/stretchr/testify/assert"
15
15
)
16
16
17
+ func TestExternalCacheURLValidate (t * testing.T ) {
18
+ testCases := []struct {
19
+ desc string
20
+ data ExternalCache
21
+ expErrors int
22
+ }{
23
+ {
24
+ desc : "With http://" ,
25
+ data : ExternalCache {Host : "http://www.google.com" , Path : "/path/v1" },
26
+ expErrors : 1 ,
27
+ },
28
+ {
29
+ desc : "Without http://" ,
30
+ data : ExternalCache {Host : "www.google.com" , Path : "/path/v1" },
31
+ expErrors : 0 ,
32
+ },
33
+ {
34
+ desc : "No scheme but '//' prefix" ,
35
+ data : ExternalCache {Host : "//www.google.com" , Path : "/path/v1" },
36
+ expErrors : 1 ,
37
+ },
38
+ {
39
+ desc : "// appears twice" ,
40
+ data : ExternalCache {Host : "//www.google.com//" , Path : "path/v1" },
41
+ expErrors : 1 ,
42
+ },
43
+ {
44
+ desc : "Host has an only // value" ,
45
+ data : ExternalCache {Host : "//" , Path : "path/v1" },
46
+ expErrors : 1 ,
47
+ },
48
+ {
49
+ desc : "only scheme host, valid path" ,
50
+ data : ExternalCache {Host : "http://" , Path : "/path/v1" },
51
+ expErrors : 1 ,
52
+ },
53
+ {
54
+ desc : "No host, path only" ,
55
+ data : ExternalCache {Host : "" , Path : "path/v1" },
56
+ expErrors : 1 ,
57
+ },
58
+ {
59
+ desc : "No host, nor path" ,
60
+ data : ExternalCache {Host : "" , Path : "" },
61
+ expErrors : 0 ,
62
+ },
63
+ {
64
+ desc : "Invalid http at the end" ,
65
+ data : ExternalCache {Host : "www.google.com" , Path : "http://" },
66
+ expErrors : 1 ,
67
+ },
68
+ {
69
+ desc : "Host has an unknown scheme" ,
70
+ data : ExternalCache {Host : "unknownscheme://host" , Path : "/path/v1" },
71
+ expErrors : 1 ,
72
+ },
73
+ {
74
+ desc : "Wrong colon side in scheme" ,
75
+ data : ExternalCache {Host : "http//:www.appnexus.com" , Path : "/path/v1" },
76
+ expErrors : 1 ,
77
+ },
78
+ {
79
+ desc : "Missing '/' in scheme" ,
80
+ data : ExternalCache {Host : "http:/www.appnexus.com" , Path : "/path/v1" },
81
+ expErrors : 1 ,
82
+ },
83
+ {
84
+ desc : "host with scheme, no path" ,
85
+ data : ExternalCache {Host : "http://www.appnexus.com" , Path : "" },
86
+ expErrors : 1 ,
87
+ },
88
+ {
89
+ desc : "scheme, no host nor path" ,
90
+ data : ExternalCache {Host : "http://" , Path : "" },
91
+ expErrors : 1 ,
92
+ },
93
+ }
94
+ for _ , test := range testCases {
95
+ var errs configErrors
96
+ errs = test .data .validate (errs )
97
+
98
+ assert .Equal (t , test .expErrors , len (errs ), "Test case threw unexpected number of errors. Desc: %s errMsg = %v \n " , test .desc , errs )
99
+ }
100
+ }
101
+
17
102
func TestDefaults (t * testing.T ) {
18
103
v := viper .New ()
19
104
SetupViper (v , "" )
@@ -66,7 +151,7 @@ cache:
66
151
query: uuid=%PBS_CACHE_UUID%
67
152
external_cache:
68
153
host: www.externalprebidcache.net
69
- path: endpoints/cache
154
+ path: / endpoints/cache
70
155
http_client:
71
156
max_connections_per_host: 10
72
157
max_idle_connections: 500
@@ -223,7 +308,7 @@ func TestFullConfig(t *testing.T) {
223
308
cmpStrings (t , "cache.host" , cfg .CacheURL .Host , "prebidcache.net" )
224
309
cmpStrings (t , "cache.query" , cfg .CacheURL .Query , "uuid=%PBS_CACHE_UUID%" )
225
310
cmpStrings (t , "external_cache.host" , cfg .ExtCacheURL .Host , "www.externalprebidcache.net" )
226
- cmpStrings (t , "external_cache.path" , cfg .ExtCacheURL .Path , "endpoints/cache" )
311
+ cmpStrings (t , "external_cache.path" , cfg .ExtCacheURL .Path , "/ endpoints/cache" )
227
312
cmpInts (t , "http_client.max_connections_per_host" , cfg .Client .MaxConnsPerHost , 10 )
228
313
cmpInts (t , "http_client.max_idle_connections" , cfg .Client .MaxIdleConns , 500 )
229
314
cmpInts (t , "http_client.max_idle_connections_per_host" , cfg .Client .MaxIdleConnsPerHost , 20 )
0 commit comments