Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions modules/clickhouse/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,7 @@ func TestClickHouseWithZookeeper(t *testing.T) {
// withZookeeper {
zkPort := nat.Port("2181/tcp")

zkcontainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
ExposedPorts: []string{zkPort.Port()},
Image: "zookeeper:3.7",
WaitingFor: wait.ForListeningPort(zkPort),
},
Started: true,
})
zkcontainer, err := testcontainers.Run(ctx, "zookeeper:3.7", testcontainers.WithExposedPorts(zkPort.Port()), testcontainers.WithWaitStrategy(wait.ForListeningPort(zkPort)))
testcontainers.CleanupContainer(t, zkcontainer)
require.NoError(t, err)

Expand Down
13 changes: 1 addition & 12 deletions modules/k6/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,7 @@ func ExampleRun() {

// create a container with the httpbin application that will be the target
// for the test script that runs in the k6 container
gcr := testcontainers.GenericContainerRequest{
ProviderType: testcontainers.ProviderDocker,
ContainerRequest: testcontainers.ContainerRequest{
Image: "kennethreitz/httpbin",
ExposedPorts: []string{
"80",
},
WaitingFor: wait.ForExposedPort(),
},
Started: true,
}
httpbin, err := testcontainers.GenericContainer(ctx, gcr)
httpbin, err := testcontainers.Run(ctx, "kennethreitz/httpbin", testcontainers.WithExposedPorts("80/tcp"), testcontainers.WithWaitStrategy(wait.ForExposedPort()))
defer func() {
if err := testcontainers.TerminateContainer(httpbin); err != nil {
log.Printf("failed to terminate container: %s", err)
Expand Down
52 changes: 24 additions & 28 deletions modules/localstack/localstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,35 +224,31 @@ func TestStartV2WithNetwork(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, localstack)

networkName := nw.Name

cli, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "amazon/aws-cli:2.7.27",
Networks: []string{networkName},
Entrypoint: []string{"tail"},
Cmd: []string{"-f", "/dev/null"},
Env: map[string]string{
"AWS_ACCESS_KEY_ID": "accesskey",
"AWS_SECRET_ACCESS_KEY": "secretkey",
"AWS_REGION": "eu-west-1",
},
WaitingFor: wait.ForExec([]string{
"/usr/local/bin/aws", "sqs", "create-queue", "--queue-name", "baz", "--region", "eu-west-1",
"--endpoint-url", "http://localstack:4566", "--no-verify-ssl",
cli, err := testcontainers.Run(
ctx, "amazon/aws-cli:2.7.27",
network.WithNetwork([]string{"cli"}, nw),
testcontainers.WithEntrypoint("tail"),
testcontainers.WithCmd("-f", "/dev/null"),
testcontainers.WithEnv(map[string]string{
"AWS_ACCESS_KEY_ID": "accesskey",
"AWS_SECRET_ACCESS_KEY": "secretkey",
"AWS_REGION": "eu-west-1",
}),
testcontainers.WithWaitStrategy(wait.ForExec([]string{
"/usr/local/bin/aws", "sqs", "create-queue", "--queue-name", "baz", "--region", "eu-west-1",
"--endpoint-url", "http://localstack:4566", "--no-verify-ssl",
}).
WithStartupTimeout(time.Second*10).
WithExitCodeMatcher(func(exitCode int) bool {
return exitCode == 0
}).
WithStartupTimeout(time.Second * 10).
WithExitCodeMatcher(func(exitCode int) bool {
return exitCode == 0
}).
WithResponseMatcher(func(r io.Reader) bool {
respBytes, _ := io.ReadAll(r)
resp := string(respBytes)
return strings.Contains(resp, "http://localstack:4566")
}),
},
Started: true,
})
WithResponseMatcher(func(r io.Reader) bool {
respBytes, _ := io.ReadAll(r)
resp := string(respBytes)
return strings.Contains(resp, "http://localstack:4566")
}),
),
)
testcontainers.CleanupContainer(t, cli)
require.NoError(t, err)
require.NotNil(t, cli)
Expand Down
22 changes: 6 additions & 16 deletions modules/redpanda/redpanda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,22 +587,12 @@ func TestRedpandaListener_Simple(t *testing.T) {

// 3. Start KCat container
// withListenerKcat {
kcat, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "confluentinc/cp-kcat:7.4.1",
Networks: []string{
rpNetwork.Name,
},
Entrypoint: []string{
"sh",
},
Cmd: []string{
"-c",
"tail -f /dev/null",
},
},
Started: true,
})
kcat, err := testcontainers.Run(
ctx, "confluentinc/cp-kcat:7.4.1",
network.WithNetwork([]string{"kcat"}, rpNetwork),
testcontainers.WithEntrypoint("sh"),
testcontainers.WithCmd("-c", "tail -f /dev/null"),
)
// }
testcontainers.CleanupContainer(t, kcat)
require.NoError(t, err)
Expand Down
63 changes: 27 additions & 36 deletions modules/registry/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,18 @@ func ExampleRun_withAuthentication() {
// build a custom redis image from the private registry,
// using RegistryName of the container as the registry.

redisC, err := testcontainers.GenericContainer(context.Background(), testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: filepath.Join("testdata", "redis"),
BuildArgs: map[string]*string{
"REGISTRY_HOST": &registryHost,
},
redisC, err := testcontainers.Run(
context.Background(), "",
testcontainers.WithDockerfile(testcontainers.FromDockerfile{
Context: filepath.Join("testdata", "redis"),
BuildArgs: map[string]*string{
"REGISTRY_HOST": &registryHost,
},
AlwaysPullImage: true, // make sure the authentication takes place
ExposedPorts: []string{"6379/tcp"},
WaitingFor: wait.ForLog("Ready to accept connections"),
},
Started: true,
})
}),
testcontainers.WithAlwaysPull(), // make sure the authentication takes place
testcontainers.WithExposedPorts("6379/tcp"),
testcontainers.WithWaitStrategy(wait.ForLog("Ready to accept connections")),
)
defer func() {
if err := testcontainers.TerminateContainer(redisC); err != nil {
log.Printf("failed to terminate container: %s", err)
Expand Down Expand Up @@ -155,22 +153,19 @@ func ExampleRun_pushImage() {
repo := registryContainer.RegistryName + "/customredis"
tag := "v1.2.3"

redisC, err := testcontainers.GenericContainer(context.Background(), testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: filepath.Join("testdata", "redis"),
BuildArgs: map[string]*string{
"REGISTRY_HOST": &registryHost,
},
Repo: repo,
Tag: tag,
redisC, err := testcontainers.Run(context.Background(), "",
testcontainers.WithDockerfile(testcontainers.FromDockerfile{
Context: filepath.Join("testdata", "redis"),
BuildArgs: map[string]*string{
"REGISTRY_HOST": &registryHost,
},
AlwaysPullImage: true, // make sure the authentication takes place
ExposedPorts: []string{"6379/tcp"},
WaitingFor: wait.ForLog("Ready to accept connections"),
},
Started: true,
})
Repo: repo,
Tag: tag,
}),
testcontainers.WithAlwaysPull(), // make sure the authentication takes place
testcontainers.WithExposedPorts("6379/tcp"),
testcontainers.WithWaitStrategy(wait.ForLog("Ready to accept connections")),
)
defer func() {
if err := testcontainers.TerminateContainer(redisC); err != nil {
log.Printf("failed to terminate container: %s", err)
Expand Down Expand Up @@ -247,14 +242,10 @@ func ExampleRun_pushImage() {
return
}

newRedisC, err := testcontainers.GenericContainer(context.Background(), testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: taggedImage,
ExposedPorts: []string{"6379/tcp"},
WaitingFor: wait.ForLog("Ready to accept connections"),
},
Started: true,
})
newRedisC, err := testcontainers.Run(context.Background(), taggedImage,
testcontainers.WithExposedPorts("6379/tcp"),
testcontainers.WithWaitStrategy(wait.ForLog("Ready to accept connections")),
)
defer func() {
if err := testcontainers.TerminateContainer(newRedisC); err != nil {
log.Printf("failed to terminate container: %s", err)
Expand Down
71 changes: 32 additions & 39 deletions modules/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,18 @@ func TestRunContainer_authenticated(t *testing.T) {
t.Run("build images with wrong credentials fails", func(tt *testing.T) {
setAuthConfig(tt, registryHost, "foo", "bar")

redisC, err := testcontainers.GenericContainer(context.Background(), testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: filepath.Join("testdata", "redis"),
BuildArgs: map[string]*string{
"REGISTRY_HOST": &registryHost,
},
redisC, err := testcontainers.Run(
context.Background(), "",
testcontainers.WithDockerfile(testcontainers.FromDockerfile{
Context: filepath.Join("testdata", "redis"),
BuildArgs: map[string]*string{
"REGISTRY_HOST": &registryHost,
},
AlwaysPullImage: true, // make sure the authentication takes place
ExposedPorts: []string{"6379/tcp"},
WaitingFor: wait.ForLog("Ready to accept connections"),
},
Started: true,
})
}),
testcontainers.WithAlwaysPull(), // make sure the authentication takes place
testcontainers.WithExposedPorts("6379/tcp"),
testcontainers.WithWaitStrategy(wait.ForLog("Ready to accept connections")),
)
testcontainers.CleanupContainer(tt, redisC)
require.Error(tt, err)
require.Contains(tt, err.Error(), "unauthorized: authentication required")
Expand All @@ -123,20 +121,18 @@ func TestRunContainer_authenticated(t *testing.T) {
// The container should start because the authentication
// is correct.

redisC, err := testcontainers.GenericContainer(context.Background(), testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: filepath.Join("testdata", "redis"),
BuildArgs: map[string]*string{
"REGISTRY_HOST": &registryHost,
},
redisC, err := testcontainers.Run(
context.Background(), "",
testcontainers.WithDockerfile(testcontainers.FromDockerfile{
Context: filepath.Join("testdata", "redis"),
BuildArgs: map[string]*string{
"REGISTRY_HOST": &registryHost,
},
AlwaysPullImage: true, // make sure the authentication takes place
ExposedPorts: []string{"6379/tcp"},
WaitingFor: wait.ForLog("Ready to accept connections"),
},
Started: true,
})
}),
testcontainers.WithAlwaysPull(), // make sure the authentication takes place
testcontainers.WithExposedPorts("6379/tcp"),
testcontainers.WithWaitStrategy(wait.ForLog("Ready to accept connections")),
)
testcontainers.CleanupContainer(tt, redisC)
require.NoError(tt, err)

Expand Down Expand Up @@ -256,20 +252,17 @@ func TestRunContainer_wrongData(t *testing.T) {
// The container won't be able to start because the data
// directory is wrong.

redisC, err := testcontainers.GenericContainer(context.Background(), testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: filepath.Join("testdata", "redis"),
BuildArgs: map[string]*string{
"REGISTRY_HOST": &registryHost,
},
redisC, err := testcontainers.Run(context.Background(), "",
testcontainers.WithDockerfile(testcontainers.FromDockerfile{
Context: filepath.Join("testdata", "redis"),
BuildArgs: map[string]*string{
"REGISTRY_HOST": &registryHost,
},
AlwaysPullImage: true, // make sure the authentication takes place
ExposedPorts: []string{"6379/tcp"},
WaitingFor: wait.ForLog("Ready to accept connections"),
},
Started: true,
})
}),
testcontainers.WithAlwaysPull(), // make sure the authentication takes place
testcontainers.WithExposedPorts("6379/tcp"),
testcontainers.WithWaitStrategy(wait.ForLog("Ready to accept connections")),
)
testcontainers.CleanupContainer(t, redisC)
require.ErrorContains(t, err, "manifest unknown")
}
Expand Down
30 changes: 8 additions & 22 deletions modules/socat/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,10 @@ func ExampleRun() {
}
}()

ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "testcontainers/helloworld:1.2.0",
ExposedPorts: []string{"8080/tcp"},
Networks: []string{nw.Name},
NetworkAliases: map[string][]string{
nw.Name: {"helloworld"},
},
},
Started: true,
})
ctr, err := testcontainers.Run(ctx, "testcontainers/helloworld:1.2.0",
testcontainers.WithExposedPorts("8080/tcp"),
network.WithNetwork([]string{"helloworld"}, nw),
)
if err != nil {
log.Printf("failed to create container: %v", err)
return
Expand Down Expand Up @@ -106,17 +99,10 @@ func ExampleRun_multipleTargets() {
// }

// createHelloWorldContainer {
ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "testcontainers/helloworld:1.2.0",
ExposedPorts: []string{"8080/tcp"},
Networks: []string{nw.Name},
NetworkAliases: map[string][]string{
nw.Name: {"helloworld"},
},
},
Started: true,
})
ctr, err := testcontainers.Run(ctx, "testcontainers/helloworld:1.2.0",
network.WithNetwork([]string{"helloworld"}, nw),
testcontainers.WithExposedPorts("8080/tcp"),
)
if err != nil {
log.Printf("failed to create container: %v", err)
return
Expand Down
Loading
Loading