Skip to content

Commit 63fd627

Browse files
committed
Resolve env var values when unmarshalling
Commit 1595c1d accidentally removed the lines that resolve env var values. This adds env var resolution and adds a test to assert the behavior.
1 parent 65c282f commit 63fd627

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

envlist_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package sup
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
7+
"gopkg.in/yaml.v2"
8+
)
9+
10+
func TestEnvListUnmarshalYAML(t *testing.T) {
11+
type holder struct {
12+
Env EnvList `yaml:"env"`
13+
}
14+
15+
testCases := []struct {
16+
input string
17+
expect holder
18+
}{
19+
{
20+
21+
input: `
22+
env:
23+
MY_KEY: abc123
24+
`,
25+
expect: holder{
26+
Env: EnvList{
27+
&EnvVar{Key: "MY_KEY", Value: "abc123"},
28+
},
29+
},
30+
},
31+
{
32+
33+
input: `
34+
env:
35+
MY_KEY: $(echo abc123)
36+
`,
37+
expect: holder{
38+
Env: EnvList{
39+
&EnvVar{Key: "MY_KEY", Value: "abc123"},
40+
},
41+
},
42+
},
43+
}
44+
45+
for _, tc := range testCases {
46+
h := holder{}
47+
yaml.Unmarshal([]byte(tc.input), &h)
48+
if !reflect.DeepEqual(h, tc.expect) {
49+
t.Errorf("Unmarshalling yaml did not produce the expected result. Got:\n%#v\nExpected: %#v\n", h, tc.expect)
50+
}
51+
}
52+
}

supfile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (e *EnvList) UnmarshalYAML(unmarshal func(interface{}) error) error {
192192
e.Set(fmt.Sprintf("%v", v.Key), fmt.Sprintf("%v", v.Value))
193193
}
194194

195-
return nil
195+
return e.ResolveValues()
196196
}
197197

198198
// Set key to be equal value in this list.

0 commit comments

Comments
 (0)