-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters