-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenv_test.go
More file actions
55 lines (47 loc) · 1.87 KB
/
env_test.go
File metadata and controls
55 lines (47 loc) · 1.87 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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_TEST_DOLLAR", "testing$a1^h")
e.Add("DOCKER_CONSUL_BOOTSTRAP_TEST_EXTRA", "abc^d$1234&567")
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_DOLLAR=testing$a1^h",
"DOCKER_CONSUL_BOOTSTRAP_TEST_EXTRA=abc^d$1234&567",
"DOCKER_CONSUL_BOOTSTRAP_TEST_BAZ=bar",
"DOCKER_CONSUL_BOOTSTRAP_EXPAND_ONE=foo-ignore-bar",
"DOCKER_CONSUL_BOOTSTRAP_EXPAND_TWO=foo-bar-baz",
}, e.Environ())
e.Add("DOCKER_CONSUL_BOOTSTRAP_NEWLINE_ESCAPED", "hello\nworld\n")
e.Add("DOCKER_CONSUL_BOOTSTRAP_NEWLINE", `foo
bar
baz
test`)
assert.Equal(t, map[string]string{
"DOCKER_CONSUL_BOOTSTRAP_TEST_TEST": "testing",
"DOCKER_CONSUL_BOOTSTRAP_TEST_DOLLAR": "testing$a1^h",
"DOCKER_CONSUL_BOOTSTRAP_TEST_EXTRA": "abc^d$1234&567",
"DOCKER_CONSUL_BOOTSTRAP_TEST_BAZ": "bar",
"DOCKER_CONSUL_BOOTSTRAP_EXPAND_ONE": "foo-ignore-bar",
"DOCKER_CONSUL_BOOTSTRAP_EXPAND_TWO": "foo-bar-baz",
"DOCKER_CONSUL_BOOTSTRAP_NEWLINE": "foo\nbar\nbaz\n\ntest",
"DOCKER_CONSUL_BOOTSTRAP_NEWLINE_ESCAPED": "hello\nworld\n",
}, e.Map())
}