Skip to content

Commit

Permalink
Resolve env var values when unmarshalling
Browse files Browse the repository at this point in the history
Commit 1595c1d accidentally removed the lines that resolve env var
values. This adds env var resolution and adds a test to assert the
behavior.
  • Loading branch information
stengaard committed Feb 22, 2020
1 parent a6c85cd commit 60873a9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions envlist_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package sup

import (
"reflect"
"testing"

"gopkg.in/yaml.v2"
)

func TestEnvListUnmarshalYAML(t *testing.T) {
type holder struct {
Env EnvList `yaml:"env"`
}

testCases := []struct {
input string
expect holder
}{
{

input: `
env:
MY_KEY: abc123
`,
expect: holder{
Env: EnvList{
&EnvVar{Key: "MY_KEY", Value: "abc123"},
},
},
},
{

input: `
env:
MY_KEY: $(echo abc123)
`,
expect: holder{
Env: EnvList{
&EnvVar{Key: "MY_KEY", Value: "abc123"},
},
},
},
}

for _, tc := range testCases {
h := holder{}
yaml.Unmarshal([]byte(tc.input), &h)
if !reflect.DeepEqual(h, tc.expect) {
t.Errorf("Unmarshalling yaml did not produce the expected result. Got:\n%#v\nExpected: %#v\n", h, tc.expect)
}
}
}
2 changes: 1 addition & 1 deletion supfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (e *EnvList) UnmarshalYAML(unmarshal func(interface{}) error) error {
e.Set(fmt.Sprintf("%v", v.Key), fmt.Sprintf("%v", v.Value))
}

return nil
return e.ResolveValues()
}

// Set key to be equal value in this list.
Expand Down

0 comments on commit 60873a9

Please sign in to comment.