-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support passing io.Reader as ContainerFile (#2401)
* chore: run mod tidy * feat: support passing a reader to the ContainerFile struct * chore: fix lint
- Loading branch information
1 parent
2dfbcf7
commit 462bb50
Showing
13 changed files
with
147 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// 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 ( | ||
"errors" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestContainerFileValidation(t *testing.T) { | ||
type ContainerFileValidationTestCase struct { | ||
Name string | ||
ExpectedError error | ||
File ContainerFile | ||
} | ||
|
||
f, err := os.Open(filepath.Join(".", "testdata", "hello.sh")) | ||
if err != nil { | ||
t.Fatal(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: errors.New("either HostFilePath or Reader must be specified"), | ||
File: ContainerFile{ | ||
HostFilePath: "", | ||
Reader: nil, | ||
ContainerFilePath: "/path/to/container", | ||
}, | ||
}, | ||
{ | ||
Name: "invalid container file", | ||
ExpectedError: errors.New("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() | ||
switch { | ||
case err == nil && testCase.ExpectedError == nil: | ||
return | ||
case err == nil && testCase.ExpectedError != nil: | ||
t.Errorf("did not receive expected error: %s", testCase.ExpectedError.Error()) | ||
case err != nil && testCase.ExpectedError == nil: | ||
t.Errorf("received unexpected error: %s", err.Error()) | ||
case err.Error() != testCase.ExpectedError.Error(): | ||
t.Errorf("errors mismatch: %s != %s", err.Error(), testCase.ExpectedError.Error()) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.