@@ -119,4 +119,84 @@ describe("RedisContainer", { timeout: 240_000 }, () => {
119119 client . destroy ( ) ;
120120 // }
121121 } ) ;
122+
123+ it ( "should start redis with custom command" , async ( ) => {
124+ const container = new RedisContainer ( IMAGE ) . withCommand ( [ "redis-server" , "--loglevel" , "verbose" ] ) ;
125+ await using startedContainer = await container . start ( ) ;
126+
127+ // @ts -expect-error - accessing private property for testing
128+ expect ( container . createOpts . Cmd ) . toEqual ( [ "redis-server" , "--loglevel" , "verbose" ] ) ;
129+
130+ const client = createClient ( { url : startedContainer . getConnectionUrl ( ) } ) ;
131+ await client . connect ( ) ;
132+
133+ await client . set ( "key" , "val" ) ;
134+ expect ( await client . get ( "key" ) ) . toBe ( "val" ) ;
135+
136+ client . destroy ( ) ;
137+ } ) ;
138+
139+ it ( "should start redis-stack with custom env" , async ( ) => {
140+ const container = new RedisContainer ( REDISSTACK_IMAGE ) . withEnvironment ( { REDIS_ARGS : "--loglevel verbose" } ) ;
141+ await using startedContainer = await container . start ( ) ;
142+
143+ // @ts -expect-error - accessing private property for testing
144+ expect ( container . createOpts . Env ) . toEqual ( [ "REDIS_ARGS=--loglevel verbose" ] ) ;
145+
146+ const client = createClient ( { url : startedContainer . getConnectionUrl ( ) } ) ;
147+ await client . connect ( ) ;
148+
149+ await client . set ( "key" , "val" ) ;
150+ expect ( await client . get ( "key" ) ) . toBe ( "val" ) ;
151+
152+ client . destroy ( ) ;
153+ } ) ;
154+
155+ it ( "should start redis with custom command and keeping default args" , async ( ) => {
156+ const sourcePath = fs . mkdtempSync ( "redis-" ) ;
157+
158+ const container = new RedisContainer ( IMAGE )
159+ . withCommand ( [ "redis-server" , "--loglevel" , "verbose" ] )
160+ . withPersistence ( sourcePath ) ;
161+ await using startedContainer = await container . start ( ) ;
162+
163+ // @ts -expect-error - accessing private property for testing
164+ expect ( container . createOpts . Cmd ) . toEqual ( [
165+ "redis-server" ,
166+ "--loglevel" ,
167+ "verbose" ,
168+ "--save 1 1 " ,
169+ "--appendonly yes" ,
170+ ] ) ;
171+
172+ const client = createClient ( { url : startedContainer . getConnectionUrl ( ) } ) ;
173+ await client . connect ( ) ;
174+
175+ await client . set ( "key" , "val" ) ;
176+ expect ( await client . get ( "key" ) ) . toBe ( "val" ) ;
177+
178+ client . destroy ( ) ;
179+ fs . rmSync ( sourcePath , { force : true , recursive : true } ) ;
180+ } ) ;
181+
182+ it ( "should start redis-stack with custom env and keeping default args" , async ( ) => {
183+ const sourcePath = fs . mkdtempSync ( "redis-" ) ;
184+
185+ const container = new RedisContainer ( REDISSTACK_IMAGE )
186+ . withEnvironment ( { REDIS_ARGS : "--loglevel verbose" } )
187+ . withPersistence ( sourcePath ) ;
188+ await using startedContainer = await container . start ( ) ;
189+
190+ // @ts -expect-error - accessing private property for testing
191+ expect ( container . createOpts . Env ) . toEqual ( [ "REDIS_ARGS=--loglevel verbose --save 1 1 --appendonly yes" ] ) ;
192+
193+ const client = createClient ( { url : startedContainer . getConnectionUrl ( ) } ) ;
194+ await client . connect ( ) ;
195+
196+ await client . set ( "key" , "val" ) ;
197+ expect ( await client . get ( "key" ) ) . toBe ( "val" ) ;
198+
199+ client . destroy ( ) ;
200+ fs . rmSync ( sourcePath , { force : true , recursive : true } ) ;
201+ } ) ;
122202} ) ;
0 commit comments