Skip to content

Commit

Permalink
Merge branch 'main' into ci/tests-enable-race
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya authored Oct 28, 2024
2 parents 82e9dd9 + 11eb809 commit 4314326
Show file tree
Hide file tree
Showing 91 changed files with 525 additions and 586 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
14 changes: 7 additions & 7 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func Test_BuildImageWithContexts(t *testing.T) {
}{
{
Name: "Dockerfile",
Contents: `FROM docker.io/alpine
Contents: `FROM alpine
CMD ["echo", "this is from the archive"]`,
},
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func Test_BuildImageWithContexts(t *testing.T) {
},
{
Name: "Dockerfile",
Contents: `FROM docker.io/alpine
Contents: `FROM alpine
WORKDIR /app
COPY . .
CMD ["sh", "./say_hi.sh"]`,
Expand Down Expand Up @@ -365,7 +365,7 @@ func Test_GetLogsFromFailedContainer(t *testing.T) {
ctx := context.Background()
// directDockerHubReference {
req := testcontainers.ContainerRequest{
Image: "docker.io/alpine",
Image: "alpine",
Cmd: []string{"echo", "-n", "I was not expecting this"},
WaitingFor: wait.ForLog("I was expecting this").WithStartupTimeout(5 * time.Second),
}
Expand All @@ -392,11 +392,11 @@ func Test_GetLogsFromFailedContainer(t *testing.T) {
type dockerImageSubstitutor struct{}

func (s dockerImageSubstitutor) Description() string {
return "DockerImageSubstitutor (prepends docker.io)"
return "DockerImageSubstitutor (prepends registry.hub.docker.com)"
}

func (s dockerImageSubstitutor) Substitute(image string) (string, error) {
return "docker.io/" + image, nil
return "registry.hub.docker.com/library/" + image, nil
}

// }
Expand Down Expand Up @@ -455,7 +455,7 @@ func TestImageSubstitutors(t *testing.T) {
name: "Prepend namespace",
image: "alpine",
substitutors: []testcontainers.ImageSubstitutor{dockerImageSubstitutor{}},
expectedImage: "docker.io/alpine",
expectedImage: "registry.hub.docker.com/library/alpine",
},
{
name: "Substitution with error",
Expand Down Expand Up @@ -554,5 +554,5 @@ func ExampleGenericContainer_withSubstitutors() {

fmt.Println(dockerContainer.Image)

// Output: docker.io/alpine:latest
// Output: registry.hub.docker.com/library/alpine:latest
}
48 changes: 16 additions & 32 deletions docker_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@ import (
"github.com/testcontainers/testcontainers-go/wait"
)

const testBashImage string = "bash:5.2.26"

func TestCopyFileToContainer(t *testing.T) {
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
defer cnl()

// 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{
Image: "docker.io/bash",
Image: testBashImage,
Files: []testcontainers.ContainerFile{
{
Reader: r,
Expand All @@ -56,17 +54,13 @@ 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{
Image: "docker.io/bash:5.2.26",
Image: testBashImage,
Files: []testcontainers.ContainerFile{
{
HostFilePath: waitForPath,
Expand Down Expand Up @@ -98,13 +92,11 @@ 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{
Image: "docker.io/bash",
Image: testBashImage,
Files: []testcontainers.ContainerFile{
{
HostFilePath: dataDirectory,
Expand All @@ -131,17 +123,13 @@ 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{
Image: "docker.io/bash",
Image: testBashImage,
Files: []testcontainers.ContainerFile{
{
HostFilePath: waitForPath,
Expand Down Expand Up @@ -173,17 +161,13 @@ 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{
Image: "docker.io/bash",
Image: testBashImage,
Files: []testcontainers.ContainerFile{
{
HostFilePath: waitForPath,
Expand Down
Loading

0 comments on commit 4314326

Please sign in to comment.