Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pass-through for entrypoint to ContainerRequest #209

Merged
merged 1 commit into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/docker/docker/pkg/archive"
"github.com/docker/go-connections/nat"
"github.com/pkg/errors"

"github.com/testcontainers/testcontainers-go/wait"
)

Expand Down Expand Up @@ -69,6 +70,7 @@ type FromDockerfile struct {
type ContainerRequest struct {
FromDockerfile
Image string
Entrypoint []string
Env map[string]string
ExposedPorts []string // allow specifying protocol info
Cmd []string
Expand Down
3 changes: 2 additions & 1 deletion docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
}

dockerInput := &container.Config{
Entrypoint: req.Entrypoint,
Image: tag,
Env: env,
ExposedPorts: exposedPortSet,
Expand Down Expand Up @@ -600,7 +601,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
return c, nil
}

//attemptToPullImage tries to pull the image while respecting the ctx cancellations.
// attemptToPullImage tries to pull the image while respecting the ctx cancellations.
// Besides, if the image cannot be pulled due to ErrorNotFound then no need to retry but terminate immediately.
func (p *DockerProvider) attemptToPullImage(ctx context.Context, tag string, pullOpt types.ImagePullOptions) error {
var (
Expand Down
30 changes: 30 additions & 0 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,36 @@ func TestCMD(t *testing.T) {
defer c.Terminate(ctx)
}

func TestEntrypoint(t *testing.T) {
/*
echo a unique statement to ensure that we
can pass in an entrypoint to the ContainerRequest
and it will be run when we run the container
*/

ctx := context.Background()

req := ContainerRequest{
Image: "alpine",
WaitingFor: wait.ForAll(
wait.ForLog("entrypoint override!"),
),
Entrypoint: []string{"echo", "entrypoint override!"},
}

c, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: req,
Started: true,
})

if err != nil {
t.Fatal(err)
}

// defer not needed, but keeping it in for consistency
defer c.Terminate(ctx)
}

func ExampleDockerProvider_CreateContainer() {
ctx := context.Background()
req := ContainerRequest{
Expand Down