Skip to content

Commit

Permalink
fix: better error message in tests (#577)
Browse files Browse the repository at this point in the history
* fix: better error message in tests

* chore: remove error message checks
  • Loading branch information
mdelapenya authored Oct 22, 2022
1 parent 9bee089 commit 6b8d699
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1994,9 +1994,9 @@ func TestDockerCreateContainerWithDirs(t *testing.T) {
hostDirName := "testresources"

tests := []struct {
name string
dir ContainerFile
errMsg []string
name string
dir ContainerFile
hasError bool
}{
{
name: "success copy directory",
Expand All @@ -2005,6 +2005,7 @@ func TestDockerCreateContainerWithDirs(t *testing.T) {
ContainerFilePath: "/tmp/" + hostDirName, // the parent dir must exist
FileMode: 700,
},
hasError: false,
},
{
name: "host dir not found",
Expand All @@ -2013,11 +2014,7 @@ func TestDockerCreateContainerWithDirs(t *testing.T) {
ContainerFilePath: "/tmp/" + hostDirName, // the parent dir must exist
FileMode: 700,
},
errMsg: []string{
"can't copy ./testresources123 to container",
"open ./testresources123: no such file or directory",
"failed to create container",
},
hasError: true,
},
{
name: "container dir not found",
Expand All @@ -2026,10 +2023,7 @@ func TestDockerCreateContainerWithDirs(t *testing.T) {
ContainerFilePath: "/parent-does-not-exist/testresources123", // does not exist
FileMode: 700,
},
errMsg: []string{
"can't copy ./testresources to container",
"No such container:path",
},
hasError: true,
},
}

Expand All @@ -2045,12 +2039,8 @@ func TestDockerCreateContainerWithDirs(t *testing.T) {
Started: false,
})

if err != nil {
require.NotEmpty(t, tc.errMsg)
for _, msg := range tc.errMsg {
require.Contains(t, err.Error(), msg)
}
} else {
require.True(t, (err != nil) == tc.hasError)
if err == nil {
dir := tc.dir

assertExtractedFiles(t, ctx, nginxC, dir.HostFilePath, dir.ContainerFilePath)
Expand Down

0 comments on commit 6b8d699

Please sign in to comment.