Skip to content

Commit

Permalink
chore: replace 'assert' with 'require' (#2827)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelLau authored Oct 16, 2024
1 parent cc71645 commit fb6a4ba
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 36 deletions.
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

0 comments on commit fb6a4ba

Please sign in to comment.