Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing for running tests on a port other than the fixed 6380 #2466

Merged
merged 5 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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