Skip to content

Commit 7c51ea6

Browse files
mdelapenyaclaude
andcommitted
chore(vearch): use Run function
This commit migrates the vearch 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 WithExposedPorts, WithCmd, WithHostConfigModifier, WithFiles, WithWaitStrategy Ref: testcontainers#3174 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1c64a46 commit 7c51ea6

File tree

1 file changed

+15
-29
lines changed

1 file changed

+15
-29
lines changed

modules/vearch/vearch.go

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,31 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
2424

2525
// Run creates an instance of the Vearch container type
2626
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*VearchContainer, error) {
27-
req := testcontainers.ContainerRequest{
28-
Image: img,
29-
ExposedPorts: []string{"8817/tcp", "9001/tcp"},
30-
Cmd: []string{"-conf=/vearch/config.toml", "all"},
31-
HostConfigModifier: func(hc *container.HostConfig) {
27+
moduleOpts := []testcontainers.ContainerCustomizer{
28+
testcontainers.WithExposedPorts("8817/tcp", "9001/tcp"),
29+
testcontainers.WithCmd("-conf=/vearch/config.toml", "all"),
30+
testcontainers.WithHostConfigModifier(func(hc *container.HostConfig) {
3231
hc.Privileged = true
33-
},
34-
Files: []testcontainers.ContainerFile{
35-
{
36-
HostFilePath: "config.toml",
37-
ContainerFilePath: "/vearch/config.toml",
38-
FileMode: 0o666,
39-
},
40-
},
41-
WaitingFor: wait.ForAll(
32+
}),
33+
testcontainers.WithFiles(testcontainers.ContainerFile{
34+
HostFilePath: "config.toml",
35+
ContainerFilePath: "/vearch/config.toml",
36+
FileMode: 0o666,
37+
}),
38+
testcontainers.WithWaitStrategy(
4239
wait.ForListeningPort("8817/tcp").WithStartupTimeout(5*time.Second),
4340
wait.ForListeningPort("9001/tcp").WithStartupTimeout(5*time.Second),
4441
),
4542
}
4643

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

6450
if err != nil {
65-
return c, fmt.Errorf("generic container: %w", err)
51+
return c, fmt.Errorf("run vearch: %w", err)
6652
}
6753

6854
return c, nil

0 commit comments

Comments
 (0)