Skip to content

Commit

Permalink
fix: replace if-condition for error handling in tests with require.No…
Browse files Browse the repository at this point in the history
…Error()/require.Error()
  • Loading branch information
vchandela committed Sep 14, 2024
1 parent 36a4e89 commit a58712d
Show file tree
Hide file tree
Showing 21 changed files with 159 additions and 439 deletions.
6 changes: 3 additions & 3 deletions container_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"path/filepath"
"testing"

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

func TestContainerFileValidation(t *testing.T) {
Expand All @@ -17,9 +19,7 @@ func TestContainerFileValidation(t *testing.T) {
}

f, err := os.Open(filepath.Join(".", "testdata", "hello.sh"))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

testTable := []ContainerFileValidationTestCase{
{
Expand Down
36 changes: 9 additions & 27 deletions docker_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ func TestCopyFileToContainer(t *testing.T) {

// copyFileOnCreate {
absPath, err := filepath.Abs(filepath.Join(".", "testdata", "hello.sh"))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

r, err := os.Open(absPath)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Expand Down Expand Up @@ -56,13 +52,9 @@ func TestCopyFileToRunningContainer(t *testing.T) {
// Not using the assertations here to avoid leaking the library into the example
// copyFileAfterCreate {
waitForPath, err := filepath.Abs(filepath.Join(".", "testdata", "waitForHello.sh"))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
helloPath, err := filepath.Abs(filepath.Join(".", "testdata", "hello.sh"))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Expand Down Expand Up @@ -98,9 +90,7 @@ func TestCopyDirectoryToContainer(t *testing.T) {
// Not using the assertations here to avoid leaking the library into the example
// copyDirectoryToContainer {
dataDirectory, err := filepath.Abs(filepath.Join(".", "testdata"))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Expand Down Expand Up @@ -131,13 +121,9 @@ func TestCopyDirectoryToRunningContainerAsFile(t *testing.T) {

// copyDirectoryToRunningContainerAsFile {
dataDirectory, err := filepath.Abs(filepath.Join(".", "testdata"))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
waitForPath, err := filepath.Abs(filepath.Join(dataDirectory, "waitForHello.sh"))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Expand Down Expand Up @@ -173,13 +159,9 @@ func TestCopyDirectoryToRunningContainerAsDir(t *testing.T) {
// Not using the assertations here to avoid leaking the library into the example
// copyDirectoryToRunningContainerAsDir {
waitForPath, err := filepath.Abs(filepath.Join(".", "testdata", "waitForHello.sh"))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
dataDirectory, err := filepath.Abs(filepath.Join(".", "testdata"))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Expand Down
Loading

0 comments on commit a58712d

Please sign in to comment.