Skip to content

Commit

Permalink
internal/testing/container: Add ability to pass envs to ContainerCrea…
Browse files Browse the repository at this point in the history
…te (#1397)

Add method to optionally provide envs while creating containers.
  • Loading branch information
asuresh4 committed Oct 28, 2020
1 parent e51351a commit 92cfa83
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/common/testing/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ func (c *Containers) pullImage(image string) {
}
}

func (c *Containers) createContainer(image string) container.ContainerCreateCreatedBody {
func (c *Containers) createContainer(image string, env []string) container.ContainerCreateCreatedBody {
created, err := c.cli.ContainerCreate(context.Background(), &container.Config{
Image: image,
Labels: map[string]string{"started-by": "opentelemetry-testing"},
Env: env,
}, &container.HostConfig{
PublishAllPorts: true,
}, &network.NetworkingConfig{}, "")
Expand Down Expand Up @@ -179,8 +180,12 @@ func (c *Containers) waitForPorts(con Container) {

// StartImage starts a container with the given image and zero or more ContainerOptions.
func (c *Containers) StartImage(image string, opts ...Option) Container {
return c.StartImageWithEnv(image, nil, opts...)
}

func (c *Containers) StartImageWithEnv(image string, env []string, opts ...Option) Container {
c.pullImage(image)
created := c.createContainer(image)
created := c.createContainer(image, env)
con := c.startContainer(created)
c.runningContainers[con.ID] = con

Expand Down

0 comments on commit 92cfa83

Please sign in to comment.