diff --git a/modulegen/_template/examples_test.go.tmpl b/modulegen/_template/examples_test.go.tmpl index 8e47e5cd0a..127d69ba16 100644 --- a/modulegen/_template/examples_test.go.tmpl +++ b/modulegen/_template/examples_test.go.tmpl @@ -3,6 +3,7 @@ import ( "context" "fmt" + "log" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/{{ ParentDir }}/{{ $lower }}" diff --git a/modulegen/_template/module_test.go.tmpl b/modulegen/_template/module_test.go.tmpl index 1057d3d447..9a0f5391d5 100644 --- a/modulegen/_template/module_test.go.tmpl +++ b/modulegen/_template/module_test.go.tmpl @@ -1,16 +1,17 @@ -{{ $entrypoint := Entrypoint }}{{ $image := Image }}{{ $lower := ToLower }}{{ $title := Title }}package {{ $lower }} +{{ $entrypoint := Entrypoint }}{{ $image := Image }}{{ $lower := ToLower }}{{ $title := Title }}package {{ $lower }}_test import ( "context" "testing" "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/{{ ParentDir }}/{{ $lower }}" ) func Test{{ $title }}(t *testing.T) { ctx := context.Background() - container, err := {{ $entrypoint }}(ctx, testcontainers.WithImage("{{ $image }}")) + container, err := {{ $lower }}.{{ $entrypoint }}(ctx, testcontainers.WithImage("{{ $image }}")) if err != nil { t.Fatal(err) } diff --git a/modulegen/main_test.go b/modulegen/main_test.go index f861a8d3ac..772a18c952 100644 --- a/modulegen/main_test.go +++ b/modulegen/main_test.go @@ -430,15 +430,15 @@ func assertExamplesTestContent(t *testing.T, module context.TestcontainersModule title := module.Title() data := sanitiseContent(content) - assert.Equal(t, data[0], "package "+lower+"_test") - assert.Equal(t, "\t\"github.com/testcontainers/testcontainers-go\"", data[6]) - assert.Equal(t, data[7], "\t\"github.com/testcontainers/testcontainers-go/modules/"+lower+"\"") - assert.Equal(t, data[10], "func Example"+entrypoint+"() {") - assert.Equal(t, data[11], "\t// run"+title+"Container {") - assert.Equal(t, data[14], "\t"+lower+"Container, err := "+lower+"."+entrypoint+"(ctx, testcontainers.WithImage(\""+module.Image+"\"))") - assert.Equal(t, "\tfmt.Println(state.Running)", data[32]) - assert.Equal(t, "\t// Output:", data[34]) - assert.Equal(t, "\t// true", data[35]) + assert.Equal(t, "package "+lower+"_test", data[0]) + assert.Equal(t, "\t\"github.com/testcontainers/testcontainers-go\"", data[7]) + assert.Equal(t, "\t\"github.com/testcontainers/testcontainers-go/modules/"+lower+"\"", data[8]) + assert.Equal(t, "func Example"+entrypoint+"() {", data[11]) + assert.Equal(t, "\t// run"+title+"Container {", data[12]) + assert.Equal(t, "\t"+lower+"Container, err := "+lower+"."+entrypoint+"(ctx, testcontainers.WithImage(\""+module.Image+"\"))", data[15]) + assert.Equal(t, "\tfmt.Println(state.Running)", data[33]) + assert.Equal(t, "\t// Output:", data[35]) + assert.Equal(t, "\t// true", data[36]) } // assert content module test @@ -447,9 +447,9 @@ func assertModuleTestContent(t *testing.T, module context.TestcontainersModule, require.NoError(t, err) data := sanitiseContent(content) - assert.Equal(t, data[0], "package "+module.Lower()) - assert.Equal(t, data[9], "func Test"+module.Title()+"(t *testing.T) {") - assert.Equal(t, data[12], "\tcontainer, err := "+module.Entrypoint()+"(ctx, testcontainers.WithImage(\""+module.Image+"\"))") + assert.Equal(t, "package "+module.Lower()+"_test", data[0]) + assert.Equal(t, "func Test"+module.Title()+"(t *testing.T) {", data[10]) + assert.Equal(t, "\tcontainer, err := "+module.Lower()+"."+module.Entrypoint()+"(ctx, testcontainers.WithImage(\""+module.Image+"\"))", data[13]) } // assert content module diff --git a/modules/cassandra/cassandra_test.go b/modules/cassandra/cassandra_test.go index 11e47ccb55..831ce01d32 100644 --- a/modules/cassandra/cassandra_test.go +++ b/modules/cassandra/cassandra_test.go @@ -1,4 +1,4 @@ -package cassandra +package cassandra_test import ( "context" @@ -8,6 +8,8 @@ import ( "github.com/gocql/gocql" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/testcontainers/testcontainers-go/modules/cassandra" ) type Test struct { @@ -18,7 +20,7 @@ type Test struct { func TestCassandra(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx) + container, err := cassandra.RunContainer(ctx) if err != nil { t.Fatal(err) } @@ -58,7 +60,7 @@ func TestCassandra(t *testing.T) { func TestCassandraWithConfigFile(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, WithConfigFile(filepath.Join("testdata", "config.yaml"))) + container, err := cassandra.RunContainer(ctx, cassandra.WithConfigFile(filepath.Join("testdata", "config.yaml"))) if err != nil { t.Fatal(err) } @@ -89,7 +91,7 @@ func TestCassandraWithInitScripts(t *testing.T) { ctx := context.Background() // withInitScripts { - container, err := RunContainer(ctx, WithInitScripts(filepath.Join("testdata", "init.cql"))) + container, err := cassandra.RunContainer(ctx, cassandra.WithInitScripts(filepath.Join("testdata", "init.cql"))) // } if err != nil { t.Fatal(err) @@ -121,7 +123,7 @@ func TestCassandraWithInitScripts(t *testing.T) { t.Run("with init bash script", func(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, WithInitScripts(filepath.Join("testdata", "init.sh"))) + container, err := cassandra.RunContainer(ctx, cassandra.WithInitScripts(filepath.Join("testdata", "init.sh"))) if err != nil { t.Fatal(err) } diff --git a/modules/clickhouse/clickhouse.go b/modules/clickhouse/clickhouse.go index 86ebac1704..b133d98752 100644 --- a/modules/clickhouse/clickhouse.go +++ b/modules/clickhouse/clickhouse.go @@ -36,9 +36,9 @@ const ( // ClickHouseContainer represents the ClickHouse container type used in the module type ClickHouseContainer struct { testcontainers.Container - dbName string - user string - password string + DbName string + User string + Password string } // ConnectionHost returns the host and port of the clickhouse container, using the default, native 9000 port, and @@ -75,7 +75,7 @@ func (c *ClickHouseContainer) ConnectionString(ctx context.Context, args ...stri extraArgs = "?" + extraArgs } - connectionString := fmt.Sprintf("clickhouse://%s:%s@%s/%s%s", c.user, c.password, host, c.dbName, extraArgs) + connectionString := fmt.Sprintf("clickhouse://%s:%s@%s/%s%s", c.User, c.Password, host, c.DbName, extraArgs) return connectionString, nil } @@ -237,5 +237,5 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize password := req.Env["CLICKHOUSE_PASSWORD"] dbName := req.Env["CLICKHOUSE_DB"] - return &ClickHouseContainer{Container: container, dbName: dbName, password: password, user: user}, nil + return &ClickHouseContainer{Container: container, DbName: dbName, Password: password, User: user}, nil } diff --git a/modules/clickhouse/clickhouse_test.go b/modules/clickhouse/clickhouse_test.go index 075bbf4460..970106a471 100644 --- a/modules/clickhouse/clickhouse_test.go +++ b/modules/clickhouse/clickhouse_test.go @@ -1,4 +1,4 @@ -package clickhouse +package clickhouse_test import ( "context" @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/modules/clickhouse" "github.com/testcontainers/testcontainers-go/wait" ) @@ -29,7 +30,7 @@ type Test struct { func TestClickHouseDefaultConfig(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx) + container, err := clickhouse.RunContainer(ctx) if err != nil { t.Fatal(err) } @@ -45,9 +46,9 @@ func TestClickHouseDefaultConfig(t *testing.T) { conn, err := ch.Open(&ch.Options{ Addr: []string{connectionHost}, Auth: ch.Auth{ - Database: container.dbName, - Username: container.user, - Password: container.password, + Database: container.DbName, + Username: container.User, + Password: container.Password, }, }) require.NoError(t, err) @@ -61,10 +62,10 @@ func TestClickHouseDefaultConfig(t *testing.T) { func TestClickHouseConnectionHost(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, - WithUsername(user), - WithPassword(password), - WithDatabase(dbname), + container, err := clickhouse.RunContainer(ctx, + clickhouse.WithUsername(user), + clickhouse.WithPassword(password), + clickhouse.WithDatabase(dbname), ) if err != nil { t.Fatal(err) @@ -101,7 +102,7 @@ func TestClickHouseConnectionHost(t *testing.T) { func TestClickHouseDSN(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, WithUsername(user), WithPassword(password), WithDatabase(dbname)) + container, err := clickhouse.RunContainer(ctx, clickhouse.WithUsername(user), clickhouse.WithPassword(password), clickhouse.WithDatabase(dbname)) if err != nil { t.Fatal(err) } @@ -134,11 +135,11 @@ func TestClickHouseWithInitScripts(t *testing.T) { ctx := context.Background() // withInitScripts { - container, err := RunContainer(ctx, - WithUsername(user), - WithPassword(password), - WithDatabase(dbname), - WithInitScripts(filepath.Join("testdata", "init-db.sh")), + container, err := clickhouse.RunContainer(ctx, + clickhouse.WithUsername(user), + clickhouse.WithPassword(password), + clickhouse.WithDatabase(dbname), + clickhouse.WithInitScripts(filepath.Join("testdata", "init-db.sh")), ) if err != nil { t.Fatal(err) @@ -178,15 +179,15 @@ func TestClickHouseWithConfigFile(t *testing.T) { desc string configOption testcontainers.CustomizeRequestOption }{ - {"XML_Config", WithConfigFile(filepath.Join("testdata", "config.xml"))}, // 1 - {"YAML_Config", WithYamlConfigFile(filepath.Join("testdata", "config.yaml"))}, // allow_no_password: true + {"XML_Config", clickhouse.WithConfigFile(filepath.Join("testdata", "config.xml"))}, // 1 + {"YAML_Config", clickhouse.WithYamlConfigFile(filepath.Join("testdata", "config.yaml"))}, // allow_no_password: true } for _, tC := range testCases { t.Run(tC.desc, func(t *testing.T) { - container, err := RunContainer(ctx, - WithUsername(user), - WithPassword(""), - WithDatabase(dbname), + container, err := clickhouse.RunContainer(ctx, + clickhouse.WithUsername(user), + clickhouse.WithPassword(""), + clickhouse.WithDatabase(dbname), tC.configOption, ) if err != nil { @@ -244,11 +245,11 @@ func TestClickHouseWithZookeeper(t *testing.T) { t.Fatal(err) } - container, err := RunContainer(ctx, - WithUsername(user), - WithPassword(password), - WithDatabase(dbname), - WithZookeeper(ipaddr, zkPort.Port()), + container, err := clickhouse.RunContainer(ctx, + clickhouse.WithUsername(user), + clickhouse.WithPassword(password), + clickhouse.WithDatabase(dbname), + clickhouse.WithZookeeper(ipaddr, zkPort.Port()), ) if err != nil { t.Fatal(err) diff --git a/modules/k6/k6_test.go b/modules/k6/k6_test.go index 02e8433c70..f90b24ab29 100644 --- a/modules/k6/k6_test.go +++ b/modules/k6/k6_test.go @@ -1,9 +1,11 @@ -package k6 +package k6_test import ( "context" "path/filepath" "testing" + + "github.com/testcontainers/testcontainers-go/modules/k6" ) func TestK6(t *testing.T) { @@ -34,7 +36,7 @@ func TestK6(t *testing.T) { t.Fatal(err) } - container, err := RunContainer(ctx, WithCache(), WithTestScript(absPath)) + container, err := k6.RunContainer(ctx, k6.WithCache(), k6.WithTestScript(absPath)) if err != nil { t.Fatal(err) } diff --git a/modules/kafka/consumer_test.go b/modules/kafka/consumer_test.go index 20d32a5232..d7305540f8 100644 --- a/modules/kafka/consumer_test.go +++ b/modules/kafka/consumer_test.go @@ -1,4 +1,4 @@ -package kafka +package kafka_test import ( "testing" diff --git a/modules/kafka/kafka_helpers_test.go b/modules/kafka/kafka_helpers_test.go new file mode 100644 index 0000000000..4a49a00f50 --- /dev/null +++ b/modules/kafka/kafka_helpers_test.go @@ -0,0 +1,111 @@ +package kafka + +import ( + "testing" + + "github.com/testcontainers/testcontainers-go" +) + +func TestConfigureQuorumVoters(t *testing.T) { + tests := []struct { + name string + req *testcontainers.GenericContainerRequest + expectedVoters string + }{ + { + name: "voters on localhost", + req: &testcontainers.GenericContainerRequest{ + ContainerRequest: testcontainers.ContainerRequest{ + Env: map[string]string{}, + }, + }, + expectedVoters: "1@localhost:9094", + }, + { + name: "voters on first network alias of the first network", + req: &testcontainers.GenericContainerRequest{ + ContainerRequest: testcontainers.ContainerRequest{ + Env: map[string]string{}, + Networks: []string{"foo", "bar", "baaz"}, + NetworkAliases: map[string][]string{ + "foo": {"foo0", "foo1", "foo2", "foo3"}, + "bar": {"bar0", "bar1", "bar2", "bar3"}, + "baaz": {"baaz0", "baaz1", "baaz2", "baaz3"}, + }, + }, + }, + expectedVoters: "1@foo0:9094", + }, + { + name: "voters on localhost if alias but no networks", + req: &testcontainers.GenericContainerRequest{ + ContainerRequest: testcontainers.ContainerRequest{ + NetworkAliases: map[string][]string{ + "foo": {"foo0", "foo1", "foo2", "foo3"}, + "bar": {"bar0", "bar1", "bar2", "bar3"}, + "baaz": {"baaz0", "baaz1", "baaz2", "baaz3"}, + }, + }, + }, + expectedVoters: "1@localhost:9094", + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + configureControllerQuorumVoters(test.req) + + if test.req.Env["KAFKA_CONTROLLER_QUORUM_VOTERS"] != test.expectedVoters { + t.Fatalf("expected KAFKA_CONTROLLER_QUORUM_VOTERS to be %s, got %s", test.expectedVoters, test.req.Env["KAFKA_CONTROLLER_QUORUM_VOTERS"]) + } + }) + } +} + +func TestValidateKRaftVersion(t *testing.T) { + tests := []struct { + name string + image string + wantErr bool + }{ + { + name: "Official: valid version", + image: "confluentinc/confluent-local:7.5.0", + wantErr: false, + }, + { + name: "Official: valid, limit version", + image: "confluentinc/confluent-local:7.4.0", + wantErr: false, + }, + { + name: "Official: invalid, low version", + image: "confluentinc/confluent-local:7.3.99", + wantErr: true, + }, + { + name: "Official: invalid, too low version", + image: "confluentinc/confluent-local:5.0.0", + wantErr: true, + }, + { + name: "Unofficial does not validate KRaft version", + image: "my-kafka:1.0.0", + wantErr: false, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + err := validateKRaftVersion(test.image) + + if test.wantErr && err == nil { + t.Fatalf("expected error, got nil") + } + + if !test.wantErr && err != nil { + t.Fatalf("expected no error, got %s", err) + } + }) + } +} diff --git a/modules/kafka/kafka_test.go b/modules/kafka/kafka_test.go index 821ca66fef..662bb5d0a8 100644 --- a/modules/kafka/kafka_test.go +++ b/modules/kafka/kafka_test.go @@ -1,4 +1,4 @@ -package kafka +package kafka_test import ( "context" @@ -8,6 +8,7 @@ import ( "github.com/IBM/sarama" "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/modules/kafka" ) func TestKafka(t *testing.T) { @@ -15,7 +16,7 @@ func TestKafka(t *testing.T) { ctx := context.Background() - kafkaContainer, err := RunContainer(ctx, WithClusterID("kraftCluster"), testcontainers.WithImage("confluentinc/confluent-local:7.5.0")) + kafkaContainer, err := kafka.RunContainer(ctx, kafka.WithClusterID("kraftCluster"), testcontainers.WithImage("confluentinc/confluent-local:7.5.0")) if err != nil { t.Fatal(err) } @@ -87,112 +88,8 @@ func TestKafka(t *testing.T) { func TestKafka_invalidVersion(t *testing.T) { ctx := context.Background() - _, err := RunContainer(ctx, WithClusterID("kraftCluster"), testcontainers.WithImage("confluentinc/confluent-local:6.3.3")) + _, err := kafka.RunContainer(ctx, kafka.WithClusterID("kraftCluster"), testcontainers.WithImage("confluentinc/confluent-local:6.3.3")) if err == nil { t.Fatal(err) } } - -func TestConfigureQuorumVoters(t *testing.T) { - tests := []struct { - name string - req *testcontainers.GenericContainerRequest - expectedVoters string - }{ - { - name: "voters on localhost", - req: &testcontainers.GenericContainerRequest{ - ContainerRequest: testcontainers.ContainerRequest{ - Env: map[string]string{}, - }, - }, - expectedVoters: "1@localhost:9094", - }, - { - name: "voters on first network alias of the first network", - req: &testcontainers.GenericContainerRequest{ - ContainerRequest: testcontainers.ContainerRequest{ - Env: map[string]string{}, - Networks: []string{"foo", "bar", "baaz"}, - NetworkAliases: map[string][]string{ - "foo": {"foo0", "foo1", "foo2", "foo3"}, - "bar": {"bar0", "bar1", "bar2", "bar3"}, - "baaz": {"baaz0", "baaz1", "baaz2", "baaz3"}, - }, - }, - }, - expectedVoters: "1@foo0:9094", - }, - { - name: "voters on localhost if alias but no networks", - req: &testcontainers.GenericContainerRequest{ - ContainerRequest: testcontainers.ContainerRequest{ - NetworkAliases: map[string][]string{ - "foo": {"foo0", "foo1", "foo2", "foo3"}, - "bar": {"bar0", "bar1", "bar2", "bar3"}, - "baaz": {"baaz0", "baaz1", "baaz2", "baaz3"}, - }, - }, - }, - expectedVoters: "1@localhost:9094", - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - configureControllerQuorumVoters(test.req) - - if test.req.Env["KAFKA_CONTROLLER_QUORUM_VOTERS"] != test.expectedVoters { - t.Fatalf("expected KAFKA_CONTROLLER_QUORUM_VOTERS to be %s, got %s", test.expectedVoters, test.req.Env["KAFKA_CONTROLLER_QUORUM_VOTERS"]) - } - }) - } -} - -func TestValidateKRaftVersion(t *testing.T) { - tests := []struct { - name string - image string - wantErr bool - }{ - { - name: "Official: valid version", - image: "confluentinc/confluent-local:7.5.0", - wantErr: false, - }, - { - name: "Official: valid, limit version", - image: "confluentinc/confluent-local:7.4.0", - wantErr: false, - }, - { - name: "Official: invalid, low version", - image: "confluentinc/confluent-local:7.3.99", - wantErr: true, - }, - { - name: "Official: invalid, too low version", - image: "confluentinc/confluent-local:5.0.0", - wantErr: true, - }, - { - name: "Unofficial does not validate KRaft version", - image: "my-kafka:1.0.0", - wantErr: false, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - err := validateKRaftVersion(test.image) - - if test.wantErr && err == nil { - t.Fatalf("expected error, got nil") - } - - if !test.wantErr && err != nil { - t.Fatalf("expected no error, got %s", err) - } - }) - } -} diff --git a/modules/mariadb/mariadb_test.go b/modules/mariadb/mariadb_test.go index 6ec9bc0070..e7399bdb09 100644 --- a/modules/mariadb/mariadb_test.go +++ b/modules/mariadb/mariadb_test.go @@ -1,4 +1,4 @@ -package mariadb +package mariadb_test import ( "context" @@ -10,12 +10,13 @@ import ( _ "github.com/go-sql-driver/mysql" "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/modules/mariadb" ) func TestMariaDB(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx) + container, err := mariadb.RunContainer(ctx) if err != nil { t.Fatal(err) } @@ -57,10 +58,10 @@ func TestMariaDB(t *testing.T) { func TestMariaDBWithNonRootUserAndEmptyPassword(t *testing.T) { ctx := context.Background() - _, err := RunContainer(ctx, - WithDatabase("foo"), - WithUsername("test"), - WithPassword("")) + _, err := mariadb.RunContainer(ctx, + mariadb.WithDatabase("foo"), + mariadb.WithUsername("test"), + mariadb.WithPassword("")) if err.Error() != "empty password can be used only with the root user" { t.Fatal(err) } @@ -69,10 +70,10 @@ func TestMariaDBWithNonRootUserAndEmptyPassword(t *testing.T) { func TestMariaDBWithRootUserAndEmptyPassword(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, - WithDatabase("foo"), - WithUsername("root"), - WithPassword("")) + container, err := mariadb.RunContainer(ctx, + mariadb.WithDatabase("foo"), + mariadb.WithUsername("root"), + mariadb.WithPassword("")) if err != nil { t.Fatal(err) } @@ -111,8 +112,8 @@ func TestMariaDBWithRootUserAndEmptyPassword(t *testing.T) { func TestMariaDBWithMySQLEnvVars(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, testcontainers.WithImage("mariadb:10.3.29"), - WithScripts(filepath.Join("testdata", "schema.sql"))) + container, err := mariadb.RunContainer(ctx, testcontainers.WithImage("mariadb:10.3.29"), + mariadb.WithScripts(filepath.Join("testdata", "schema.sql"))) if err != nil { t.Fatal(err) } @@ -129,8 +130,8 @@ func TestMariaDBWithMySQLEnvVars(t *testing.T) { func TestMariaDBWithConfigFile(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, testcontainers.WithImage("mariadb:11.0.3"), - WithConfigFile(filepath.Join("testdata", "my.cnf"))) + container, err := mariadb.RunContainer(ctx, testcontainers.WithImage("mariadb:11.0.3"), + mariadb.WithConfigFile(filepath.Join("testdata", "my.cnf"))) if err != nil { t.Fatal(err) } @@ -180,8 +181,8 @@ func TestMariaDBWithConfigFile(t *testing.T) { func TestMariaDBWithScripts(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, - WithScripts(filepath.Join("testdata", "schema.sql"))) + container, err := mariadb.RunContainer(ctx, + mariadb.WithScripts(filepath.Join("testdata", "schema.sql"))) if err != nil { t.Fatal(err) } @@ -196,7 +197,7 @@ func TestMariaDBWithScripts(t *testing.T) { assertDataCanBeFetched(t, ctx, container) } -func assertDataCanBeFetched(t *testing.T, ctx context.Context, container *MariaDBContainer) { +func assertDataCanBeFetched(t *testing.T, ctx context.Context, container *mariadb.MariaDBContainer) { connectionString, err := container.ConnectionString(ctx) if err != nil { t.Fatal(err) diff --git a/modules/minio/minio_test.go b/modules/minio/minio_test.go index 36a7fd11b6..0cb5a7fc2e 100644 --- a/modules/minio/minio_test.go +++ b/modules/minio/minio_test.go @@ -1,4 +1,4 @@ -package minio +package minio_test import ( "context" @@ -10,14 +10,15 @@ import ( "github.com/minio/minio-go/v7/pkg/credentials" "github.com/testcontainers/testcontainers-go" + tcminio "github.com/testcontainers/testcontainers-go/modules/minio" ) func TestMinio(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, + container, err := tcminio.RunContainer(ctx, testcontainers.WithImage("minio/minio:RELEASE.2024-01-16T16-07-38Z"), - WithUsername("thisismyuser"), WithPassword("thisismypassword")) + tcminio.WithUsername("thisismyuser"), tcminio.WithPassword("thisismypassword")) if err != nil { t.Fatal(err) } diff --git a/modules/mockserver/coverage.out b/modules/mockserver/coverage.out deleted file mode 100644 index 5f02b11199..0000000000 --- a/modules/mockserver/coverage.out +++ /dev/null @@ -1 +0,0 @@ -mode: set diff --git a/modules/mssql/mssql_test.go b/modules/mssql/mssql_test.go index 8d8aa9c48c..b691935eaa 100644 --- a/modules/mssql/mssql_test.go +++ b/modules/mssql/mssql_test.go @@ -1,4 +1,4 @@ -package mssql +package mssql_test import ( "context" @@ -8,14 +8,15 @@ import ( _ "github.com/microsoft/go-mssqldb" "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/modules/mssql" "github.com/testcontainers/testcontainers-go/wait" ) func TestMSSQLServer(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, - WithAcceptEULA(), + container, err := mssql.RunContainer(ctx, + mssql.WithAcceptEULA(), ) if err != nil { t.Fatal(err) @@ -57,22 +58,27 @@ func TestMSSQLServer(t *testing.T) { func TestMSSQLServerWithMissingEulaOption(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx) - testcontainers.WithWaitStrategy( - wait.ForLog("The SQL Server End-User License Agreement (EULA) must be accepted")) - - if container == nil && err != nil { - t.Log("Success: Confirmed proper handling of missing EULA, so container is nil.") - } else { + container, err := mssql.RunContainer(ctx, testcontainers.WithWaitStrategy( + wait.ForLog("The SQL Server End-User License Agreement (EULA) must be accepted"))) + if err != nil { t.Fatalf("Expected a log to confirm missing EULA but got error: %s", err) } + + state, err := container.State(ctx) + if err != nil { + t.Fatalf("failed to get container state: %s", err) + } + + if !state.Running { + t.Log("Success: Confirmed proper handling of missing EULA, so container is not running.") + } } func TestMSSQLServerWithConnectionStringParameters(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, - WithAcceptEULA(), + container, err := mssql.RunContainer(ctx, + mssql.WithAcceptEULA(), ) if err != nil { t.Fatal(err) @@ -114,9 +120,9 @@ func TestMSSQLServerWithConnectionStringParameters(t *testing.T) { func TestMSSQLServerWithCustomStrongPassword(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, - WithAcceptEULA(), - WithPassword("Strong@Passw0rd"), + container, err := mssql.RunContainer(ctx, + mssql.WithAcceptEULA(), + mssql.WithPassword("Strong@Passw0rd"), ) if err != nil { t.Fatal(err) @@ -150,11 +156,11 @@ func TestMSSQLServerWithCustomStrongPassword(t *testing.T) { func TestMSSQLServerWithInvalidPassword(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, + container, err := mssql.RunContainer(ctx, testcontainers.WithWaitStrategy( wait.ForLog("Password validation failed")), - WithAcceptEULA(), - WithPassword("weakPassword"), + mssql.WithAcceptEULA(), + mssql.WithPassword("weakPassword"), ) if err == nil { @@ -174,9 +180,9 @@ func TestMSSQLServerWithInvalidPassword(t *testing.T) { func TestMSSQLServerWithAlternativeImage(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, + container, err := mssql.RunContainer(ctx, testcontainers.WithImage("mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04"), - WithAcceptEULA(), + mssql.WithAcceptEULA(), ) if err != nil { t.Fatalf("Failed to create the container with alternative image: %s", err) diff --git a/modules/nats/nats_test.go b/modules/nats/nats_test.go index 5d05432ac7..c5aa12a86a 100644 --- a/modules/nats/nats_test.go +++ b/modules/nats/nats_test.go @@ -1,17 +1,19 @@ -package nats +package nats_test import ( "context" "testing" "github.com/nats-io/nats.go" + + tcnats "github.com/testcontainers/testcontainers-go/modules/nats" ) func TestNATS(t *testing.T) { ctx := context.Background() // createNATSContainer { - container, err := RunContainer(ctx) + container, err := tcnats.RunContainer(ctx) // } if err != nil { t.Fatal(err) diff --git a/modules/openldap/openldap_test.go b/modules/openldap/openldap_test.go index d11d89b7ed..9407a5716a 100644 --- a/modules/openldap/openldap_test.go +++ b/modules/openldap/openldap_test.go @@ -1,4 +1,4 @@ -package openldap +package openldap_test import ( "context" @@ -8,12 +8,13 @@ import ( "github.com/go-ldap/ldap/v3" "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/modules/openldap" ) func TestOpenLDAP(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6")) + container, err := openldap.RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6")) if err != nil { t.Fatal(err) } @@ -29,7 +30,11 @@ func TestOpenLDAP(t *testing.T) { func TestOpenLDAPWithAdminUsernameAndPassword(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6"), WithAdminUsername("openldap"), WithAdminPassword("openldap")) + container, err := openldap.RunContainer(ctx, + testcontainers.WithImage("bitnami/openldap:2.6.6"), + openldap.WithAdminUsername("openldap"), + openldap.WithAdminPassword("openldap"), + ) if err != nil { t.Fatal(err) } @@ -62,7 +67,7 @@ func TestOpenLDAPWithAdminUsernameAndPassword(t *testing.T) { func TestOpenLDAPWithDifferentRoot(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6"), WithRoot("dc=mydomain,dc=com")) + container, err := openldap.RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6"), openldap.WithRoot("dc=mydomain,dc=com")) if err != nil { t.Fatal(err) } @@ -97,7 +102,7 @@ func TestOpenLDAPWithDifferentRoot(t *testing.T) { func TestOpenLDAPLoadLdif(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6")) + container, err := openldap.RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6")) if err != nil { t.Fatal(err) } @@ -188,7 +193,7 @@ userPassword: Password1 t.Fatal(err) } - container, err := RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6"), WithInitialLdif(f.Name())) + container, err := openldap.RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6"), openldap.WithInitialLdif(f.Name())) if err != nil { t.Fatal(err) } diff --git a/modules/redis/options_test.go b/modules/redis/options_test.go new file mode 100644 index 0000000000..7150af6df2 --- /dev/null +++ b/modules/redis/options_test.go @@ -0,0 +1,138 @@ +package redis + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/testcontainers/testcontainers-go" +) + +func TestWithConfigFile(t *testing.T) { + tests := []struct { + name string + cmds []string + expectedCmds []string + }{ + { + name: "no existing command", + cmds: []string{}, + expectedCmds: []string{redisServerProcess, "/usr/local/redis.conf"}, + }, + { + name: "existing redis-server command as first argument", + cmds: []string{redisServerProcess, "a", "b", "c"}, + expectedCmds: []string{redisServerProcess, "/usr/local/redis.conf", "a", "b", "c"}, + }, + { + name: "non existing redis-server command", + cmds: []string{"a", "b", "c"}, + expectedCmds: []string{redisServerProcess, "/usr/local/redis.conf", "a", "b", "c"}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + req := &testcontainers.GenericContainerRequest{ + ContainerRequest: testcontainers.ContainerRequest{ + Cmd: tt.cmds, + }, + } + + WithConfigFile("redis.conf")(req) + + require.Equal(t, tt.expectedCmds, req.Cmd) + }) + } +} + +func TestWithLogLevel(t *testing.T) { + tests := []struct { + name string + cmds []string + expectedCmds []string + }{ + { + name: "no existing command", + cmds: []string{}, + expectedCmds: []string{redisServerProcess, "--loglevel", "debug"}, + }, + { + name: "existing redis-server command as first argument", + cmds: []string{redisServerProcess, "a", "b", "c"}, + expectedCmds: []string{redisServerProcess, "a", "b", "c", "--loglevel", "debug"}, + }, + { + name: "non existing redis-server command", + cmds: []string{"a", "b", "c"}, + expectedCmds: []string{redisServerProcess, "a", "b", "c", "--loglevel", "debug"}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + req := &testcontainers.GenericContainerRequest{ + ContainerRequest: testcontainers.ContainerRequest{ + Cmd: tt.cmds, + }, + } + + WithLogLevel(LogLevelDebug)(req) + + require.Equal(t, tt.expectedCmds, req.Cmd) + }) + } +} + +func TestWithSnapshotting(t *testing.T) { + tests := []struct { + name string + cmds []string + expectedCmds []string + seconds int + changedKeys int + }{ + { + name: "no existing command", + cmds: []string{}, + seconds: 60, + changedKeys: 100, + expectedCmds: []string{redisServerProcess, "--save", "60", "100"}, + }, + { + name: "existing redis-server command as first argument", + cmds: []string{redisServerProcess, "a", "b", "c"}, + seconds: 60, + changedKeys: 100, + expectedCmds: []string{redisServerProcess, "a", "b", "c", "--save", "60", "100"}, + }, + { + name: "non existing redis-server command", + cmds: []string{"a", "b", "c"}, + seconds: 60, + changedKeys: 100, + expectedCmds: []string{redisServerProcess, "a", "b", "c", "--save", "60", "100"}, + }, + { + name: "existing redis-server command as first argument", + cmds: []string{redisServerProcess, "a", "b", "c"}, + seconds: 0, + changedKeys: 0, + expectedCmds: []string{redisServerProcess, "a", "b", "c", "--save", "1", "1"}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + req := &testcontainers.GenericContainerRequest{ + ContainerRequest: testcontainers.ContainerRequest{ + Cmd: tt.cmds, + }, + } + + WithSnapshotting(tt.seconds, tt.changedKeys)(req) + + require.Equal(t, tt.expectedCmds, req.Cmd) + }) + } +} diff --git a/modules/redis/redis_test.go b/modules/redis/redis_test.go index 86d123dd8e..e66e6e37d5 100644 --- a/modules/redis/redis_test.go +++ b/modules/redis/redis_test.go @@ -1,4 +1,4 @@ -package redis +package redis_test import ( "context" @@ -12,12 +12,13 @@ import ( "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" + tcredis "github.com/testcontainers/testcontainers-go/modules/redis" ) func TestIntegrationSetGet(t *testing.T) { ctx := context.Background() - redisContainer, err := RunContainer(ctx) + redisContainer, err := tcredis.RunContainer(ctx) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -31,7 +32,7 @@ func TestIntegrationSetGet(t *testing.T) { func TestRedisWithConfigFile(t *testing.T) { ctx := context.Background() - redisContainer, err := RunContainer(ctx, WithConfigFile(filepath.Join("testdata", "redis7.conf"))) + redisContainer, err := tcredis.RunContainer(ctx, tcredis.WithConfigFile(filepath.Join("testdata", "redis7.conf"))) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -73,7 +74,7 @@ func TestRedisWithImage(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - redisContainer, err := RunContainer(ctx, testcontainers.WithImage(tt.image), WithConfigFile(filepath.Join("testdata", "redis6.conf"))) + redisContainer, err := tcredis.RunContainer(ctx, testcontainers.WithImage(tt.image), tcredis.WithConfigFile(filepath.Join("testdata", "redis6.conf"))) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -89,7 +90,7 @@ func TestRedisWithImage(t *testing.T) { func TestRedisWithLogLevel(t *testing.T) { ctx := context.Background() - redisContainer, err := RunContainer(ctx, WithLogLevel(LogLevelVerbose)) + redisContainer, err := tcredis.RunContainer(ctx, tcredis.WithLogLevel(tcredis.LogLevelVerbose)) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -103,7 +104,7 @@ func TestRedisWithLogLevel(t *testing.T) { func TestRedisWithSnapshotting(t *testing.T) { ctx := context.Background() - redisContainer, err := RunContainer(ctx, WithSnapshotting(10, 1)) + redisContainer, err := tcredis.RunContainer(ctx, tcredis.WithSnapshotting(10, 1)) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -114,7 +115,7 @@ func TestRedisWithSnapshotting(t *testing.T) { assertSetsGets(t, ctx, redisContainer, 10) } -func assertSetsGets(t *testing.T, ctx context.Context, redisContainer *RedisContainer, keyCount int) { +func assertSetsGets(t *testing.T, ctx context.Context, redisContainer *tcredis.RedisContainer, keyCount int) { // connectionString { uri, err := redisContainer.ConnectionString(ctx) // } @@ -163,132 +164,3 @@ func assertSetsGets(t *testing.T, ctx context.Context, redisContainer *RedisCont func flushRedis(ctx context.Context, client redis.Client) error { return client.FlushAll(ctx).Err() } - -func TestWithConfigFile(t *testing.T) { - tests := []struct { - name string - cmds []string - expectedCmds []string - }{ - { - name: "no existing command", - cmds: []string{}, - expectedCmds: []string{redisServerProcess, "/usr/local/redis.conf"}, - }, - { - name: "existing redis-server command as first argument", - cmds: []string{redisServerProcess, "a", "b", "c"}, - expectedCmds: []string{redisServerProcess, "/usr/local/redis.conf", "a", "b", "c"}, - }, - { - name: "non existing redis-server command", - cmds: []string{"a", "b", "c"}, - expectedCmds: []string{redisServerProcess, "/usr/local/redis.conf", "a", "b", "c"}, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - req := &testcontainers.GenericContainerRequest{ - ContainerRequest: testcontainers.ContainerRequest{ - Cmd: tt.cmds, - }, - } - - WithConfigFile("redis.conf")(req) - - require.Equal(t, tt.expectedCmds, req.Cmd) - }) - } -} - -func TestWithLogLevel(t *testing.T) { - tests := []struct { - name string - cmds []string - expectedCmds []string - }{ - { - name: "no existing command", - cmds: []string{}, - expectedCmds: []string{redisServerProcess, "--loglevel", "debug"}, - }, - { - name: "existing redis-server command as first argument", - cmds: []string{redisServerProcess, "a", "b", "c"}, - expectedCmds: []string{redisServerProcess, "a", "b", "c", "--loglevel", "debug"}, - }, - { - name: "non existing redis-server command", - cmds: []string{"a", "b", "c"}, - expectedCmds: []string{redisServerProcess, "a", "b", "c", "--loglevel", "debug"}, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - req := &testcontainers.GenericContainerRequest{ - ContainerRequest: testcontainers.ContainerRequest{ - Cmd: tt.cmds, - }, - } - - WithLogLevel(LogLevelDebug)(req) - - require.Equal(t, tt.expectedCmds, req.Cmd) - }) - } -} - -func TestWithSnapshotting(t *testing.T) { - tests := []struct { - name string - cmds []string - expectedCmds []string - seconds int - changedKeys int - }{ - { - name: "no existing command", - cmds: []string{}, - seconds: 60, - changedKeys: 100, - expectedCmds: []string{redisServerProcess, "--save", "60", "100"}, - }, - { - name: "existing redis-server command as first argument", - cmds: []string{redisServerProcess, "a", "b", "c"}, - seconds: 60, - changedKeys: 100, - expectedCmds: []string{redisServerProcess, "a", "b", "c", "--save", "60", "100"}, - }, - { - name: "non existing redis-server command", - cmds: []string{"a", "b", "c"}, - seconds: 60, - changedKeys: 100, - expectedCmds: []string{redisServerProcess, "a", "b", "c", "--save", "60", "100"}, - }, - { - name: "existing redis-server command as first argument", - cmds: []string{redisServerProcess, "a", "b", "c"}, - seconds: 0, - changedKeys: 0, - expectedCmds: []string{redisServerProcess, "a", "b", "c", "--save", "1", "1"}, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - req := &testcontainers.GenericContainerRequest{ - ContainerRequest: testcontainers.ContainerRequest{ - Cmd: tt.cmds, - }, - } - - WithSnapshotting(tt.seconds, tt.changedKeys)(req) - - require.Equal(t, tt.expectedCmds, req.Cmd) - }) - } -} diff --git a/modules/redpanda/redpanda_helpers_test.go b/modules/redpanda/redpanda_helpers_test.go new file mode 100644 index 0000000000..36503bdf11 --- /dev/null +++ b/modules/redpanda/redpanda_helpers_test.go @@ -0,0 +1,56 @@ +package redpanda + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_isAtLeastVersion(t *testing.T) { + type args struct { + image string + major string + } + tests := []struct { + name string + args args + want bool + }{ + { + name: "v21.5.6", + args: args{ + image: "redpandadata/redpanda:v21.5.6", + major: "23.3", + }, + want: false, + }, + { + name: "v23.3.3", + args: args{ + image: "redpandadata/redpanda:v23.3.3", + major: "23.3", + }, + want: true, + }, + { + name: "v23.3.3-rc1", + args: args{ + image: "redpandadata/redpanda:v23.3.3-rc1", + major: "23.3", + }, + want: true, + }, + { + name: "v21.3.3-rc1", + args: args{ + image: "redpandadata/redpanda:v21.3.3-rc1", + major: "23.3", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equalf(t, tt.want, isAtLeastVersion(tt.args.image, tt.args.major), "isAtLeastVersion(%v, %v)", tt.args.image, tt.args.major) + }) + } +} diff --git a/modules/redpanda/redpanda_test.go b/modules/redpanda/redpanda_test.go index aeea2f7f63..cdb264bd56 100644 --- a/modules/redpanda/redpanda_test.go +++ b/modules/redpanda/redpanda_test.go @@ -1,4 +1,4 @@ -package redpanda +package redpanda_test import ( "context" @@ -20,13 +20,14 @@ import ( "github.com/twmb/franz-go/pkg/sasl/scram" "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/modules/redpanda" "github.com/testcontainers/testcontainers-go/network" ) func TestRedpanda(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx) + container, err := redpanda.RunContainer(ctx) require.NoError(t, err) // Clean up the container after the test is complete @@ -82,15 +83,15 @@ func TestRedpanda(t *testing.T) { func TestRedpandaWithAuthentication(t *testing.T) { ctx := context.Background() // redpandaCreateContainer { - container, err := RunContainer(ctx, - WithEnableSASL(), - WithEnableKafkaAuthorization(), - WithEnableWasmTransform(), - WithNewServiceAccount("superuser-1", "test"), - WithNewServiceAccount("superuser-2", "test"), - WithNewServiceAccount("no-superuser", "test"), - WithSuperusers("superuser-1", "superuser-2"), - WithEnableSchemaRegistryHTTPBasicAuth(), + container, err := redpanda.RunContainer(ctx, + redpanda.WithEnableSASL(), + redpanda.WithEnableKafkaAuthorization(), + redpanda.WithEnableWasmTransform(), + redpanda.WithNewServiceAccount("superuser-1", "test"), + redpanda.WithNewServiceAccount("superuser-2", "test"), + redpanda.WithNewServiceAccount("no-superuser", "test"), + redpanda.WithSuperusers("superuser-1", "superuser-2"), + redpanda.WithEnableSchemaRegistryHTTPBasicAuth(), ) require.NoError(t, err) // } @@ -193,16 +194,16 @@ func TestRedpandaWithOldVersionAndWasm(t *testing.T) { ctx := context.Background() // redpandaCreateContainer { // this would fail to start if we weren't ignoring wasm transforms for older versions - container, err := RunContainer(ctx, + container, err := redpanda.RunContainer(ctx, testcontainers.WithImage("redpandadata/redpanda:v23.2.18"), - WithEnableSASL(), - WithEnableKafkaAuthorization(), - WithEnableWasmTransform(), - WithNewServiceAccount("superuser-1", "test"), - WithNewServiceAccount("superuser-2", "test"), - WithNewServiceAccount("no-superuser", "test"), - WithSuperusers("superuser-1", "superuser-2"), - WithEnableSchemaRegistryHTTPBasicAuth(), + redpanda.WithEnableSASL(), + redpanda.WithEnableKafkaAuthorization(), + redpanda.WithEnableWasmTransform(), + redpanda.WithNewServiceAccount("superuser-1", "test"), + redpanda.WithNewServiceAccount("superuser-2", "test"), + redpanda.WithNewServiceAccount("no-superuser", "test"), + redpanda.WithSuperusers("superuser-1", "superuser-2"), + redpanda.WithEnableSchemaRegistryHTTPBasicAuth(), ) require.NoError(t, err) // } @@ -321,7 +322,7 @@ func TestRedpandaWithOldVersionAndWasm(t *testing.T) { func TestRedpandaProduceWithAutoCreateTopics(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, WithAutoCreateTopics()) + container, err := redpanda.RunContainer(ctx, redpanda.WithAutoCreateTopics()) require.NoError(t, err) t.Cleanup(func() { @@ -350,7 +351,7 @@ func TestRedpandaWithTLS(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, WithTLS(localhostCert, localhostKey)) + container, err := redpanda.RunContainer(ctx, redpanda.WithTLS(localhostCert, localhostKey)) require.NoError(t, err) t.Cleanup(func() { @@ -419,12 +420,12 @@ func TestRedpandaWithTLSAndSASL(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, - WithTLS(localhostCert, localhostKey), - WithEnableSASL(), - WithEnableKafkaAuthorization(), - WithNewServiceAccount("superuser-1", "test"), - WithSuperusers("superuser-1"), + container, err := redpanda.RunContainer(ctx, + redpanda.WithTLS(localhostCert, localhostKey), + redpanda.WithEnableSASL(), + redpanda.WithEnableKafkaAuthorization(), + redpanda.WithNewServiceAccount("superuser-1", "test"), + redpanda.WithSuperusers("superuser-1"), ) require.NoError(t, err) @@ -469,10 +470,10 @@ func TestRedpandaListener_Simple(t *testing.T) { // 2. Start Redpanda container // withListenerRP { - container, err := RunContainer(ctx, + container, err := redpanda.RunContainer(ctx, testcontainers.WithImage("redpandadata/redpanda:v23.2.18"), network.WithNetwork([]string{"redpanda-host"}, rpNetwork), - WithListener("redpanda:29092"), WithAutoCreateTopics(), + redpanda.WithListener("redpanda:29092"), redpanda.WithAutoCreateTopics(), ) // } require.NoError(t, err) @@ -542,9 +543,9 @@ func TestRedpandaListener_InvalidPort(t *testing.T) { require.NoError(t, err) // 2. Attempt Start Redpanda container - _, err = RunContainer(ctx, + _, err = redpanda.RunContainer(ctx, testcontainers.WithImage("redpandadata/redpanda:v23.2.18"), - WithListener("redpanda:99092"), + redpanda.WithListener("redpanda:99092"), network.WithNetwork([]string{"redpanda-host"}, RPNetwork), ) @@ -563,9 +564,9 @@ func TestRedpandaListener_NoNetwork(t *testing.T) { ctx := context.Background() // 1. Attempt Start Redpanda container - _, err := RunContainer(ctx, + _, err := redpanda.RunContainer(ctx, testcontainers.WithImage("redpandadata/redpanda:v23.2.18"), - WithListener("redpanda:99092"), + redpanda.WithListener("redpanda:99092"), ) require.Error(t, err) @@ -628,52 +629,3 @@ D4ZNvyXf/6E27Ibu6v2p/vs= -----END TESTING KEY-----`)) func testingKey(s string) string { return strings.ReplaceAll(s, "TESTING KEY", "PRIVATE KEY") } - -func Test_isAtLeastVersion(t *testing.T) { - type args struct { - image string - major string - } - tests := []struct { - name string - args args - want bool - }{ - { - name: "v21.5.6", - args: args{ - image: "redpandadata/redpanda:v21.5.6", - major: "23.3", - }, - want: false, - }, - { - name: "v23.3.3", - args: args{ - image: "redpandadata/redpanda:v23.3.3", - major: "23.3", - }, - want: true, - }, - { - name: "v23.3.3-rc1", - args: args{ - image: "redpandadata/redpanda:v23.3.3-rc1", - major: "23.3", - }, - want: true, - }, - { - name: "v21.3.3-rc1", - args: args{ - image: "redpandadata/redpanda:v21.3.3-rc1", - major: "23.3", - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - assert.Equalf(t, tt.want, isAtLeastVersion(tt.args.image, tt.args.major), "isAtLeastVersion(%v, %v)", tt.args.image, tt.args.major) - }) - } -}