@@ -73,6 +73,9 @@ var RECluster = false
7373// Redis Community Edition Docker
7474var RCEDocker = false
7575
76+ // Are tests running in CI (github actions)
77+ var CI = false
78+
7679func registerProcess (port string , p * redisProcess ) {
7780 if processes == nil {
7881 processes = make (map [string ]* redisProcess )
@@ -89,14 +92,13 @@ var _ = BeforeSuite(func() {
8992 var err error
9093 RECluster , _ = strconv .ParseBool (os .Getenv ("RE_CLUSTER" ))
9194 RCEDocker , _ = strconv .ParseBool (os .Getenv ("RCE_DOCKER" ))
95+ CI , _ = strconv .ParseBool (os .Getenv ("CI" ))
9296 fmt .Printf ("RECluster: %v\n " , RECluster )
9397 fmt .Printf ("RCEDocker: %v\n " , RCEDocker )
9498 if ! RECluster && ! RCEDocker {
95-
9699 // redis stack container will be started for tests
97100 // TODO: Rewrite this section to be aware that redis stack is running in docker
98- err = startRedisStack (redisPort )
99- Expect (err ).NotTo (HaveOccurred ())
101+ startRedisStack (redisPort )
100102
101103 ringShard1 , err = startRedis (ringShard1Port )
102104 Expect (err ).NotTo (HaveOccurred ())
@@ -136,7 +138,6 @@ var _ = BeforeSuite(func() {
136138})
137139
138140var _ = AfterSuite (func () {
139- Expect (stopRedisStack (redisPort )).NotTo (HaveOccurred ())
140141 // This should result in no errors when there were no processes started from the tests
141142 Expect (cluster .Close ()).NotTo (HaveOccurred ())
142143
@@ -352,26 +353,36 @@ func redisDir(port string) (string, error) {
352353}
353354
354355func startRedisStack (port string , args ... string ) error {
356+ // don't start redis stack in CI, the github action should handle this
357+ if CI {
358+ return nil
359+ }
360+
355361 ctx := context .Background ()
356362 dockerClient , err := client .NewClientWithOpts (client .FromEnv )
357363 imageName := "redis/redis-stack-server:latest"
358364
359365 if err != nil {
360- return err
366+ panic ( err )
361367 }
362368 defer dockerClient .Close ()
363369
364370 resp , err := dockerClient .ImagePull (ctx , imageName , image.PullOptions {})
365371 if err != nil {
366- return err
372+ panic ( err )
367373 }
368374 defer resp .Close ()
369- io .Copy (io .Discard , resp )
375+
376+ _ , err = io .Copy (io .Discard , resp )
377+ if err != nil {
378+ panic (err )
379+ }
370380
371381 rePort := nat .Port (port )
372382 cont , err := dockerClient .ContainerCreate (ctx , & container.Config {
373383 Image : imageName ,
374384 ExposedPorts : nat.PortSet {rePort : struct {}{}},
385+ Env : []string {`REDIS_ARGS=--enable-debug-command yes --enable-module-command yes` },
375386 Labels : map [string ]string {"go-redis-testing" : "true" },
376387 }, & container.HostConfig {
377388 PortBindings : map [nat.Port ][]nat.PortBinding {rePort : {
@@ -383,24 +394,32 @@ func startRedisStack(port string, args ...string) error {
383394 }, nil , nil , fmt .Sprintf ("go-redis-test-%d" , time .Now ().UnixNano ()))
384395
385396 if err != nil {
386- return err
397+ panic (err )
398+ } else {
399+ fmt .Println (cont .ID )
387400 }
388401
389402 if err := dockerClient .ContainerStart (ctx , cont .ID , container.StartOptions {}); err != nil {
390- return err
403+ panic ( err )
391404 }
405+
392406 return nil
393407}
394408
395409func stopRedisStack (port string , args ... string ) error {
410+ // don't stop redis stack in CI, the github action will handle this
411+ if os .Getenv ("CI" ) == "true" {
412+ return nil
413+ }
414+
396415 ctx := context .Background ()
397416 dockerClient , err := client .NewClientWithOpts (client .FromEnv , client .WithAPIVersionNegotiation ())
398417 if err != nil {
399418 return err
400419 }
401420 defer dockerClient .Close ()
402421
403- f := filters .NewArgs (filters.KeyValuePair {Key : "go-redis-testing " , Value : "true" })
422+ f := filters .NewArgs (filters.KeyValuePair {Key : "label " , Value : "go-redis-testing= true" })
404423 containers , err := dockerClient .ContainerList (ctx , container.ListOptions {Filters : f })
405424 if err != nil {
406425 return err
0 commit comments