-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathprint_test.go
56 lines (48 loc) · 1.64 KB
/
print_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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package cli
import (
"os"
"path"
"testing"
"github.com/bitrise-io/envman/env"
"github.com/stretchr/testify/require"
)
func TestPrint(t *testing.T) {
envsStr := `
envs:
- TEST_HOME1: $HOME
- TEST_HOME2: $TEST_HOME1/test
`
environments, err := ParseEnvsYML([]byte(envsStr))
require.Equal(t, nil, err)
envsJSONList, err := ConvertToEnvsJSONModel(environments, false, false, &env.DefaultEnvironmentSource{})
require.Equal(t, nil, err)
require.Equal(t, "$HOME", envsJSONList["TEST_HOME1"])
require.Equal(t, "$TEST_HOME1/test", envsJSONList["TEST_HOME2"])
testHome1 := os.Getenv("HOME")
testHome2 := path.Join(testHome1, "test")
envsJSONList, err = ConvertToEnvsJSONModel(environments, true, false, &env.DefaultEnvironmentSource{})
require.Equal(t, nil, err)
require.Equal(t, testHome1, envsJSONList["TEST_HOME1"])
require.Equal(t, testHome2, envsJSONList["TEST_HOME2"])
}
func TestPrint_Sensitive(t *testing.T) {
envsStr := `
envs:
- nonsensitivekey: testvalue
- sensitivekey: testsecret
opts:
is_sensitive: true
`
environments, err := ParseEnvsYML([]byte(envsStr))
require.Equal(t, nil, err)
// print everything
envsJSONList, err := ConvertToEnvsJSONModel(environments, false, false, &env.DefaultEnvironmentSource{})
require.Equal(t, nil, err)
require.Equal(t, "testvalue", envsJSONList["nonsensitivekey"])
require.Equal(t, "testsecret", envsJSONList["sensitivekey"])
// print sensitive only
envsJSONList, err = ConvertToEnvsJSONModel(environments, true, true, &env.DefaultEnvironmentSource{})
require.Equal(t, nil, err)
require.Equal(t, "", envsJSONList["nonsensitivekey"])
require.Equal(t, "testsecret", envsJSONList["sensitivekey"])
}