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 ENVs using NewTestDockerCluster #27457

Merged
merged 8 commits into from
Aug 16, 2024
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
3 changes: 3 additions & 0 deletions changelog/27457.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
sdk/helper: Allow setting environment variables when using NewTestDockerCluster
```
20 changes: 12 additions & 8 deletions sdk/helper/testcluster/docker/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,20 +805,23 @@ func (n *DockerClusterNode) Start(ctx context.Context, opts *DockerClusterOption
}
}

envs := []string{
// For now we're using disable_mlock, because this is for testing
// anyway, and because it prevents us using external plugins.
"SKIP_SETCAP=true",
"VAULT_LOG_FORMAT=json",
"VAULT_LICENSE=" + opts.VaultLicense,
}
envs = append(envs, opts.Envs...)

r, err := dockhelper.NewServiceRunner(dockhelper.RunOptions{
ImageRepo: n.ImageRepo,
ImageTag: n.ImageTag,
// We don't need to run update-ca-certificates in the container, because
// we're providing the CA in the raft join call, and otherwise Vault
// servers don't talk to one another on the API port.
Cmd: append([]string{"server"}, opts.Args...),
Env: []string{
// For now we're using disable_mlock, because this is for testing
// anyway, and because it prevents us using external plugins.
"SKIP_SETCAP=true",
"VAULT_LOG_FORMAT=json",
"VAULT_LICENSE=" + opts.VaultLicense,
},
Cmd: append([]string{"server"}, opts.Args...),
Env: envs,
Ports: ports,
ContainerName: n.Name(),
NetworkName: opts.NetworkName,
Expand Down Expand Up @@ -1089,6 +1092,7 @@ type DockerClusterOptions struct {
CA *testcluster.CA
VaultBinary string
Args []string
Envs []string
StartProbe func(*api.Client) error
Storage testcluster.ClusterStorage
DisableTLS bool
Expand Down
38 changes: 38 additions & 0 deletions sdk/helper/testcluster/docker/environment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package docker

import (
"testing"
)

func TestSettingEnvsToContainer(t *testing.T) {
expectedEnv := "TEST_ENV=value1"
expectedEnv2 := "TEST_ENV2=value2"
opts := &DockerClusterOptions{
ImageRepo: "hashicorp/vault",
ImageTag: "latest",
Envs: []string{expectedEnv, expectedEnv2},
}
cluster := NewTestDockerCluster(t, opts)
defer cluster.Cleanup()

envs := cluster.GetActiveClusterNode().Container.Config.Env

if !findEnv(envs, expectedEnv) {
t.Errorf("Missing ENV variable: %s", expectedEnv)
}
if !findEnv(envs, expectedEnv2) {
t.Errorf("Missing ENV variable: %s", expectedEnv2)
}
}

func findEnv(envs []string, env string) bool {
for _, e := range envs {
if e == env {
return true
}
}
return false
}
Loading