Files
sablier/pkg/provider/docker/container_list_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

116 lines
2.5 KiB
Go

package docker_test
import (
"github.com/neilotoole/slogt"
"github.com/sablierapp/sablier/pkg/provider"
"github.com/sablierapp/sablier/pkg/provider/docker"
"github.com/sablierapp/sablier/pkg/sablier"
"gotest.tools/v3/assert"
"sort"
"strings"
"testing"
)
func TestDockerClassicProvider_InstanceList(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
ctx := t.Context()
dind := setupDinD(t)
p, err := docker.New(ctx, dind.client, slogt.New(t))
assert.NilError(t, err)
c1, err := dind.CreateMimic(ctx, MimicOptions{
Labels: map[string]string{
"sablier.enable": "true",
},
})
assert.NilError(t, err)
i1, err := dind.client.ContainerInspect(ctx, c1.ID)
assert.NilError(t, err)
assert.NilError(t, err)
c2, err := dind.CreateMimic(ctx, MimicOptions{
Labels: map[string]string{
"sablier.enable": "true",
"sablier.group": "my-group",
},
})
assert.NilError(t, err)
i2, err := dind.client.ContainerInspect(ctx, c2.ID)
assert.NilError(t, err)
got, err := p.InstanceList(ctx, provider.InstanceListOptions{
All: true,
})
assert.NilError(t, err)
want := []sablier.InstanceConfiguration{
{
Name: strings.TrimPrefix(i1.Name, "/"),
Group: "default",
},
{
Name: strings.TrimPrefix(i2.Name, "/"),
Group: "my-group",
},
}
// Assert go is equal to want
// Sort both array to ensure they are equal
sort.Slice(got, func(i, j int) bool {
return strings.Compare(got[i].Name, got[j].Name) < 0
})
sort.Slice(want, func(i, j int) bool {
return strings.Compare(want[i].Name, want[j].Name) < 0
})
assert.DeepEqual(t, got, want)
}
func TestDockerClassicProvider_GetGroups(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
ctx := t.Context()
dind := setupDinD(t)
p, err := docker.New(ctx, dind.client, slogt.New(t))
assert.NilError(t, err)
c1, err := dind.CreateMimic(ctx, MimicOptions{
Labels: map[string]string{
"sablier.enable": "true",
},
})
assert.NilError(t, err)
i1, err := dind.client.ContainerInspect(ctx, c1.ID)
assert.NilError(t, err)
assert.NilError(t, err)
c2, err := dind.CreateMimic(ctx, MimicOptions{
Labels: map[string]string{
"sablier.enable": "true",
"sablier.group": "my-group",
},
})
assert.NilError(t, err)
i2, err := dind.client.ContainerInspect(ctx, c2.ID)
assert.NilError(t, err)
got, err := p.InstanceGroups(ctx)
assert.NilError(t, err)
want := map[string][]string{
"default": {strings.TrimPrefix(i1.Name, "/")},
"my-group": {strings.TrimPrefix(i2.Name, "/")},
}
assert.DeepEqual(t, got, want)
}