@@ -119,4 +119,47 @@ 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+ const 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 with custom command and keeping default args" , async ( ) => {
140+ const sourcePath = fs . mkdtempSync ( "redis-" ) ;
141+
142+ const container = new RedisContainer ( IMAGE )
143+ . withCommand ( [ "redis-server" , "--loglevel" , "verbose" ] )
144+ . withPersistence ( sourcePath ) ;
145+ const startedContainer = await container . start ( ) ;
146+
147+ // @ts -expect-error - accessing private property for testing
148+ expect ( container . createOpts . Cmd ) . toEqual ( [
149+ "redis-server" ,
150+ "--loglevel" ,
151+ "verbose" ,
152+ "--save 1 1 " ,
153+ "--appendonly yes" ,
154+ ] ) ;
155+
156+ const client = createClient ( { url : startedContainer . getConnectionUrl ( ) } ) ;
157+ await client . connect ( ) ;
158+
159+ await client . set ( "key" , "val" ) ;
160+ expect ( await client . get ( "key" ) ) . toBe ( "val" ) ;
161+
162+ client . destroy ( ) ;
163+ fs . rmSync ( sourcePath , { force : true , recursive : true } ) ;
164+ } ) ;
122165} ) ;
0 commit comments