Skip to content

Commit

Permalink
feat: add require for critical checks (testcontainers#2812)
Browse files Browse the repository at this point in the history
* add require for critial checks

* feat: change assert to require for critical  check

---------

Co-authored-by: Apple <apple@Apples-MacBook-Air.local>
  • Loading branch information
AshutoshKD and Apple authored Oct 5, 2024
1 parent 7c53667 commit e41374c
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions internal/core/docker_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -252,15 +252,15 @@ 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) {
ctx := context.Background()

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) {
Expand Down Expand Up @@ -289,15 +289,15 @@ 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) {
setupDockerSocketNotFound(t)

socket, err := dockerSocketPath(context.Background())
require.ErrorIs(t, err, ErrSocketNotFoundInPath)
assert.Empty(t, socket)
require.Empty(t, socket)
})
})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/core/docker_rootless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}

Expand Down
2 changes: 1 addition & 1 deletion internal/core/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion modulegen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions modulegen/mkdocs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion modules/compose/compose_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions modules/localstack/v1/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions modules/localstack/v2/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit e41374c

Please sign in to comment.