Fix index out of bound for Dagger compute inputs + add tests ["input-dir", "input-git", input-string"]

Signed-off-by: Guillaume de Rouville <guillaume.derouville@gmail.com>
This commit is contained in:
Guillaume de Rouville 2021-05-31 12:11:54 +02:00
parent 5ab66cc5ef
commit d74efa2420
2 changed files with 24 additions and 0 deletions

View File

@ -43,6 +43,10 @@ var computeCmd = &cobra.Command{
for _, input := range viper.GetStringSlice("input-string") {
parts := strings.SplitN(input, "=", 2)
if len(parts) != 2 {
lg.Fatal().Msgf("failed to parse input: input-string")
}
k, v := parts[0], parts[1]
err := st.SetInput(k, state.TextInput(v))
if err != nil {
@ -56,6 +60,10 @@ var computeCmd = &cobra.Command{
for _, input := range viper.GetStringSlice("input-dir") {
parts := strings.SplitN(input, "=", 2)
if len(parts) != 2 {
lg.Fatal().Msgf("failed to parse input: input-dir")
}
k, v := parts[0], parts[1]
err := st.SetInput(k, state.DirInput(v, []string{}, []string{}))
if err != nil {
@ -69,6 +77,10 @@ var computeCmd = &cobra.Command{
for _, input := range viper.GetStringSlice("input-git") {
parts := strings.SplitN(input, "=", 2)
if len(parts) != 2 {
lg.Fatal().Msgf("failed to parse input: input-git")
}
k, v := parts[0], parts[1]
err := st.SetInput(k, state.GitInput(v, "", ""))
if err != nil {

View File

@ -65,6 +65,18 @@ setup() {
run "$DAGGER" compute --input-string 'in=foobar' "$TESTDIR"/compute/input/default
assert_success
assert_line '{"in":"foobar","test":"received: foobar"}'
run "$DAGGER" compute --input-string=foobar "$TESTDIR"/compute/input/default
assert_failure
assert_output --partial 'failed to parse input: input-string'
run "$DAGGER" compute --input-dir=foobar "$TESTDIR"/compute/input/default
assert_failure
assert_output --partial 'failed to parse input: input-dir'
run "$DAGGER" compute --input-git=foobar "$TESTDIR"/compute/input/default
assert_failure
assert_output --partial 'failed to parse input: input-git'
}
@test "compute: secrets" {