Skip to content

Commit

Permalink
Fix .env file parsing so merging works properly
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Henderson <[email protected]>
  • Loading branch information
hairyhenderson committed Mar 9, 2019
1 parent 5c27e1e commit 4d228ff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,15 @@ func TOML(in string) (interface{}, error) {

// dotEnv - Unmarshal a dotenv file
func dotEnv(in string) (interface{}, error) {
return godotenv.Unmarshal(in)
env, err := godotenv.Unmarshal(in)
if err != nil {
return nil, err
}
out := make(map[string]interface{})
for k, v := range env {
out[k] = v
}
return out, nil
}

func parseCSV(args ...string) ([][]string, []string, error) {
Expand Down
2 changes: 1 addition & 1 deletion data/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ FOO.BAR = "values can be double-quoted, and shell\nescapes are supported"
BAZ = "variable expansion: ${FOO}"
QUX='single quotes ignore $variables'
`
expected := map[string]string{
expected := map[string]interface{}{
"FOO": "a regular unquoted value",
"BAR": "another value, exports are ignored",
"FOO.BAR": "values can be double-quoted, and shell\nescapes are supported",
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/datasources_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func (s *MergeDatasourceSuite) SetUpSuite(c *C) {
handle(c, err)

http.HandleFunc("/foo.json", typeHandler("application/json", `{"foo": "bar"}`))
http.HandleFunc("/1.env", typeHandler("application/x-env", "FOO=1\nBAR=2\n"))
http.HandleFunc("/2.env", typeHandler("application/x-env", "FOO=3\n"))
go http.Serve(s.l, nil)
}

Expand Down Expand Up @@ -63,4 +65,10 @@ func (s *MergeDatasourceSuite) TestMergeDatasource(c *C) {
"-i", `{{ ds "config" | toJSON }}`,
)
result.Assert(c, icmd.Expected{ExitCode: 0, Out: `{"foo":"bar","other":true}`})

result = icmd.RunCommand(GomplateBin,
"-c", "merged=merge:http://"+s.l.Addr().String()+"/2.env|http://"+s.l.Addr().String()+"/1.env",
"-i", `FOO is {{ .merged.FOO }}`,
)
result.Assert(c, icmd.Expected{ExitCode: 0, Out: `FOO is 3`})
}

0 comments on commit 4d228ff

Please sign in to comment.