Skip to content

Commit cbfe6cd

Browse files
chayimvmihailencomonkey92t
authored
Allowing for running tests on a port other than the fixed 6380 (#2466)
* Allowing for redis on a specified port * updating the readme --------- Co-authored-by: Vladimir Mihailenco <[email protected]> Co-authored-by: Monkey <[email protected]>
1 parent ad89a97 commit cbfe6cd

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ Lastly, run:
167167
go test
168168
```
169169

170+
Another option is to run your specific tests with an already running redis. The example below, tests against a redis running on port 9999.:
171+
172+
```shell
173+
REDIS_PORT=9999 go test <your options>
174+
```
175+
170176
## See also
171177

172178
- [Golang ORM](https://bun.uptrace.dev) for PostgreSQL, MySQL, MSSQL, and SQLite

main_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
)
1818

1919
const (
20-
redisPort = "6380"
21-
redisAddr = ":" + redisPort
2220
redisSecondaryPort = "6381"
2321
)
2422

@@ -38,6 +36,9 @@ const (
3836
sentinelPort3 = "9128"
3937
)
4038

39+
var redisPort = "6380"
40+
var redisAddr = ":" + redisPort
41+
4142
var (
4243
sentinelAddrs = []string{":" + sentinelPort1, ":" + sentinelPort2, ":" + sentinelPort3}
4344

@@ -64,6 +65,11 @@ func registerProcess(port string, p *redisProcess) {
6465
}
6566

6667
var _ = BeforeSuite(func() {
68+
addr := os.Getenv("REDIS_PORT")
69+
if addr != "" {
70+
redisPort = addr
71+
redisAddr = ":" + redisPort
72+
}
6773
var err error
6874

6975
redisMain, err = startRedis(redisPort)

redis_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"errors"
7+
"fmt"
78
"net"
89
"testing"
910
"time"
@@ -64,7 +65,7 @@ var _ = Describe("Client", func() {
6465
})
6566

6667
It("should Stringer", func() {
67-
Expect(client.String()).To(Equal("Redis<:6380 db:15>"))
68+
Expect(client.String()).To(Equal(fmt.Sprintf("Redis<:%s db:15>", redisPort)))
6869
})
6970

7071
It("supports context", func() {

0 commit comments

Comments
 (0)