From cc71645e576a0afb003123eb3e03d7955f342792 Mon Sep 17 00:00:00 2001 From: Joel Lau Date: Mon, 14 Oct 2024 23:56:47 +0800 Subject: [PATCH] chore: replace 'assert' with 'require' for critical checks (#2824) --- from_dockerfile_test.go | 7 +++---- modules/etcd/etcd_test.go | 2 +- modules/vault/vault_test.go | 2 +- options_test.go | 8 ++++---- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/from_dockerfile_test.go b/from_dockerfile_test.go index f6f7512ae3..854492fbfd 100644 --- a/from_dockerfile_test.go +++ b/from_dockerfile_test.go @@ -12,7 +12,6 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/image" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -38,7 +37,7 @@ func TestBuildImageFromDockerfile(t *testing.T) { // } }) require.NoError(t, err) - assert.Equal(t, "test-repo:test-tag", tag) + require.Equal(t, "test-repo:test-tag", tag) _, _, err = cli.ImageInspectWithRaw(ctx, tag) require.NoError(t, err) @@ -73,7 +72,7 @@ func TestBuildImageFromDockerfile_NoRepo(t *testing.T) { }, }) require.NoError(t, err) - assert.True(t, strings.HasPrefix(tag, "test-repo:")) + require.True(t, strings.HasPrefix(tag, "test-repo:")) _, _, err = cli.ImageInspectWithRaw(ctx, tag) require.NoError(t, err) @@ -130,7 +129,7 @@ func TestBuildImageFromDockerfile_NoTag(t *testing.T) { }, }) require.NoError(t, err) - assert.True(t, strings.HasSuffix(tag, ":test-tag")) + require.True(t, strings.HasSuffix(tag, ":test-tag")) _, _, err = cli.ImageInspectWithRaw(ctx, tag) require.NoError(t, err) diff --git a/modules/etcd/etcd_test.go b/modules/etcd/etcd_test.go index 5095ba8429..046e277cac 100644 --- a/modules/etcd/etcd_test.go +++ b/modules/etcd/etcd_test.go @@ -23,7 +23,7 @@ func TestRun(t *testing.T) { c, r, err := ctr.Exec(ctx, []string{"etcdctl", "member", "list"}, tcexec.Multiplexed()) require.NoError(t, err) - require.Equal(t, 0, c) + require.Zero(t, c) output, err := io.ReadAll(r) require.NoError(t, err) diff --git a/modules/vault/vault_test.go b/modules/vault/vault_test.go index c55f792c2c..22b87930bb 100644 --- a/modules/vault/vault_test.go +++ b/modules/vault/vault_test.go @@ -50,7 +50,7 @@ func TestVault(t *testing.T) { exec, reader, err := vaultContainer.Exec(ctx, []string{"vault", "kv", "get", "-format=json", "secret/test1"}) // } require.NoError(t, err) - assert.Equal(t, 0, exec) + require.Zero(t, exec) bytes, err := io.ReadAll(reader) require.NoError(t, err) diff --git a/options_test.go b/options_test.go index c8a67b0b06..dbbb2964d6 100644 --- a/options_test.go +++ b/options_test.go @@ -115,8 +115,8 @@ func TestWithStartupCommand(t *testing.T) { err := testcontainers.WithStartupCommand(testExec)(&req) require.NoError(t, err) - assert.Len(t, req.LifecycleHooks, 1) - assert.Len(t, req.LifecycleHooks[0].PostStarts, 1) + require.Len(t, req.LifecycleHooks, 1) + require.Len(t, req.LifecycleHooks[0].PostStarts, 1) c, err := testcontainers.GenericContainer(context.Background(), req) testcontainers.CleanupContainer(t, c) @@ -144,8 +144,8 @@ func TestWithAfterReadyCommand(t *testing.T) { err := testcontainers.WithAfterReadyCommand(testExec)(&req) require.NoError(t, err) - assert.Len(t, req.LifecycleHooks, 1) - assert.Len(t, req.LifecycleHooks[0].PostReadies, 1) + require.Len(t, req.LifecycleHooks, 1) + require.Len(t, req.LifecycleHooks[0].PostReadies, 1) c, err := testcontainers.GenericContainer(context.Background(), req) testcontainers.CleanupContainer(t, c)