Skip to content

Commit

Permalink
Allowing for running tests on a port other than the fixed 6380 (redis…
Browse files Browse the repository at this point in the history
…#2466)

* Allowing for redis on a specified port

* updating the readme

---------

Co-authored-by: Vladimir Mihailenco <[email protected]>
Co-authored-by: Monkey <[email protected]>
  • Loading branch information
3 people authored Mar 6, 2023
1 parent ad89a97 commit cbfe6cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ Lastly, run:
go test
```

Another option is to run your specific tests with an already running redis. The example below, tests against a redis running on port 9999.:

```shell
REDIS_PORT=9999 go test <your options>
```

## See also

- [Golang ORM](https://bun.uptrace.dev) for PostgreSQL, MySQL, MSSQL, and SQLite
Expand Down
10 changes: 8 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
)

const (
redisPort = "6380"
redisAddr = ":" + redisPort
redisSecondaryPort = "6381"
)

Expand All @@ -38,6 +36,9 @@ const (
sentinelPort3 = "9128"
)

var redisPort = "6380"
var redisAddr = ":" + redisPort

var (
sentinelAddrs = []string{":" + sentinelPort1, ":" + sentinelPort2, ":" + sentinelPort3}

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

var _ = BeforeSuite(func() {
addr := os.Getenv("REDIS_PORT")
if addr != "" {
redisPort = addr
redisAddr = ":" + redisPort
}
var err error

redisMain, err = startRedis(redisPort)
Expand Down
3 changes: 2 additions & 1 deletion redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
"fmt"
"net"
"testing"
"time"
Expand Down Expand Up @@ -64,7 +65,7 @@ var _ = Describe("Client", func() {
})

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

It("supports context", func() {
Expand Down

0 comments on commit cbfe6cd

Please sign in to comment.