-
Notifications
You must be signed in to change notification settings - Fork 2
/
env_test.go
33 lines (28 loc) · 1011 Bytes
/
env_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestEnvMap(t *testing.T) {
t.Setenv("DOCKER_CONSUL_BOOTSTRAP_TEST_FOO", "ignore")
t.Setenv("DOCKER_CONSUL_BOOTSTRAP_TEST_BAR", "ignored")
e := NewEnvMap()
e.Merge(map[string]string{
"DOCKER_CONSUL_BOOTSTRAP_TEST_FOO": "changed",
"DOCKER_CONSUL_BOOTSTRAP_TEST_TEST": "testing",
"DOCKER_CONSUL_BOOTSTRAP_TEST_BAZ": "foo",
})
e.Merge(map[string]string{
"DOCKER_CONSUL_BOOTSTRAP_TEST_BAZ": "bar",
})
e.Add("DOCKER_CONSUL_BOOTSTRAP_TEST_BAR", "testing")
e.Add("DOCKER_CONSUL_BOOTSTRAP_EXPAND_ONE", "foo-${DOCKER_CONSUL_BOOTSTRAP_TEST_FOO}-bar")
e.Add("DOCKER_CONSUL_BOOTSTRAP_EXPAND_TWO", "foo-${DOCKER_CONSUL_BOOTSTRAP_TEST_BAZ}-baz")
e.Add(" ", "test-empty")
assert.ElementsMatch(t, []string{
"DOCKER_CONSUL_BOOTSTRAP_TEST_TEST=testing",
"DOCKER_CONSUL_BOOTSTRAP_TEST_BAZ=bar",
"DOCKER_CONSUL_BOOTSTRAP_EXPAND_ONE=foo-ignore-bar",
"DOCKER_CONSUL_BOOTSTRAP_EXPAND_TWO=foo-bar-baz",
}, e.Environ())
}