@@ -3,7 +3,7 @@ import { expect } from 'chai'
33import { getCacheConfig } from '../../../src/cache/client'
44
55describe ( 'getCacheConfig' , ( ) => {
6- const originalEnv = { ... process . env }
6+ const originalEnv = process . env
77
88 beforeEach ( ( ) => {
99 process . env = { ...originalEnv }
@@ -14,7 +14,7 @@ describe('getCacheConfig', () => {
1414 delete process . env . REDIS_PORT
1515 } )
1616
17- after ( ( ) => {
17+ afterEach ( ( ) => {
1818 process . env = originalEnv
1919 } )
2020
@@ -29,7 +29,7 @@ describe('getCacheConfig', () => {
2929 } )
3030 } )
3131
32- it ( 'builds authenticated redis url when REDIS_PASSWORD is set' , ( ) => {
32+ it ( 'builds authenticated redis config when REDIS_PASSWORD is set' , ( ) => {
3333 process . env . REDIS_HOST = 'localhost'
3434 process . env . REDIS_PORT = '6379'
3535 process . env . REDIS_USER = 'default'
@@ -38,7 +38,22 @@ describe('getCacheConfig', () => {
3838 const config = getCacheConfig ( )
3939
4040 expect ( config ) . to . deep . equal ( {
41- url : 'redis://default:secret@localhost:6379' ,
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' ,
4257 password : 'secret' ,
4358 } )
4459 } )
0 commit comments