Skip to content

Commit 3baaaa2

Browse files
committed
test: add integration testing with dynamic Redis container
- Add integration test for Redis store using a testcontainer-managed Redis instance - Replace hardcoded Redis address with dynamic container address in test configuration - Ensure Redis container is properly cleaned up after test execution Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
1 parent c696326 commit 3baaaa2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pkg/store/factory_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package store
22

33
import (
4+
"context"
45
"testing"
56

67
"github.com/go-training/mcp-workshop/pkg/core"
@@ -166,10 +167,26 @@ func TestFactory_Create_Memory(t *testing.T) {
166167
}
167168

168169
func TestFactory_Create_Redis(t *testing.T) {
170+
ctx := context.Background()
171+
172+
// Setup Redis container using testcontainers
173+
redisAddr, err := setupRedisContainer(ctx)
174+
if err != nil {
175+
t.Skipf("Failed to setup Redis container: %v", err)
176+
}
177+
178+
// Clean up container on test completion
179+
defer func() {
180+
if redisContainer != nil {
181+
_ = redisContainer.Terminate(ctx)
182+
redisContainer = nil
183+
}
184+
}()
185+
169186
config := Config{
170187
Type: StoreTypeRedis,
171188
Redis: RedisOptions{
172-
Addr: "localhost:6379",
189+
Addr: redisAddr,
173190
},
174191
}
175192
factory := NewFactory(config)

0 commit comments

Comments
 (0)