Files
sablier/pkg/provider/docker/testcontainers_test.go
dependabot[bot] 52ce80d46c build(deps): bump the testcontainers-go group across 1 directory with 3 updates (#578)
* build(deps): bump the testcontainers-go group across 1 directory with 3 updates

Bumps the testcontainers-go group with 3 updates in the / directory: [github.com/testcontainers/testcontainers-go](https://github.com/testcontainers/testcontainers-go), [github.com/testcontainers/testcontainers-go/modules/k3s](https://github.com/testcontainers/testcontainers-go) and [github.com/testcontainers/testcontainers-go/modules/valkey](https://github.com/testcontainers/testcontainers-go).


Updates `github.com/testcontainers/testcontainers-go` from 0.35.0 to 0.36.0
- [Release notes](https://github.com/testcontainers/testcontainers-go/releases)
- [Commits](https://github.com/testcontainers/testcontainers-go/compare/v0.35.0...v0.36.0)

Updates `github.com/testcontainers/testcontainers-go/modules/k3s` from 0.35.0 to 0.36.0
- [Release notes](https://github.com/testcontainers/testcontainers-go/releases)
- [Commits](https://github.com/testcontainers/testcontainers-go/compare/v0.35.0...v0.36.0)

Updates `github.com/testcontainers/testcontainers-go/modules/valkey` from 0.35.0 to 0.36.0
- [Release notes](https://github.com/testcontainers/testcontainers-go/releases)
- [Commits](https://github.com/testcontainers/testcontainers-go/compare/v0.35.0...v0.36.0)

---
updated-dependencies:
- dependency-name: github.com/testcontainers/testcontainers-go
  dependency-version: 0.36.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: testcontainers-go
- dependency-name: github.com/testcontainers/testcontainers-go/modules/k3s
  dependency-version: 0.36.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: testcontainers-go
- dependency-name: github.com/testcontainers/testcontainers-go/modules/valkey
  dependency-version: 0.36.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: testcontainers-go
...

Signed-off-by: dependabot[bot] <support@github.com>

* use dind module for docker based tests

* do not use testcontainers dind module fork

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alexis Couvreur <alexiscouvreur.pro@gmail.com>
2025-03-31 23:49:58 -04:00

68 lines
1.7 KiB
Go

package docker_test
import (
"context"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/dind"
"gotest.tools/v3/assert"
"testing"
)
type dindContainer struct {
testcontainers.Container
client *client.Client
t *testing.T
}
type MimicOptions struct {
Cmd []string
Healthcheck *container.HealthConfig
RestartPolicy container.RestartPolicy
Labels map[string]string
}
func (d *dindContainer) CreateMimic(ctx context.Context, opts MimicOptions) (container.CreateResponse, error) {
if len(opts.Cmd) == 0 {
opts.Cmd = []string{"/mimic", "-running", "-running-after=1s", "-healthy=false"}
}
d.t.Log("Creating mimic container with options", opts)
return d.client.ContainerCreate(ctx, &container.Config{
Entrypoint: opts.Cmd,
Image: "sablierapp/mimic:v0.3.1",
Labels: opts.Labels,
Healthcheck: opts.Healthcheck,
}, &container.HostConfig{RestartPolicy: opts.RestartPolicy}, nil, nil, "")
}
func setupDinD(t *testing.T) *dindContainer {
t.Helper()
ctx := t.Context()
c, err := dind.Run(ctx, "docker:28.0.4-dind")
assert.NilError(t, err)
testcontainers.CleanupContainer(t, c)
host, err := c.Host(ctx)
assert.NilError(t, err)
dindCli, err := client.NewClientWithOpts(client.WithHost(host), client.WithAPIVersionNegotiation())
assert.NilError(t, err)
provider, err := testcontainers.ProviderDocker.GetProvider()
assert.NilError(t, err)
err = provider.PullImage(ctx, "sablierapp/mimic:v0.3.1")
assert.NilError(t, err)
err = c.LoadImage(ctx, "sablierapp/mimic:v0.3.1")
assert.NilError(t, err)
return &dindContainer{
Container: c,
client: dindCli,
t: t,
}
}