diff --git a/plan/plan.go b/plan/plan.go index ad7b58ad..97307926 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -2,7 +2,10 @@ package plan import ( "context" + "errors" "fmt" + "os" + "path/filepath" "strings" "time" @@ -69,6 +72,13 @@ func (p *Plan) registerLocalDirs() error { if err != nil { return err } + abs, err := filepath.Abs(dir) + if err != nil { + return err + } + if _, err := os.Stat(abs); errors.Is(err, os.ErrNotExist) { + return fmt.Errorf("path %q does not exist", abs) + } p.context.LocalDirs.Add(dir) } diff --git a/tests/plan.bats b/tests/plan.bats index b2e29e32..58bb7f21 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -44,6 +44,13 @@ setup() { "$DAGGER" --europa up ./plan/inputs/directories/exists.cue } +@test "plan/inputs/directories not exists" { + cd "$TESTDIR" + run "$DAGGER" --europa up ./plan/inputs/directories/not_exists.cue + assert_failure + assert_output --partial 'tests/fasdfsdfs" does not exist' +} + @test "plan/inputs/directories conflicting values" { cd "$TESTDIR" run "$DAGGER" --europa up ./plan/inputs/directories/conflicting_values.cue diff --git a/tests/plan/inputs/directories/not_exists.cue b/tests/plan/inputs/directories/not_exists.cue new file mode 100644 index 00000000..5fc01c0d --- /dev/null +++ b/tests/plan/inputs/directories/not_exists.cue @@ -0,0 +1,16 @@ +package main + +import ( + "alpha.dagger.io/europa/dagger/engine" +) + +engine.#Plan & { + // should fail because path does not exist locally + inputs: directories: test: path: "./fasdfsdfs" + actions: verify: engine.#ReadFile & { + input: inputs.directories.test.contents + path: "test.txt" + } & { + contents: "local directory" + } +}