Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump testcontainers-go to its latest release #614

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
32 changes: 16 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ require (
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d
github.com/sebest/xff v0.0.0-20210106013422-671bd2870b3a
github.com/sirupsen/logrus v1.9.3
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/image v0.18.0
golang.org/x/net v0.25.0
golang.org/x/net v0.26.0
)

require (
github.com/didip/tollbooth/v7 v7.0.1
github.com/docker/docker v27.1.1+incompatible
github.com/docker/go-connections v0.5.0
github.com/go-redsync/redsync/v4 v4.12.1
github.com/julienschmidt/httprouter v1.3.0
Expand All @@ -59,29 +60,30 @@ require (
github.com/t2bot/go-typed-singleflight v0.0.3
github.com/t2bot/gotd-contrib v0.0.0-20230907202504-d21987ea2957
github.com/t2bot/pgo-fleet/embedded v1.0.1
github.com/testcontainers/testcontainers-go v0.26.0
github.com/testcontainers/testcontainers-go/modules/postgres v0.26.0
github.com/testcontainers/testcontainers-go v0.33.0
github.com/testcontainers/testcontainers-go/modules/minio v0.33.0
github.com/testcontainers/testcontainers-go/modules/postgres v0.33.0
github.com/testcontainers/testcontainers-go/modules/redis v0.33.0
golang.org/x/sync v0.7.0
golang.org/x/term v0.20.0
golang.org/x/term v0.21.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Jeffail/gabs v1.4.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.12.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/containerd v1.7.14 // indirect
github.com/containerd/containerd v1.7.18 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349 // indirect
github.com/fatih/color v1.16.0 // indirect
Expand Down Expand Up @@ -112,6 +114,7 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mewkiz/flac v1.0.10 // indirect
github.com/mewkiz/pkg v0.0.0-20231012081350-95d6616c5403 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
Expand All @@ -137,12 +140,9 @@ require (
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Expand All @@ -166,7 +166,7 @@ require (
github.com/peterbourgon/g2s v0.0.0-20170223122336-d4e7ad98afea // indirect
github.com/tebeka/strftime v0.1.3 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/grpc v1.64.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1
)
82 changes: 45 additions & 37 deletions go.sum

Large diffs are not rendered by default.

47 changes: 26 additions & 21 deletions test/test_internals/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"
"log"
"os"
"path"
"path/filepath"
"strings"
"time"

Expand All @@ -17,13 +17,15 @@ import (
"github.com/t2bot/matrix-media-repo/homeserver_interop/synapse"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/postgres"
"github.com/testcontainers/testcontainers-go/modules/redis"
tcnetwork "github.com/testcontainers/testcontainers-go/network"
"github.com/testcontainers/testcontainers-go/wait"
)

type ContainerDeps struct {
ctx context.Context
pgContainer *postgres.PostgresContainer
redisContainer testcontainers.Container
redisContainer *redis.RedisContainer
minioDep *MinioDep
depNet *NetworkDep
mmrExtConfigPath string
Expand All @@ -37,11 +39,17 @@ func MakeTestDeps() (*ContainerDeps, error) {
ctx := context.Background()

// Create a network
depNet, err := MakeNetwork()
nw, err := tcnetwork.New(ctx)
if err != nil {
return nil, err
}

depNet := &NetworkDep{
ctx: ctx,
dockerNet: nw,
NetId: nw.ID,
}

// Create a shared signing key for the MMR instances
signingKeyFile, err := os.CreateTemp(os.TempDir(), "mmr-signing-key")
if err != nil {
Expand Down Expand Up @@ -97,12 +105,12 @@ func MakeTestDeps() (*ContainerDeps, error) {
}

// Start postgresql database
pgContainer, err := postgres.RunContainer(ctx,
testcontainers.WithImage("docker.io/library/postgres:14"),
pgContainer, err := postgres.Run(ctx,
"docker.io/library/postgres:14",
postgres.WithDatabase("mmr"),
postgres.WithUsername("postgres"),
postgres.WithPassword("test1234"),
depNet.ApplyToContainer(),
tcnetwork.WithNetwork([]string{"postgres"}, depNet.dockerNet),
testcontainers.WithWaitStrategy(
wait.ForLog("database system is ready to accept connections").WithOccurrence(2).WithStartupTimeout(5*time.Second)),
)
Expand All @@ -120,24 +128,21 @@ func MakeTestDeps() (*ContainerDeps, error) {
return nil, err
}

// Start a redis container
cwd, err := os.Getwd()
wd, err := os.Getwd()
if err != nil {
return nil, err
}
redisContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "docker.io/library/redis:7",
ExposedPorts: []string{"6379/tcp"},
Mounts: []testcontainers.ContainerMount{
testcontainers.BindMount(path.Join(cwd, ".", "dev", "redis.conf"), "/usr/local/etc/redis/redis.conf"),
},
Cmd: []string{"redis-server", "/usr/local/etc/redis/redis.conf"},
Networks: []string{depNet.NetId},
WaitingFor: wait.ForListeningPort("6379/tcp"),
},
Started: true,
})

redisConf, err := filepath.Abs(filepath.Join(wd, "..", "dev", "redis.conf"))
if err != nil {
return nil, err
}

// Start a redis container
redisContainer, err := redis.Run(ctx, "docker.io/library/redis:7",
redis.WithConfigFile(redisConf),
tcnetwork.WithNetwork([]string{"redis"}, depNet.dockerNet),
)
if err != nil {
return nil, err
}
Expand Down
80 changes: 0 additions & 80 deletions test/test_internals/deps_docker_context.go

This file was deleted.

39 changes: 20 additions & 19 deletions test/test_internals/deps_minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"fmt"
"log"
"os"
"path"
"path/filepath"
"strings"
"text/template"
"time"

"github.com/docker/go-connections/nat"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/minio"
tcnetwork "github.com/testcontainers/testcontainers-go/network"
"github.com/testcontainers/testcontainers-go/wait"
)

Expand All @@ -21,35 +22,35 @@ type minioTmplArgs struct {

type MinioDep struct {
ctx context.Context
container testcontainers.Container
container *minio.MinioContainer

Endpoint string
ExternalEndpoint string
}

// MakeMinio creates a new Minio instance for testing
// This function should be called from the `test` package,
// as it contains file paths relative to that package.
func MakeMinio(depNet *NetworkDep) (*MinioDep, error) {
ctx := context.Background()

// Start the minio container
consolePort, _ := nat.NewPort("tcp", "9090")
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "quay.io/minio/minio:latest",
ExposedPorts: []string{"9000/tcp", "9090/tcp"},
Env: map[string]string{
"MINIO_ROOT_USER": "admin",
"MINIO_ROOT_PASSWORD": "test1234",
container, err := minio.Run(ctx,
"quay.io/minio/minio:latest",
minio.WithPassword("test1234"),
minio.WithUsername("admin"),
tcnetwork.WithNetwork([]string{"minio"}, depNet.dockerNet),
testcontainers.CustomizeRequest(testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
ExposedPorts: []string{"9090/tcp"},
Cmd: []string{"--console-address", ":9090"},
},
WaitingFor: wait.ForHTTP("/login").WithPort(consolePort),
Networks: []string{depNet.NetId},
Cmd: []string{"server", "/data", "--console-address", ":9090"},
// we don't bind any volumes because we don't care if we lose the data
},
Started: true,
})
}),
)
if err != nil {
return nil, err
}

if _, _, err = container.Exec(ctx, []string{"mkdir", "-p", "/data"}); err != nil {
return nil, err
}
Expand All @@ -69,7 +70,7 @@ func MakeMinio(depNet *NetworkDep) (*MinioDep, error) {
}

// Prepare the test script
t, err := template.New("minio-config.sh").ParseFiles(path.Join(".", "test", "templates", "minio-config.sh"))
t, err := template.New("minio-config.sh").ParseFiles(filepath.Join("templates", "minio-config.sh"))
if err != nil {
return nil, err
}
Expand Down
Loading