@@ -30,6 +30,36 @@ func TestReadDefaults(t *testing.T) {
3030 if got .KV .RedisURL != "" {
3131 t .Fatalf ("RedisURL = %q, want empty" , got .KV .RedisURL )
3232 }
33+ if got .KV .RedisPool .Size != 4 {
34+ t .Fatalf ("RedisPool.Size = %d, want 4" , got .KV .RedisPool .Size )
35+ }
36+ if got .KV .RedisPool .MinIdleConns != 2 {
37+ t .Fatalf ("RedisPool.MinIdleConns = %d, want 2" , got .KV .RedisPool .MinIdleConns )
38+ }
39+ if got .KV .RedisPool .MaxIdleConns != 4 {
40+ t .Fatalf ("RedisPool.MaxIdleConns = %d, want 4" , got .KV .RedisPool .MaxIdleConns )
41+ }
42+ if got .KV .RedisPool .MaxActiveConns != 8 {
43+ t .Fatalf ("RedisPool.MaxActiveConns = %d, want 8" , got .KV .RedisPool .MaxActiveConns )
44+ }
45+ if got .KV .RedisPool .Timeout != 250 * time .Millisecond {
46+ t .Fatalf ("RedisPool.Timeout = %s, want 250ms" , got .KV .RedisPool .Timeout )
47+ }
48+ if got .KV .RedisTimeouts .Dial != time .Second {
49+ t .Fatalf ("RedisTimeouts.Dial = %s, want 1s" , got .KV .RedisTimeouts .Dial )
50+ }
51+ if got .KV .RedisTimeouts .Read != 750 * time .Millisecond {
52+ t .Fatalf ("RedisTimeouts.Read = %s, want 750ms" , got .KV .RedisTimeouts .Read )
53+ }
54+ if got .KV .RedisTimeouts .Write != 750 * time .Millisecond {
55+ t .Fatalf ("RedisTimeouts.Write = %s, want 750ms" , got .KV .RedisTimeouts .Write )
56+ }
57+ if got .KV .RedisConnMaxIdle != 10 * time .Minute {
58+ t .Fatalf ("RedisConnMaxIdle = %s, want 10m" , got .KV .RedisConnMaxIdle )
59+ }
60+ if ! got .KV .RedisDisableIdentity {
61+ t .Fatal ("RedisDisableIdentity = false, want true" )
62+ }
3363 if got .Pkgsite .CacheDisabled {
3464 t .Fatal ("CacheDisabled = true, want false" )
3565 }
@@ -57,21 +87,31 @@ func TestReadOverrides(t *testing.T) {
5787 t .Parallel ()
5888
5989 got , err := read (mapGetenv (map [string ]string {
60- "PORT" : "9090" ,
61- "O11Y_SERVICE_NAME" : "pkgsite-test" ,
62- "O11Y_ENVIRONMENT" : "test" ,
63- "O11Y_FLUSH_TIMEOUT" : "5s" ,
64- "O11Y_TRACES_SAMPLE_RATE" : "0.25" ,
65- "O11Y_ENABLE_LOGS" : "false" ,
66- "O11Y_ENABLE_METRICS" : "false" ,
67- "PKGSITE_BASE_URL" : "http://example.test" ,
68- "PKGSITE_HTTP_TIMEOUT" : "250ms" ,
69- "KV_REDIS_URL" : "redis://localhost:6379/0" ,
70- "PKGSITE_CACHE_DISABLED" : "true" ,
71- "RATE_LIMIT_ENABLED" : "false" ,
72- "RATE_LIMIT_REQUESTS" : "10" ,
73- "RATE_LIMIT_WINDOW" : "30s" ,
74- "SENTRY_DSN" : "https://public@example.invalid/1" ,
90+ "PORT" : "9090" ,
91+ "O11Y_SERVICE_NAME" : "pkgsite-test" ,
92+ "O11Y_ENVIRONMENT" : "test" ,
93+ "O11Y_FLUSH_TIMEOUT" : "5s" ,
94+ "O11Y_TRACES_SAMPLE_RATE" : "0.25" ,
95+ "O11Y_ENABLE_LOGS" : "false" ,
96+ "O11Y_ENABLE_METRICS" : "false" ,
97+ "PKGSITE_BASE_URL" : "http://example.test" ,
98+ "PKGSITE_HTTP_TIMEOUT" : "250ms" ,
99+ "KV_REDIS_URL" : "redis://localhost:6379/0" ,
100+ "KV_REDIS_POOL_SIZE" : "12" ,
101+ "KV_REDIS_MIN_IDLE_CONNS" : "3" ,
102+ "KV_REDIS_MAX_IDLE_CONNS" : "6" ,
103+ "KV_REDIS_MAX_ACTIVE_CONNS" : "18" ,
104+ "KV_REDIS_POOL_TIMEOUT" : "400ms" ,
105+ "KV_REDIS_DIAL_TIMEOUT" : "2s" ,
106+ "KV_REDIS_READ_TIMEOUT" : "900ms" ,
107+ "KV_REDIS_WRITE_TIMEOUT" : "950ms" ,
108+ "KV_REDIS_CONN_MAX_IDLE_TIME" : "12m" ,
109+ "KV_REDIS_DISABLE_IDENTITY" : "false" ,
110+ "PKGSITE_CACHE_DISABLED" : "true" ,
111+ "RATE_LIMIT_ENABLED" : "false" ,
112+ "RATE_LIMIT_REQUESTS" : "10" ,
113+ "RATE_LIMIT_WINDOW" : "30s" ,
114+ "SENTRY_DSN" : "https://public@example.invalid/1" ,
75115 }))
76116 if err != nil {
77117 t .Fatalf ("Read returned error: %v" , err )
@@ -103,6 +143,36 @@ func TestReadOverrides(t *testing.T) {
103143 if got .KV .RedisURL != "redis://localhost:6379/0" {
104144 t .Fatalf ("RedisURL = %q, want override" , got .KV .RedisURL )
105145 }
146+ if got .KV .RedisPool .Size != 12 {
147+ t .Fatalf ("RedisPool.Size = %d, want 12" , got .KV .RedisPool .Size )
148+ }
149+ if got .KV .RedisPool .MinIdleConns != 3 {
150+ t .Fatalf ("RedisPool.MinIdleConns = %d, want 3" , got .KV .RedisPool .MinIdleConns )
151+ }
152+ if got .KV .RedisPool .MaxIdleConns != 6 {
153+ t .Fatalf ("RedisPool.MaxIdleConns = %d, want 6" , got .KV .RedisPool .MaxIdleConns )
154+ }
155+ if got .KV .RedisPool .MaxActiveConns != 18 {
156+ t .Fatalf ("RedisPool.MaxActiveConns = %d, want 18" , got .KV .RedisPool .MaxActiveConns )
157+ }
158+ if got .KV .RedisPool .Timeout != 400 * time .Millisecond {
159+ t .Fatalf ("RedisPool.Timeout = %s, want 400ms" , got .KV .RedisPool .Timeout )
160+ }
161+ if got .KV .RedisTimeouts .Dial != 2 * time .Second {
162+ t .Fatalf ("RedisTimeouts.Dial = %s, want 2s" , got .KV .RedisTimeouts .Dial )
163+ }
164+ if got .KV .RedisTimeouts .Read != 900 * time .Millisecond {
165+ t .Fatalf ("RedisTimeouts.Read = %s, want 900ms" , got .KV .RedisTimeouts .Read )
166+ }
167+ if got .KV .RedisTimeouts .Write != 950 * time .Millisecond {
168+ t .Fatalf ("RedisTimeouts.Write = %s, want 950ms" , got .KV .RedisTimeouts .Write )
169+ }
170+ if got .KV .RedisConnMaxIdle != 12 * time .Minute {
171+ t .Fatalf ("RedisConnMaxIdle = %s, want 12m" , got .KV .RedisConnMaxIdle )
172+ }
173+ if got .KV .RedisDisableIdentity {
174+ t .Fatal ("RedisDisableIdentity = true, want false" )
175+ }
106176 if ! got .Pkgsite .CacheDisabled {
107177 t .Fatal ("CacheDisabled = false, want true" )
108178 }
@@ -148,12 +218,14 @@ func TestReadParseErrorReportsAllFailures(t *testing.T) {
148218 _ , err := read (mapGetenv (map [string ]string {
149219 "O11Y_FLUSH_TIMEOUT" : "soon" ,
150220 "PKGSITE_HTTP_TIMEOUT" : "later" ,
221+ "KV_REDIS_POOL_SIZE" : "several" ,
151222 "RATE_LIMIT_REQUESTS" : "lots" ,
152223 }))
153224 if err == nil {
154225 t .Fatal ("Read returned nil error, want parse error" )
155226 }
156- const want = `config: parsing O11Y_FLUSH_TIMEOUT="soon": time: invalid duration "soon"
227+ const want = `config: parsing KV_REDIS_POOL_SIZE="several": strconv.Atoi: parsing "several": invalid syntax
228+ config: parsing O11Y_FLUSH_TIMEOUT="soon": time: invalid duration "soon"
157229config: parsing PKGSITE_HTTP_TIMEOUT="later": time: invalid duration "later"
158230config: parsing RATE_LIMIT_REQUESTS="lots": strconv.Atoi: parsing "lots": invalid syntax`
159231 if err .Error () != want {
0 commit comments