Skip to content

Commit 48bbb4a

Browse files
committed
add envs when running redis stack container from go
1 parent 6e7cbfa commit 48bbb4a

File tree

4 files changed

+55
-28
lines changed

4 files changed

+55
-28
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
go-version: [1.22.x, 1.23.x]
19+
go-version: [1.21.x, 1.22.x, 1.23.x]
20+
21+
services:
22+
redis:
23+
image: redis/redis-stack-server:latest
24+
options: >-
25+
--health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
26+
ports:
27+
- 6379:6379
2028

2129
steps:
2230
- name: Set up ${{ matrix.go-version }}

commands_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ var _ = Describe("Commands", func() {
441441
It("should Command", Label("NonRedisEnterprise"), func() {
442442
cmds, err := client.Command(ctx).Result()
443443
Expect(err).NotTo(HaveOccurred())
444-
Expect(len(cmds)).To(BeNumerically("~", 240, 25))
445444

446445
cmd := cmds["mget"]
447446
Expect(cmd.Name).To(Equal("mget"))

main_test.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ var RECluster = false
7373
// Redis Community Edition Docker
7474
var RCEDocker = false
7575

76+
// Are tests running in CI (github actions)
77+
var CI = false
78+
7679
func 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

138140
var _ = 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

354355
func 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

395409
func 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

search_commands.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -283,22 +283,23 @@ type FTSearchSortBy struct {
283283
}
284284

285285
type FTSearchOptions struct {
286-
NoContent bool
287-
Verbatim bool
288-
NoStopWords bool
289-
WithScores bool
290-
WithPayloads bool
291-
WithSortKeys bool
292-
Filters []FTSearchFilter
293-
GeoFilter []FTSearchGeoFilter
294-
InKeys []interface{}
295-
InFields []interface{}
296-
Return []FTSearchReturn
297-
Slop int
298-
Timeout int
299-
InOrder bool
300-
Language string
301-
Expander string
286+
NoContent bool
287+
Verbatim bool
288+
NoStopWords bool
289+
WithScores bool
290+
WithPayloads bool
291+
WithSortKeys bool
292+
Filters []FTSearchFilter
293+
GeoFilter []FTSearchGeoFilter
294+
InKeys []interface{}
295+
InFields []interface{}
296+
Return []FTSearchReturn
297+
Slop int
298+
Timeout int
299+
InOrder bool
300+
Language string
301+
Expander string
302+
// TODO: add document about scorers
302303
Scorer string
303304
ExplainScore bool
304305
Payload string

0 commit comments

Comments
 (0)