From 8eb6f0c9e4d268d8cd77fe2ba7efbceced19932f Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 3 Oct 2024 23:31:31 +0530 Subject: [PATCH 1/2] add require for critial checks --- modulegen/main_test.go | 6 +++++- modulegen/mkdocs_test.go | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modulegen/main_test.go b/modulegen/main_test.go index 322cb25920..10e4b32131 100644 --- a/modulegen/main_test.go +++ b/modulegen/main_test.go @@ -148,7 +148,11 @@ func TestModule_Validate(outer *testing.T) { for _, test := range tests { outer.Run(test.name, func(t *testing.T) { - assert.Equal(t, test.expectedErr, test.module.Validate()) + if test.expectedErr != nil { + require.EqualError(t, test.module.Validate(), test.expectedErr.Error()) + } else { + require.NoError(t, test.module.Validate()) + } }) } } diff --git a/modulegen/mkdocs_test.go b/modulegen/mkdocs_test.go index 5fcf7c93ba..a43afcc388 100644 --- a/modulegen/mkdocs_test.go +++ b/modulegen/mkdocs_test.go @@ -51,9 +51,9 @@ func TestReadMkDocsConfig(t *testing.T) { // nav bar nav := config.Nav assert.Equal(t, "index.md", nav[0].Home) - assert.NotEmpty(t, nav[2].Features) - assert.NotEmpty(t, nav[3].Modules) - assert.NotEmpty(t, nav[4].Examples) + require.NotEmpty(t, nav[2].Features) + require.NotEmpty(t, nav[3].Modules) + require.NotEmpty(t, nav[4].Examples) } func TestNavItems(t *testing.T) { From 263adaa4a496d0d06f0051f305b10276c66b55c8 Mon Sep 17 00:00:00 2001 From: Apple Date: Fri, 4 Oct 2024 02:50:51 +0530 Subject: [PATCH 2/2] feat: change assert to require for critical check --- container_test.go | 2 +- docker_test.go | 6 +++--- internal/core/docker_host_test.go | 14 +++++++------- internal/core/docker_rootless_test.go | 4 ++-- internal/core/images_test.go | 2 +- lifecycle_test.go | 2 +- modules/compose/compose_api_test.go | 2 +- modules/localstack/v1/s3_test.go | 8 ++++---- modules/localstack/v2/s3_test.go | 8 ++++---- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/container_test.go b/container_test.go index 0cca97e6f5..562eb038a4 100644 --- a/container_test.go +++ b/container_test.go @@ -320,7 +320,7 @@ func TestCustomLabelsImage(t *testing.T) { ctr, err := testcontainers.GenericContainer(ctx, req) require.NoError(t, err) - t.Cleanup(func() { assert.NoError(t, ctr.Terminate(ctx)) }) + t.Cleanup(func() { require.NoError(t, ctr.Terminate(ctx)) }) ctrJSON, err := ctr.Inspect(ctx) require.NoError(t, err) diff --git a/docker_test.go b/docker_test.go index bbbe519c28..1a6f406c85 100644 --- a/docker_test.go +++ b/docker_test.go @@ -307,7 +307,7 @@ func TestContainerStateAfterTermination(t *testing.T) { state, err := nginx.State(ctx) require.Error(t, err, "expected error from container inspect.") - assert.Nil(t, state, "expected nil container inspect.") + require.Nil(t, state, "expected nil container inspect.") }) t.Run("Nil State after termination if raw as already set", func(t *testing.T) { @@ -1339,7 +1339,7 @@ func TestContainerInspect_RawInspectIsCleanedOnStop(t *testing.T) { inspect, err := ctr.Inspect(context.Background()) require.NoError(t, err) - assert.NotEmpty(t, inspect.ID) + require.NotEmpty(t, inspect.ID) require.NoError(t, ctr.Stop(context.Background(), nil)) } @@ -1698,7 +1698,7 @@ func TestDockerContainerCopyEmptyFileFromContainer(t *testing.T) { if err != nil { t.Fatal(err) } - assert.Empty(t, fileContentFromContainer) + require.Empty(t, fileContentFromContainer) } func TestDockerContainerResources(t *testing.T) { diff --git a/internal/core/docker_host_test.go b/internal/core/docker_host_test.go index eceee573fc..5454ab5f95 100644 --- a/internal/core/docker_host_test.go +++ b/internal/core/docker_host_test.go @@ -192,7 +192,7 @@ func TestExtractDockerHost(t *testing.T) { socket, err := testcontainersHostFromProperties(context.Background()) require.ErrorIs(t, err, ErrTestcontainersHostNotSetInProperties) - assert.Empty(t, socket) + require.Empty(t, socket) }) t.Run("DOCKER_HOST is set", func(t *testing.T) { @@ -212,7 +212,7 @@ func TestExtractDockerHost(t *testing.T) { socket, err := dockerHostFromEnv(context.Background()) require.ErrorIs(t, err, ErrDockerHostNotSet) - assert.Empty(t, socket) + require.Empty(t, socket) }) t.Run("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE is set", func(t *testing.T) { @@ -236,7 +236,7 @@ func TestExtractDockerHost(t *testing.T) { socket, err := dockerSocketOverridePath() require.ErrorIs(t, err, ErrDockerSocketOverrideNotSet) - assert.Empty(t, socket) + require.Empty(t, socket) }) t.Run("Context sets the Docker socket", func(t *testing.T) { @@ -252,7 +252,7 @@ func TestExtractDockerHost(t *testing.T) { socket, err := dockerHostFromContext(context.WithValue(ctx, DockerHostContextKey, "path-to-docker-sock")) require.Error(t, err) - assert.Empty(t, socket) + require.Empty(t, socket) }) t.Run("Context sets a malformed schema for the Docker socket", func(t *testing.T) { @@ -260,7 +260,7 @@ func TestExtractDockerHost(t *testing.T) { socket, err := dockerHostFromContext(context.WithValue(ctx, DockerHostContextKey, "http://example.com/docker.sock")) require.ErrorIs(t, err, ErrNoUnixSchema) - assert.Empty(t, socket) + require.Empty(t, socket) }) t.Run("Docker socket exists", func(t *testing.T) { @@ -289,7 +289,7 @@ func TestExtractDockerHost(t *testing.T) { socket, err := dockerHostFromProperties(context.Background()) require.ErrorIs(t, err, ErrDockerSocketNotSetInProperties) - assert.Empty(t, socket) + require.Empty(t, socket) }) t.Run("Docker socket does not exist", func(t *testing.T) { @@ -297,7 +297,7 @@ func TestExtractDockerHost(t *testing.T) { socket, err := dockerSocketPath(context.Background()) require.ErrorIs(t, err, ErrSocketNotFoundInPath) - assert.Empty(t, socket) + require.Empty(t, socket) }) }) } diff --git a/internal/core/docker_rootless_test.go b/internal/core/docker_rootless_test.go index 7897f35783..687aa24707 100644 --- a/internal/core/docker_rootless_test.go +++ b/internal/core/docker_rootless_test.go @@ -70,7 +70,7 @@ func TestRootlessDockerSocketPathNotSupportedOnWindows(t *testing.T) { t.Setenv("GOOS", "windows") socketPath, err := rootlessDockerSocketPath(context.Background()) require.ErrorIs(t, err, ErrRootlessDockerNotSupportedWindows) - assert.Empty(t, socketPath) + require.Empty(t, socketPath) } func TestRootlessDockerSocketPath(t *testing.T) { @@ -179,7 +179,7 @@ func TestRootlessDockerSocketPath(t *testing.T) { socketPath, err := rootlessDockerSocketPath(context.Background()) require.ErrorIs(t, err, ErrRootlessDockerNotFoundXDGRuntimeDir) - assert.Empty(t, socketPath) + require.Empty(t, socketPath) }) } diff --git a/internal/core/images_test.go b/internal/core/images_test.go index 760a5cb857..509a117c80 100644 --- a/internal/core/images_test.go +++ b/internal/core/images_test.go @@ -67,7 +67,7 @@ func TestExtractImagesFromDockerfile(t *testing.T) { images, err := ExtractImagesFromDockerfile(tt.dockerfile, tt.buildArgs) if tt.expectedError { require.Error(t, err) - assert.Empty(t, images) + require.Empty(t, images) } else { require.NoError(t, err) assert.Equal(t, tt.expected, images) diff --git a/lifecycle_test.go b/lifecycle_test.go index 66c4ad8a8a..b1cff8dad8 100644 --- a/lifecycle_test.go +++ b/lifecycle_test.go @@ -281,7 +281,7 @@ func TestPreCreateModifierHook(t *testing.T) { // assertions - assert.Empty( + require.Empty( t, inputNetworkingConfig.EndpointsConfig[networkName].Aliases, "Networking config's aliases should be empty", diff --git a/modules/compose/compose_api_test.go b/modules/compose/compose_api_test.go index 7879dabfa9..e40129ede8 100644 --- a/modules/compose/compose_api_test.go +++ b/modules/compose/compose_api_test.go @@ -641,7 +641,7 @@ func TestDockerComposeAPIVolumesDeletedOnDown(t *testing.T) { volumeList, err := compose.dockerClient.VolumeList(ctx, volume.ListOptions{Filters: volumeListFilters}) require.NoError(t, err, "compose.dockerClient.VolumeList()") - assert.Empty(t, volumeList.Volumes, "Volumes are not cleaned up") + require.Empty(t, volumeList.Volumes, "Volumes are not cleaned up") } func TestDockerComposeAPIWithBuild(t *testing.T) { diff --git a/modules/localstack/v1/s3_test.go b/modules/localstack/v1/s3_test.go index 87eba46080..aa4dea378e 100644 --- a/modules/localstack/v1/s3_test.go +++ b/modules/localstack/v1/s3_test.go @@ -82,7 +82,7 @@ func TestS3(t *testing.T) { Bucket: aws.String(bucketName), }) require.NoError(t, err) - assert.NotNil(t, outputBucket) + require.NotNil(t, outputBucket) // put object s3Key1 := "key1" @@ -96,12 +96,12 @@ func TestS3(t *testing.T) { ContentDisposition: aws.String("attachment"), }) require.NoError(t, err) - assert.NotNil(t, outputObject) + require.NotNil(t, outputObject) t.Run("List Buckets", func(t *testing.T) { output, err := s3API.ListBuckets(nil) require.NoError(t, err) - assert.NotNil(t, output) + require.NotNil(t, output) buckets := output.Buckets assert.Len(t, buckets, 1) @@ -113,7 +113,7 @@ func TestS3(t *testing.T) { Bucket: aws.String(bucketName), }) require.NoError(t, err) - assert.NotNil(t, output) + require.NotNil(t, output) objects := output.Contents diff --git a/modules/localstack/v2/s3_test.go b/modules/localstack/v2/s3_test.go index 477549fb9c..09380a7665 100644 --- a/modules/localstack/v2/s3_test.go +++ b/modules/localstack/v2/s3_test.go @@ -88,7 +88,7 @@ func TestS3(t *testing.T) { Bucket: aws.String(bucketName), }) require.NoError(t, err) - assert.NotNil(t, outputBucket) + require.NotNil(t, outputBucket) // put object s3Key1 := "key1" @@ -102,12 +102,12 @@ func TestS3(t *testing.T) { ContentDisposition: aws.String("attachment"), }) require.NoError(t, err) - assert.NotNil(t, outputObject) + require.NotNil(t, outputObject) t.Run("List Buckets", func(t *testing.T) { output, err := s3Client.ListBuckets(ctx, &s3.ListBucketsInput{}) require.NoError(t, err) - assert.NotNil(t, output) + require.NotNil(t, output) buckets := output.Buckets assert.Len(t, buckets, 1) @@ -119,7 +119,7 @@ func TestS3(t *testing.T) { Bucket: aws.String(bucketName), }) require.NoError(t, err) - assert.NotNil(t, output) + require.NotNil(t, output) objects := output.Contents