1+ import { expect } from 'chai'
2+
3+ import { getCacheConfig } from '../../../src/cache/client'
4+
5+ describe ( 'getCacheConfig' , ( ) => {
6+ const originalEnv = process . env
7+
8+ beforeEach ( ( ) => {
9+ process . env = { ...originalEnv }
10+ delete process . env . REDIS_URI
11+ delete process . env . REDIS_USER
12+ delete process . env . REDIS_PASSWORD
13+ delete process . env . REDIS_HOST
14+ delete process . env . REDIS_PORT
15+ } )
16+
17+ afterEach ( ( ) => {
18+ process . env = originalEnv
19+ } )
20+
21+ it ( 'builds unauthenticated redis url when REDIS_URI and REDIS_PASSWORD are unset' , ( ) => {
22+ process . env . REDIS_HOST = 'localhost'
23+ process . env . REDIS_PORT = '6379'
24+
25+ const config = getCacheConfig ( )
26+
27+ expect ( config ) . to . deep . equal ( {
28+ url : 'redis://localhost:6379' ,
29+ } )
30+ } )
31+
32+ it ( 'builds authenticated redis config when REDIS_PASSWORD is set' , ( ) => {
33+ process . env . REDIS_HOST = 'localhost'
34+ process . env . REDIS_PORT = '6379'
35+ process . env . REDIS_USER = 'default'
36+ process . env . REDIS_PASSWORD = 'secret'
37+
38+ const config = getCacheConfig ( )
39+
40+ expect ( config ) . to . deep . equal ( {
41+ url : 'redis://localhost:6379' ,
42+ username : 'default' ,
43+ password : 'secret' ,
44+ } )
45+ } )
46+
47+ it ( 'defaults REDIS_USER to default when REDIS_PASSWORD is set and REDIS_USER is unset' , ( ) => {
48+ process . env . REDIS_HOST = 'localhost'
49+ process . env . REDIS_PORT = '6379'
50+ process . env . REDIS_PASSWORD = 'secret'
51+
52+ const config = getCacheConfig ( )
53+
54+ expect ( config ) . to . deep . equal ( {
55+ url : 'redis://localhost:6379' ,
56+ username : 'default' ,
57+ password : 'secret' ,
58+ } )
59+ } )
60+
61+ it ( 'prefers REDIS_URI over host/port settings' , ( ) => {
62+ process . env . REDIS_URI = 'redis://cache.internal:6380'
63+ process . env . REDIS_PASSWORD = 'secret'
64+
65+ const config = getCacheConfig ( )
66+
67+ expect ( config ) . to . deep . equal ( {
68+ url : 'redis://cache.internal:6380' ,
69+ password : 'secret' ,
70+ } )
71+ } )
72+ } )
0 commit comments