From d74efa24205076a1a1a4e2e4d5cb786b8cd3748a Mon Sep 17 00:00:00 2001 From: Guillaume de Rouville Date: Mon, 31 May 2021 12:11:54 +0200 Subject: [PATCH] Fix index out of bound for Dagger compute inputs + add tests ["input-dir", "input-git", input-string"] Signed-off-by: Guillaume de Rouville --- cmd/dagger/cmd/compute.go | 12 ++++++++++++ tests/compute.bats | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/cmd/dagger/cmd/compute.go b/cmd/dagger/cmd/compute.go index 6f1b43cb..a385ebca 100644 --- a/cmd/dagger/cmd/compute.go +++ b/cmd/dagger/cmd/compute.go @@ -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 { diff --git a/tests/compute.bats b/tests/compute.bats index c8b1c7aa..27b17ce1 100644 --- a/tests/compute.bats +++ b/tests/compute.bats @@ -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" {