@@ -3,6 +3,7 @@ package config_test
3
3
import (
4
4
"os"
5
5
"reflect"
6
+ "strings"
6
7
"testing"
7
8
"time"
8
9
@@ -68,8 +69,9 @@ func TestGetters(t *testing.T) {
68
69
69
70
func TestAuthConfigValidation (t * testing.T ) {
70
71
tests := map [string ]struct {
71
- cfg config.AuthorizationConfig
72
- success bool
72
+ cfg config.AuthorizationConfig
73
+ success bool
74
+ expectedErr string
73
75
}{
74
76
"success auth disabled" : {
75
77
cfg : config.AuthorizationConfig {
@@ -81,6 +83,21 @@ func TestAuthConfigValidation(t *testing.T) {
81
83
cfg : config.AuthorizationConfig {
82
84
Enabled : true ,
83
85
URL : "url" ,
86
+ Caching : & config.InMemoryCacheConfig {
87
+ Enabled : false ,
88
+ },
89
+ },
90
+ success : true ,
91
+ },
92
+ "success caching enabled" : {
93
+ cfg : config.AuthorizationConfig {
94
+ Enabled : true ,
95
+ URL : "url" ,
96
+ Caching : & config.InMemoryCacheConfig {
97
+ Enabled : true ,
98
+ KeyExpirySeconds : 100 ,
99
+ CacheCleanUpIntervalSeconds : 200 ,
100
+ },
84
101
},
85
102
success : true ,
86
103
},
@@ -89,6 +106,26 @@ func TestAuthConfigValidation(t *testing.T) {
89
106
Enabled : true ,
90
107
},
91
108
success : false ,
109
+ expectedErr : strings .Join ([]string {
110
+ "Key: 'AuthorizationConfig.Caching' " ,
111
+ "Error:Field validation for 'Caching' failed on the 'required_if' tag" ,
112
+ }, "" ),
113
+ },
114
+ "failure caching enabled no duration config" : {
115
+ cfg : config.AuthorizationConfig {
116
+ Enabled : true ,
117
+ URL : "url" ,
118
+ Caching : & config.InMemoryCacheConfig {
119
+ Enabled : true ,
120
+ },
121
+ },
122
+ success : false ,
123
+ expectedErr : strings .Join ([]string {
124
+ "Key: 'AuthorizationConfig.Caching.KeyExpirySeconds' " ,
125
+ "Error:Field validation for 'KeyExpirySeconds' failed on the 'required_if' tag\n " ,
126
+ "Key: 'AuthorizationConfig.Caching.CacheCleanUpIntervalSeconds' " ,
127
+ "Error:Field validation for 'CacheCleanUpIntervalSeconds' failed on the 'required_if' tag" ,
128
+ }, "" ),
92
129
},
93
130
}
94
131
@@ -133,7 +170,12 @@ func TestLoad(t *testing.T) {
133
170
want : & config.Config {
134
171
Port : 8080 ,
135
172
AllowedOrigins : []string {"*" },
136
- AuthConfig : & config.AuthorizationConfig {},
173
+ AuthConfig : & config.AuthorizationConfig {
174
+ Caching : & config.InMemoryCacheConfig {
175
+ KeyExpirySeconds : 600 ,
176
+ CacheCleanUpIntervalSeconds : 900 ,
177
+ },
178
+ },
137
179
DbConfig : & config.DatabaseConfig {
138
180
Host : "localhost" ,
139
181
Port : 5432 ,
@@ -201,6 +243,10 @@ func TestLoad(t *testing.T) {
201
243
AuthConfig : & config.AuthorizationConfig {
202
244
Enabled : true ,
203
245
URL : "http://example.com" ,
246
+ Caching : & config.InMemoryCacheConfig {
247
+ KeyExpirySeconds : 600 ,
248
+ CacheCleanUpIntervalSeconds : 900 ,
249
+ },
204
250
},
205
251
DbConfig : & config.DatabaseConfig {
206
252
Host : "127.0.0.1" ,
@@ -338,6 +384,10 @@ func TestLoad(t *testing.T) {
338
384
AuthConfig : & config.AuthorizationConfig {
339
385
Enabled : false ,
340
386
URL : "http://example.com" ,
387
+ Caching : & config.InMemoryCacheConfig {
388
+ KeyExpirySeconds : 600 ,
389
+ CacheCleanUpIntervalSeconds : 900 ,
390
+ },
341
391
},
342
392
DbConfig : & config.DatabaseConfig {
343
393
Host : "127.0.0.1" ,
@@ -489,6 +539,7 @@ func TestLoad(t *testing.T) {
489
539
"ALLOWEDORIGINS" : "http://baz.com,http://qux.com" ,
490
540
"AUTHCONFIG_ENABLED" : "true" ,
491
541
"AUTHCONFIG_URL" : "http://env.example.com" ,
542
+ "AUTHCONFIG_CACHING_ENABLED" : "true" ,
492
543
"DBCONFIG_USER" : "dbuser-env" ,
493
544
"DBCONFIG_PASSWORD" : "dbpassword-env" ,
494
545
"DEPLOYCONFIG_TIMEOUT" : "10m" ,
@@ -510,6 +561,11 @@ func TestLoad(t *testing.T) {
510
561
AuthConfig : & config.AuthorizationConfig {
511
562
Enabled : true ,
512
563
URL : "http://env.example.com" ,
564
+ Caching : & config.InMemoryCacheConfig {
565
+ Enabled : true ,
566
+ KeyExpirySeconds : 600 ,
567
+ CacheCleanUpIntervalSeconds : 900 ,
568
+ },
513
569
},
514
570
DbConfig : & config.DatabaseConfig {
515
571
Host : "127.0.0.1" ,
0 commit comments