@@ -3,6 +3,7 @@ package config_test
33import (
44 "os"
55 "reflect"
6+ "strings"
67 "testing"
78 "time"
89
@@ -68,8 +69,9 @@ func TestGetters(t *testing.T) {
6869
6970func TestAuthConfigValidation (t * testing.T ) {
7071 tests := map [string ]struct {
71- cfg config.AuthorizationConfig
72- success bool
72+ cfg config.AuthorizationConfig
73+ success bool
74+ expectedErr string
7375 }{
7476 "success auth disabled" : {
7577 cfg : config.AuthorizationConfig {
@@ -81,6 +83,21 @@ func TestAuthConfigValidation(t *testing.T) {
8183 cfg : config.AuthorizationConfig {
8284 Enabled : true ,
8385 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+ },
84101 },
85102 success : true ,
86103 },
@@ -89,6 +106,26 @@ func TestAuthConfigValidation(t *testing.T) {
89106 Enabled : true ,
90107 },
91108 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+ }, "" ),
92129 },
93130 }
94131
@@ -133,7 +170,12 @@ func TestLoad(t *testing.T) {
133170 want : & config.Config {
134171 Port : 8080 ,
135172 AllowedOrigins : []string {"*" },
136- AuthConfig : & config.AuthorizationConfig {},
173+ AuthConfig : & config.AuthorizationConfig {
174+ Caching : & config.InMemoryCacheConfig {
175+ KeyExpirySeconds : 600 ,
176+ CacheCleanUpIntervalSeconds : 900 ,
177+ },
178+ },
137179 DbConfig : & config.DatabaseConfig {
138180 Host : "localhost" ,
139181 Port : 5432 ,
@@ -201,6 +243,10 @@ func TestLoad(t *testing.T) {
201243 AuthConfig : & config.AuthorizationConfig {
202244 Enabled : true ,
203245 URL : "http://example.com" ,
246+ Caching : & config.InMemoryCacheConfig {
247+ KeyExpirySeconds : 600 ,
248+ CacheCleanUpIntervalSeconds : 900 ,
249+ },
204250 },
205251 DbConfig : & config.DatabaseConfig {
206252 Host : "127.0.0.1" ,
@@ -338,6 +384,10 @@ func TestLoad(t *testing.T) {
338384 AuthConfig : & config.AuthorizationConfig {
339385 Enabled : false ,
340386 URL : "http://example.com" ,
387+ Caching : & config.InMemoryCacheConfig {
388+ KeyExpirySeconds : 600 ,
389+ CacheCleanUpIntervalSeconds : 900 ,
390+ },
341391 },
342392 DbConfig : & config.DatabaseConfig {
343393 Host : "127.0.0.1" ,
@@ -489,6 +539,7 @@ func TestLoad(t *testing.T) {
489539 "ALLOWEDORIGINS" : "http://baz.com,http://qux.com" ,
490540 "AUTHCONFIG_ENABLED" : "true" ,
491541 "AUTHCONFIG_URL" : "http://env.example.com" ,
542+ "AUTHCONFIG_CACHING_ENABLED" : "true" ,
492543 "DBCONFIG_USER" : "dbuser-env" ,
493544 "DBCONFIG_PASSWORD" : "dbpassword-env" ,
494545 "DEPLOYCONFIG_TIMEOUT" : "10m" ,
@@ -510,6 +561,11 @@ func TestLoad(t *testing.T) {
510561 AuthConfig : & config.AuthorizationConfig {
511562 Enabled : true ,
512563 URL : "http://env.example.com" ,
564+ Caching : & config.InMemoryCacheConfig {
565+ Enabled : true ,
566+ KeyExpirySeconds : 600 ,
567+ CacheCleanUpIntervalSeconds : 900 ,
568+ },
513569 },
514570 DbConfig : & config.DatabaseConfig {
515571 Host : "127.0.0.1" ,
0 commit comments