forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* main: feat (postgres): support for creating and restoring Snapshots (testcontainers#2199) fix: apply volume options only to volumes (testcontainers#2201) redpanda/test: add admin client call (testcontainers#2200) chore(deps): bump cloud.google.com/go/spanner from 1.55.0 to 1.56.0 in /modules/gcloud, cloud.google.com/go/pubsub from 1.35.0 to 1.36.1 in /modules/gcloud, cloud.google.com/go/bigquery from 1.57.1 to 1.58.0 in /modules/gcloud (testcontainers#2197) chore(deps): bump github.com/docker/docker from 25.0.1+incompatible to 25.0.2+incompatible (testcontainers#2196) fix: go doc reference broken image (testcontainers#2195) Add Support for WASM Transforms to Redpanda Module (testcontainers#2170)
- Loading branch information
Showing
82 changed files
with
899 additions
and
227 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,213 @@ | ||
package testcontainers | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/testcontainers/testcontainers-go/wait" | ||
) | ||
|
||
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) | ||
} | ||
|
||
container, err := GenericContainer(ctx, GenericContainerRequest{ | ||
ContainerRequest: ContainerRequest{ | ||
Image: "docker.io/bash", | ||
Files: []ContainerFile{ | ||
{ | ||
HostFilePath: absPath, | ||
ContainerFilePath: "/hello.sh", | ||
FileMode: 0o700, | ||
}, | ||
}, | ||
Cmd: []string{"bash", "/hello.sh"}, | ||
WaitingFor: wait.ForLog("done"), | ||
}, | ||
Started: true, | ||
}) | ||
// } | ||
|
||
require.NoError(t, err) | ||
require.NoError(t, container.Terminate(ctx)) | ||
} | ||
|
||
func TestCopyFileToRunningContainer(t *testing.T) { | ||
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer cnl() | ||
|
||
// 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) | ||
} | ||
helloPath, err := filepath.Abs(filepath.Join(".", "testdata", "hello.sh")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
container, err := GenericContainer(ctx, GenericContainerRequest{ | ||
ContainerRequest: ContainerRequest{ | ||
Image: "docker.io/bash:5.2.26", | ||
Files: []ContainerFile{ | ||
{ | ||
HostFilePath: waitForPath, | ||
ContainerFilePath: "/waitForHello.sh", | ||
FileMode: 0o700, | ||
}, | ||
}, | ||
Cmd: []string{"bash", "/waitForHello.sh"}, | ||
}, | ||
Started: true, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = container.CopyFileToContainer(ctx, helloPath, "/scripts/hello.sh", 0o700) | ||
// } | ||
|
||
require.NoError(t, err) | ||
|
||
// Give some time to the wait script to catch the hello script being created | ||
err = wait.ForLog("done").WithStartupTimeout(200*time.Millisecond).WaitUntilReady(ctx, container) | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, container.Terminate(ctx)) | ||
} | ||
|
||
func TestCopyDirectoryToContainer(t *testing.T) { | ||
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer cnl() | ||
|
||
// 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) | ||
} | ||
|
||
container, err := GenericContainer(ctx, GenericContainerRequest{ | ||
ContainerRequest: ContainerRequest{ | ||
Image: "docker.io/bash", | ||
Files: []ContainerFile{ | ||
{ | ||
HostFilePath: dataDirectory, | ||
// ContainerFile cannot create the parent directory, so we copy the scripts | ||
// to the root of the container instead. Make sure to create the container directory | ||
// before you copy a host directory on create. | ||
ContainerFilePath: "/", | ||
FileMode: 0o700, | ||
}, | ||
}, | ||
Cmd: []string{"bash", "/testdata/hello.sh"}, | ||
WaitingFor: wait.ForLog("done"), | ||
}, | ||
Started: true, | ||
}) | ||
// } | ||
|
||
require.NoError(t, err) | ||
require.NoError(t, container.Terminate(ctx)) | ||
} | ||
|
||
func TestCopyDirectoryToRunningContainerAsFile(t *testing.T) { | ||
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer cnl() | ||
|
||
// copyDirectoryToRunningContainerAsFile { | ||
dataDirectory, err := filepath.Abs(filepath.Join(".", "testdata")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
waitForPath, err := filepath.Abs(filepath.Join(dataDirectory, "waitForHello.sh")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
container, err := GenericContainer(ctx, GenericContainerRequest{ | ||
ContainerRequest: ContainerRequest{ | ||
Image: "docker.io/bash", | ||
Files: []ContainerFile{ | ||
{ | ||
HostFilePath: waitForPath, | ||
ContainerFilePath: "/waitForHello.sh", | ||
FileMode: 0o700, | ||
}, | ||
}, | ||
Cmd: []string{"bash", "/waitForHello.sh"}, | ||
}, | ||
Started: true, | ||
}) | ||
require.NoError(t, err) | ||
|
||
// as the container is started, we can create the directory first | ||
_, _, err = container.Exec(ctx, []string{"mkdir", "-p", "/scripts"}) | ||
require.NoError(t, err) | ||
|
||
// because the container path is a directory, it will use the copy dir method as fallback | ||
err = container.CopyFileToContainer(ctx, dataDirectory, "/scripts", 0o700) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
// } | ||
|
||
require.NoError(t, err) | ||
require.NoError(t, container.Terminate(ctx)) | ||
} | ||
|
||
func TestCopyDirectoryToRunningContainerAsDir(t *testing.T) { | ||
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer cnl() | ||
|
||
// 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) | ||
} | ||
dataDirectory, err := filepath.Abs(filepath.Join(".", "testdata")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
container, err := GenericContainer(ctx, GenericContainerRequest{ | ||
ContainerRequest: ContainerRequest{ | ||
Image: "docker.io/bash", | ||
Files: []ContainerFile{ | ||
{ | ||
HostFilePath: waitForPath, | ||
ContainerFilePath: "/waitForHello.sh", | ||
FileMode: 0o700, | ||
}, | ||
}, | ||
Cmd: []string{"bash", "/waitForHello.sh"}, | ||
}, | ||
Started: true, | ||
}) | ||
require.NoError(t, err) | ||
|
||
// as the container is started, we can create the directory first | ||
_, _, err = container.Exec(ctx, []string{"mkdir", "-p", "/scripts"}) | ||
require.NoError(t, err) | ||
|
||
err = container.CopyDirToContainer(ctx, dataDirectory, "/scripts", 0o700) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
// } | ||
|
||
require.NoError(t, err) | ||
require.NoError(t, container.Terminate(ctx)) | ||
} |
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.