Skip to content

Commit

Permalink
Fix regression of --data-value-file flag (#680)
Browse files Browse the repository at this point in the history
also:
- include E2E test case to smoke-test this flag

Co-authored-by: John Ryan <[email protected]>
  • Loading branch information
pivotaljohn and jtigger authored May 26, 2022
1 parent f9826a6 commit 2a58cd7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
11 changes: 11 additions & 0 deletions examples/data-values/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,14 @@ string: str
bool: true
int: 124
float: 0
***
nothing: something
string: |-
Value that comes from a file.

Typically, useful for files that contain values
that should just be passed through to system
configuration, wholesale (e.g. certs).
bool: false
int: 0
float: 0
5 changes: 5 additions & 0 deletions examples/data-values/file-as-value.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Value that comes from a file.

Typically, useful for files that contain values
that should just be passed through to system
configuration, wholesale (e.g. certs).
5 changes: 5 additions & 0 deletions examples/data-values/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ echo '***'

./ytt -f examples/data-values/config.yml -f examples/data-values/values.yml \
--data-values-file examples/data-values/values-file.yml

echo '***'

./ytt -f examples/data-values/config.yml -f examples/data-values/values.yml \
--data-value-file string=examples/data-values/file-as-value.txt
2 changes: 1 addition & 1 deletion pkg/cmd/template/data_values_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *DataValuesFlags) Set(cmdFlags CmdFlags) {

cmdFlags.StringArrayVarP(&s.KVsFromStrings, "data-value", "v", nil, "Set specific data value to given value, as string (format: all.key1.subkey=123) (can be specified multiple times)")
cmdFlags.StringArrayVar(&s.KVsFromYAML, "data-value-yaml", nil, "Set specific data value to given value, parsed as YAML (format: all.key1.subkey=true) (can be specified multiple times)")
cmdFlags.StringArrayVar(&s.FromFiles, "data-value-file", nil, "Set specific data value to contents of a file (format: [@lib1:]all.key1.subkey={file path, HTTP URL, or '-' (i.e. stdin)}) (can be specified multiple times)")
cmdFlags.StringArrayVar(&s.KVsFromFiles, "data-value-file", nil, "Set specific data value to contents of a file (format: [@lib1:]all.key1.subkey={file path, HTTP URL, or '-' (i.e. stdin)}) (can be specified multiple times)")
cmdFlags.StringArrayVar(&s.FromFiles, "data-values-file", nil, "Set multiple data values via plain YAML files (format: [@lib1:]{file path, HTTP URL, or '-' (i.e. stdin)}) (can be specified multiple times)")

cmdFlags.BoolVar(&s.Inspect, "data-values-inspect", false, "Determine the final data values (applying any overlays) and display that result")
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,26 @@ float: 123.123

require.Equal(t, string(expectedOutput), actualOutput)
})
t.Run("--data-value-file flag", func(t *testing.T) {
flags := yttFlags{
{"--data-value-file": "string=../../examples/data-values/file-as-value.txt"},
}
actualOutput := runYtt(t, testInputFiles{"../../examples/data-values/config.yml", "../../examples/data-values/values.yml"}, "", flags, nil)
expectedOutput := `nothing: something
string: |-
Value that comes from a file.
Typically, useful for files that contain values
that should just be passed through to system
configuration, wholesale (e.g. certs).
bool: false
int: 0
float: 0
`

require.Equal(t, expectedOutput, actualOutput)
})

})
t.Run("can be 'required'", func(t *testing.T) {
expectedFileOutput, err := ioutil.ReadFile("../../examples/data-values-required/expected.txt")
Expand Down

0 comments on commit 2a58cd7

Please sign in to comment.