Skip to content

Commit cbe9cf3

Browse files
committed
feat: improve Redis Sentinel test setup and dynamic host configuration
- Add context initialization and setup for Redis cluster container in `TestRedisSentinel` - Add defer cleanup for the Redis container - Add retrieval and error checking for master and slave ports - Add retrieval and error checking for host IP - Replace hardcoded host addresses with dynamically generated master and slave names Signed-off-by: appleboy <[email protected]>
1 parent f9eb0d8 commit cbe9cf3

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

redis_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,28 @@ func TestRedisCluster(t *testing.T) {
213213

214214
func TestRedisSentinel(t *testing.T) {
215215
t.Helper()
216+
217+
ctx := context.Background()
218+
redisC, _ := setupRedisCluserContainer(ctx, t)
219+
defer testcontainers.CleanupContainer(t, redisC)
220+
221+
masterPort, err := redisC.MappedPort(ctx, "6379")
222+
assert.NoError(t, err)
223+
224+
slavePort, err := redisC.MappedPort(ctx, "6382")
225+
assert.NoError(t, err)
226+
227+
hostIP, err := redisC.Host(ctx)
228+
assert.NoError(t, err)
229+
216230
m := &mockMessage{
217231
Message: "foo",
218232
}
219-
hosts := []string{"127.0.0.1:26379", "127.0.0.1:26380"}
233+
234+
masterName := fmt.Sprintf("%s:%s", hostIP, masterPort.Port())
235+
slaveName := fmt.Sprintf("%s:%s", hostIP, slavePort.Port())
236+
237+
hosts := []string{masterName, slaveName}
220238

221239
w := NewWorker(
222240
WithAddr(strings.Join(hosts, ",")),

0 commit comments

Comments
 (0)