forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_file_test.go
67 lines (61 loc) · 1.63 KB
/
container_file_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// This test is testing very internal logic that should not be exported away from this package. We'll
// leave it in the main testcontainers package. Do not use for user facing examples.
package testcontainers
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestContainerFileValidation(t *testing.T) {
type ContainerFileValidationTestCase struct {
Name string
ExpectedError string
File ContainerFile
}
f, err := os.Open(filepath.Join(".", "testdata", "hello.sh"))
require.NoError(t, err)
testTable := []ContainerFileValidationTestCase{
{
Name: "valid container file: has hostfilepath",
File: ContainerFile{
HostFilePath: "/path/to/host",
ContainerFilePath: "/path/to/container",
},
},
{
Name: "valid container file: has reader",
File: ContainerFile{
Reader: f,
ContainerFilePath: "/path/to/container",
},
},
{
Name: "invalid container file",
ExpectedError: "either HostFilePath or Reader must be specified",
File: ContainerFile{
HostFilePath: "",
Reader: nil,
ContainerFilePath: "/path/to/container",
},
},
{
Name: "invalid container file",
ExpectedError: "ContainerFilePath must be specified",
File: ContainerFile{
HostFilePath: "/path/to/host",
ContainerFilePath: "",
},
},
}
for _, testCase := range testTable {
t.Run(testCase.Name, func(t *testing.T) {
err := testCase.File.validate()
if testCase.ExpectedError != "" {
require.EqualError(t, err, testCase.ExpectedError)
} else {
require.NoError(t, err)
}
})
}
}