From 7f2c26cf7202fbeec582fd07d3fb1b20875fa7d5 Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" Date: Tue, 28 Feb 2023 09:18:12 +0200 Subject: [PATCH 1/2] Allowing for redis on a specified port --- main_test.go | 10 ++++++++-- redis_test.go | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/main_test.go b/main_test.go index a5f184fc2..b1a1f3950 100644 --- a/main_test.go +++ b/main_test.go @@ -17,8 +17,6 @@ import ( ) const ( - redisPort = "6380" - redisAddr = ":" + redisPort redisSecondaryPort = "6381" ) @@ -38,6 +36,9 @@ const ( sentinelPort3 = "9128" ) +var redisPort = "6380" +var redisAddr = ":" + redisPort + var ( sentinelAddrs = []string{":" + sentinelPort1, ":" + sentinelPort2, ":" + sentinelPort3} @@ -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) diff --git a/redis_test.go b/redis_test.go index 6d3842070..92b24c729 100644 --- a/redis_test.go +++ b/redis_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "errors" + "fmt" "net" "testing" "time" @@ -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() { From 75f68036347e38128957f6e0834ff22a17b3b468 Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" Date: Tue, 28 Feb 2023 09:20:20 +0200 Subject: [PATCH 2/2] updating the readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index d5cc65774..36d60fd4e 100644 --- a/README.md +++ b/README.md @@ -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 +``` + ## See also - [Golang ORM](https://bun.uptrace.dev) for PostgreSQL, MySQL, MSSQL, and SQLite