Skip to content

Commit a4f70e3

Browse files
mdelapenyaclaude
andcommitted
chore(weaviate): use Run function
This commit migrates the weaviate module to use the new testcontainers.Run() API. The main changes are: - Use testcontainers.Run() instead of testcontainers.GenericContainer() - Convert to moduleOpts pattern with functional options - Use WithCmd, WithExposedPorts, WithEnv, WithWaitStrategy - Multiple wait strategies for HTTP and gRPC ports Tests: 7 tests, 78.6% coverage Ref: testcontainers#3174 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1c64a46 commit a4f70e3

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

modules/weaviate/weaviate.go

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,28 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
2727

2828
// Run creates an instance of the Weaviate container type
2929
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*WeaviateContainer, error) {
30-
req := testcontainers.ContainerRequest{
31-
Image: img,
32-
Cmd: []string{"--host", "0.0.0.0", "--scheme", "http", "--port", "8080"},
33-
ExposedPorts: []string{httpPort, grpcPort},
34-
Env: map[string]string{
30+
moduleOpts := []testcontainers.ContainerCustomizer{
31+
testcontainers.WithCmd("--host", "0.0.0.0", "--scheme", "http", "--port", "8080"),
32+
testcontainers.WithExposedPorts(httpPort, grpcPort),
33+
testcontainers.WithEnv(map[string]string{
3534
"AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED": "true",
3635
"PERSISTENCE_DATA_PATH": "/var/lib/weaviate",
37-
},
38-
WaitingFor: wait.ForAll(
36+
}),
37+
testcontainers.WithWaitStrategy(
3938
wait.ForListeningPort(httpPort).WithStartupTimeout(5*time.Second),
4039
wait.ForListeningPort(grpcPort).WithStartupTimeout(5*time.Second),
4140
wait.ForHTTP("/v1/.well-known/ready").WithPort(httpPort),
4241
),
4342
}
4443

45-
genericContainerReq := testcontainers.GenericContainerRequest{
46-
ContainerRequest: req,
47-
Started: true,
48-
}
49-
50-
for _, opt := range opts {
51-
if err := opt.Customize(&genericContainerReq); err != nil {
52-
return nil, err
53-
}
54-
}
55-
56-
container, err := testcontainers.GenericContainer(ctx, genericContainerReq)
44+
ctr, err := testcontainers.Run(ctx, img, append(moduleOpts, opts...)...)
5745
var c *WeaviateContainer
58-
if container != nil {
59-
c = &WeaviateContainer{Container: container}
46+
if ctr != nil {
47+
c = &WeaviateContainer{Container: ctr}
6048
}
6149

6250
if err != nil {
63-
return c, fmt.Errorf("generic container: %w", err)
51+
return c, fmt.Errorf("run weaviate: %w", err)
6452
}
6553

6654
return c, nil

0 commit comments

Comments
 (0)