Skip to content

Commit

Permalink
add some more test coverage for cache config
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps committed Jul 25, 2022
1 parent 92adb98 commit eb1af1e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 4 deletions.
41 changes: 40 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,46 @@ func TestLoad(t *testing.T) {
cfg := Default()
cfg.Cache.Enabled = true
cfg.Cache.Backend = CacheMemory
cfg.Warnings = append(cfg.Warnings, deprecatedMsgMemoryEnabled)
cfg.Cache.TTL = -1
cfg.Warnings = append(cfg.Warnings, deprecatedMsgMemoryEnabled, deprecatedMsgMemoryExpiration)
return cfg
},
},
{
name: "cache - no backend set",
path: "./testdata/cache/default.yml",
expected: func() *Config {
cfg := Default()
cfg.Cache.Enabled = true
cfg.Cache.Backend = CacheMemory
cfg.Cache.TTL = 30 * time.Minute
return cfg
},
},
{
name: "cache - memory",
path: "./testdata/cache/memory.yml",
expected: func() *Config {
cfg := Default()
cfg.Cache.Enabled = true
cfg.Cache.Backend = CacheMemory
cfg.Cache.TTL = 5 * time.Minute
cfg.Cache.Memory.EvictionInterval = 10 * time.Minute
return cfg
},
},
{
name: "cache - redis",
path: "./testdata/cache/redis.yml",
expected: func() *Config {
cfg := Default()
cfg.Cache.Enabled = true
cfg.Cache.Backend = CacheRedis
cfg.Cache.TTL = time.Minute
cfg.Cache.Redis.Host = "localhost"
cfg.Cache.Redis.Port = 6378
cfg.Cache.Redis.DB = 1
cfg.Cache.Redis.Password = "s3cr3t!"
return cfg
},
},
Expand Down
2 changes: 1 addition & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# backend: memory
# ttl: 60s
# redis:
# host: "localhost"
# host: localhost
# port: 6379
# memory:
# eviction_interval: 5m # Evict Expired Items Every 5m
Expand Down
4 changes: 2 additions & 2 deletions config/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ log:

# cache:
# enabled: false
# backend: "memory"
# backend: memory
# ttl: 60s
# redis:
# host: "localhost"
# host: localhost
# port: 6379
# memory:
# eviction_interval: 5m # evict expired items every 5m
Expand Down
3 changes: 3 additions & 0 deletions config/testdata/cache/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cache:
enabled: true
ttl: 30m
6 changes: 6 additions & 0 deletions config/testdata/cache/memory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cache:
enabled: true
backend: memory
ttl: 5m
memory:
eviction_interval: 10m
9 changes: 9 additions & 0 deletions config/testdata/cache/redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cache:
enabled: true
backend: redis
ttl: 60s
redis:
host: localhost
port: 6378
db: 1
password: "s3cr3t!"
1 change: 1 addition & 0 deletions config/testdata/deprecated/cache_memory_enabled.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cache:
memory:
enabled: true
expiration: -1

0 comments on commit eb1af1e

Please sign in to comment.