vault/sdk/helper/testcluster/docker/environment_test.go
gkoutsou 255db7aab1
Add ENVs using NewTestDockerCluster (#27457)
* Add ENVs using NewTestDockerCluster

Currently NewTestDockerCluster had no means for setting any
environment variables. This makes it tricky to create test
for functionality that require thems, like having to set
AWS environment variables.

DockerClusterOptions now exposes an option to pass extra
enviroment variables to the containers, which are appended
to the existing ones.

* adding changelog

* added test case for setting env variables to containers

* fix changelog typo; env name

* Update changelog/27457.txt

Co-authored-by: akshya96 <87045294+akshya96@users.noreply.github.com>

* adding the missing copyright

---------

Co-authored-by: akshya96 <87045294+akshya96@users.noreply.github.com>
2024-08-16 13:18:47 -07:00

39 lines
807 B
Go

// 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
}