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: replace 'assert' with 'require' #2827

Merged
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
3 changes: 2 additions & 1 deletion container_ignore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestParseDockerIgnore(t *testing.T) {
Expand Down Expand Up @@ -37,7 +38,7 @@ func TestParseDockerIgnore(t *testing.T) {
for _, testCase := range testCases {
exists, excluded, err := parseDockerIgnore(testCase.filePath)
assert.Equal(t, testCase.exists, exists)
assert.Equal(t, testCase.expectedErr, err)
require.ErrorIs(t, testCase.expectedErr, err)
assert.Equal(t, testCase.expectedExcluded, excluded)
}
}
3 changes: 2 additions & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -44,7 +45,7 @@ func TestReadConfig(t *testing.T) {
Host: "", // docker socket is empty at the properties file
}

assert.Equal(t, expected, config)
require.Equal(t, expected, config)

t.Setenv("TESTCONTAINERS_RYUK_DISABLED", "false")

Expand Down
2 changes: 1 addition & 1 deletion internal/core/docker_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestExtractDockerHost(t *testing.T) {

host := MustExtractDockerHost(context.Background())

assert.Equal(t, expected, host)
require.Equal(t, expected, host)

t.Setenv("DOCKER_HOST", "/path/to/another/docker.sock")

Expand Down
4 changes: 2 additions & 2 deletions modulegen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func TestGenerate(t *testing.T) {

moduleDirFileInfo, err := os.Stat(moduleDirPath)
require.NoError(t, err) // error nil implies the file exist
assert.True(t, moduleDirFileInfo.IsDir())
require.True(t, moduleDirFileInfo.IsDir())

moduleDocFile := filepath.Join(examplesDocTmp, moduleNameLower+".md")
_, err = os.Stat(moduleDocFile)
Expand Down Expand Up @@ -337,7 +337,7 @@ func TestGenerateModule(t *testing.T) {

moduleDirFileInfo, err := os.Stat(moduleDirPath)
require.NoError(t, err) // error nil implies the file exist
assert.True(t, moduleDirFileInfo.IsDir())
require.True(t, moduleDirFileInfo.IsDir())

moduleDocFile := filepath.Join(modulesDocTmp, moduleNameLower+".md")
_, err = os.Stat(moduleDocFile)
Expand Down
6 changes: 3 additions & 3 deletions modulegen/mkdocs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func TestReadMkDocsConfig(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, config)

assert.Equal(t, "Testcontainers for Go", config.SiteName)
assert.Equal(t, "https://github.com/testcontainers/testcontainers-go", config.RepoURL)
assert.Equal(t, "edit/main/docs/", config.EditURI)
require.Equal(t, "Testcontainers for Go", config.SiteName)
require.Equal(t, "https://github.com/testcontainers/testcontainers-go", config.RepoURL)
require.Equal(t, "edit/main/docs/", config.EditURI)

// theme
theme := config.Theme
Expand Down
2 changes: 1 addition & 1 deletion modules/artemis/artemis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestArtemis(t *testing.T) {
res, err := http.Get(u)
require.NoError(t, err, "failed to access console")
res.Body.Close()
assert.Equal(t, http.StatusOK, res.StatusCode, "failed to access console")
require.Equal(t, http.StatusOK, res.StatusCode, "failed to access console")

if test.user != "" {
assert.Equal(t, test.user, ctr.User(), "unexpected user")
Expand Down
42 changes: 21 additions & 21 deletions modules/compose/compose_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func TestDockerComposeAPIWithWaitLogStrategy(t *testing.T) {

serviceNames := compose.Services()

assert.Len(t, serviceNames, 2)
assert.Contains(t, serviceNames, "api-nginx")
assert.Contains(t, serviceNames, "api-mysql")
require.Len(t, serviceNames, 2)
require.Contains(t, serviceNames, "api-nginx")
require.Contains(t, serviceNames, "api-mysql")
}

func TestDockerComposeAPIWithRunServices(t *testing.T) {
Expand Down Expand Up @@ -170,9 +170,9 @@ func TestDockerComposeAPI_TestcontainersLabelsArePresent(t *testing.T) {

serviceNames := compose.Services()

assert.Len(t, serviceNames, 2)
assert.Contains(t, serviceNames, "api-nginx")
assert.Contains(t, serviceNames, "api-mysql")
require.Len(t, serviceNames, 2)
require.Contains(t, serviceNames, "api-nginx")
require.Contains(t, serviceNames, "api-mysql")

// all the services in the compose has the Testcontainers Labels
for _, serviceName := range serviceNames {
Expand Down Expand Up @@ -213,9 +213,9 @@ func TestDockerComposeAPI_WithReaper(t *testing.T) {

serviceNames := compose.Services()

assert.Len(t, serviceNames, 2)
assert.Contains(t, serviceNames, "api-nginx")
assert.Contains(t, serviceNames, "api-mysql")
require.Len(t, serviceNames, 2)
require.Contains(t, serviceNames, "api-nginx")
require.Contains(t, serviceNames, "api-mysql")
}

func TestDockerComposeAPI_WithoutReaper(t *testing.T) {
Expand All @@ -240,9 +240,9 @@ func TestDockerComposeAPI_WithoutReaper(t *testing.T) {

serviceNames := compose.Services()

assert.Len(t, serviceNames, 2)
assert.Contains(t, serviceNames, "api-nginx")
assert.Contains(t, serviceNames, "api-mysql")
require.Len(t, serviceNames, 2)
require.Contains(t, serviceNames, "api-nginx")
require.Contains(t, serviceNames, "api-mysql")
}

func TestDockerComposeAPIWithStopServices(t *testing.T) {
Expand All @@ -261,9 +261,9 @@ func TestDockerComposeAPIWithStopServices(t *testing.T) {

serviceNames := compose.Services()

assert.Len(t, serviceNames, 2)
assert.Contains(t, serviceNames, "api-nginx")
assert.Contains(t, serviceNames, "api-mysql")
require.Len(t, serviceNames, 2)
require.Contains(t, serviceNames, "api-nginx")
require.Contains(t, serviceNames, "api-mysql")

// close mysql container in purpose
mysqlContainer, err := compose.ServiceContainer(context.Background(), "api-mysql")
Expand Down Expand Up @@ -386,9 +386,9 @@ func TestDockerComposeAPIWithMultipleWaitStrategies(t *testing.T) {

serviceNames := compose.Services()

assert.Len(t, serviceNames, 2)
assert.Contains(t, serviceNames, "api-nginx")
assert.Contains(t, serviceNames, "api-mysql")
require.Len(t, serviceNames, 2)
require.Contains(t, serviceNames, "api-nginx")
require.Contains(t, serviceNames, "api-mysql")
}

func TestDockerComposeAPIWithFailedStrategy(t *testing.T) {
Expand Down Expand Up @@ -430,9 +430,9 @@ func TestDockerComposeAPIComplex(t *testing.T) {

serviceNames := compose.Services()

assert.Len(t, serviceNames, 2)
assert.Contains(t, serviceNames, "api-nginx")
assert.Contains(t, serviceNames, "api-mysql")
require.Len(t, serviceNames, 2)
require.Contains(t, serviceNames, "api-nginx")
require.Contains(t, serviceNames, "api-mysql")
}

func TestDockerComposeAPIWithStackReader(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions modules/redpanda/redpanda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestRedpanda(t *testing.T) {
kafkaAdmCl := kadm.NewClient(kafkaCl)
metadata, err := kafkaAdmCl.Metadata(ctx)
require.NoError(t, err)
assert.Len(t, metadata.Brokers, 1)
require.Len(t, metadata.Brokers, 1)

// Test Schema Registry API
httpCl := &http.Client{Timeout: 5 * time.Second}
Expand All @@ -55,7 +55,7 @@ func TestRedpanda(t *testing.T) {
resp, err := httpCl.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
require.Equal(t, http.StatusOK, resp.StatusCode)

// Test Admin API
// adminAPIAddress {
Expand All @@ -67,7 +67,7 @@ func TestRedpanda(t *testing.T) {
resp, err = httpCl.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
require.Equal(t, http.StatusOK, resp.StatusCode)

// Test produce to unknown topic
results := kafkaCl.ProduceSync(ctx, &kgo.Record{Topic: "test", Value: []byte("test message")})
Expand Down Expand Up @@ -289,7 +289,7 @@ func TestRedpandaWithOldVersionAndWasm(t *testing.T) {
require.NoError(t, err)
resp, err := httpCl.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusUnauthorized, resp.StatusCode)
require.Equal(t, http.StatusUnauthorized, resp.StatusCode)
resp.Body.Close()

// Successful authentication
Expand Down Expand Up @@ -357,7 +357,7 @@ func TestRedpandaWithTLS(t *testing.T) {
require.NoError(t, err)
resp, err := httpCl.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
require.Equal(t, http.StatusOK, resp.StatusCode)
resp.Body.Close()

// Test Schema Registry API
Expand All @@ -368,7 +368,7 @@ func TestRedpandaWithTLS(t *testing.T) {
require.NoError(t, err)
resp, err = httpCl.Do(req)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
require.Equal(t, http.StatusOK, resp.StatusCode)
resp.Body.Close()

brokers, err := ctr.KafkaSeedBroker(ctx)
Expand Down