From 5afaedc9ab2dca4049b1cd54b59b733fbc3c1a72 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Mon, 7 Mar 2022 16:53:50 -0700 Subject: [PATCH] Add `do` tests Signed-off-by: Joel Longtine --- tests/plan.bats | 29 +++++++++ .../do/disconnected_outputs_weirdness.cue | 57 +++++++++++++++++ .../plan/do/do_not_run_unspecified_tasks.cue | 61 +++++++++++++++++++ tests/plan/do/dynamic_tasks.cue | 49 +++++++++++++++ 4 files changed, 196 insertions(+) create mode 100644 tests/plan/do/disconnected_outputs_weirdness.cue create mode 100644 tests/plan/do/do_not_run_unspecified_tasks.cue create mode 100644 tests/plan/do/dynamic_tasks.cue diff --git a/tests/plan.bats b/tests/plan.bats index a00f5eec..03e95f44 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -4,6 +4,35 @@ setup() { common_setup } +@test "plan/do dynamic tasks - fails to find tasks" { + # Europa loader handles the cwd differently, therefore we need to CD into the tree at or below the parent of cue.mod + cd "$TESTDIR" + run "$DAGGER" "do" -p ./plan/do/dynamic_tasks.cue "test" "b" + # No output because of weirdness with dynamic tasks, which causes it to fail + refute_output +} + +@test "plan/do dynamic tasks - fails to run tasks" { + run "$DAGGER" "do" -p ./plan/do/dynamic_tasks.cue "test" + assert_failure + assert_output --partial 'outputs.files.andrea: contents is not set' +} + +@test "plan/do don't run unspecified tasks" { + run "$DAGGER" "do" -p ./plan/do/do_not_run_unspecified_tasks.cue "test" + assert_output --partial "actions.test.one.script" + assert_output --partial "actions.test.three.script" + assert_output --partial "actions.test.two.script" + assert_output --partial "actions.image" + assert_output --partial "actions.test.one" + assert_output --partial "actions.test.two" + assert_output --partial "actions.test.three" + assert_output --partial "actions.test.one.export" + assert_output --partial "outputs.files.test" + refute_output --partial "actions.notMe" +} + + @test "plan/hello" { # Europa loader handles the cwd differently, therefore we need to CD into the tree at or below the parent of cue.mod cd "$TESTDIR" diff --git a/tests/plan/do/disconnected_outputs_weirdness.cue b/tests/plan/do/disconnected_outputs_weirdness.cue new file mode 100644 index 00000000..4c786d9e --- /dev/null +++ b/tests/plan/do/disconnected_outputs_weirdness.cue @@ -0,0 +1,57 @@ +package main + +import ( + "dagger.io/dagger" + + "universe.dagger.io/alpine" + "universe.dagger.io/bash" +) + +dagger.#Plan & { + // This is acting weird... + // I don't understand why `cue/flow` thinks that outputs.files.test has a dependency + // on actions.fromAndrea.a.export._files."/output.txt"._read + // It _does_ fail correctly, FWIW, when it reaches this code. + // TASK: outputs.files.test + // DEPENDENCIES: + // actions.fromAndrea.a.export._files."/output.txt"._read + // actions.image._dag."1"._exec + // actions.image._dag."0"._op + outputs: files: test: { + dest: "./test_do" + contents: actions.test1.one.export.files["/output.txt"] + } + + actions: { + image: alpine.#Build & { + packages: bash: {} + } + + abcAction: { + a: bash.#Run & { + input: image.output + script: contents: "echo -n 'from andrea with love' > /output.txt" + export: files: "/output.txt": string + } + b: { + x: bash.#Run & { + input: image.output + script: contents: "echo -n false > /output.txt" + export: files: "/output.txt": string + } + if x.export.files["/output.txt"] == "false" { + y: bash.#Run & { + input: a.output + script: contents: "echo -n hello from y" + export: files: "/output.txt": "from andrea with love" + } + } + } + } + + notMe: bash.#Run & { + input: image.output + script: contents: "false" + } + } +} diff --git a/tests/plan/do/do_not_run_unspecified_tasks.cue b/tests/plan/do/do_not_run_unspecified_tasks.cue new file mode 100644 index 00000000..977a7c32 --- /dev/null +++ b/tests/plan/do/do_not_run_unspecified_tasks.cue @@ -0,0 +1,61 @@ +package main + +import ( + "dagger.io/dagger" + + "universe.dagger.io/alpine" + "universe.dagger.io/bash" +) + +dagger.#Plan & { + outputs: files: test: { + dest: "./test_do" + contents: actions.test.one.export.files["/output.txt"] + } + + outputs: files: dependent: { + dest: "./dependent_do" + contents: actions.dependent.one.export.files["/output.txt"] + } + + actions: { + image: alpine.#Build & { + packages: bash: {} + } + + test: { + one: bash.#Run & { + input: image.output + script: contents: "echo Hello World! > /output.txt" + export: files: "/output.txt": string + } + + two: bash.#Run & { + input: image.output + script: contents: "true" + } + + three: bash.#Run & { + input: image.output + script: contents: "cat /one/output.txt" + mounts: output: { + contents: one.export.rootfs + dest: "/one" + } + } + } + + dependent: { + one: bash.#Run & { + input: test.one.output + script: contents: "cat /output.txt" + export: files: "/output.txt": string + } + } + + notMe: bash.#Run & { + input: image.output + script: contents: "false" + } + } +} diff --git a/tests/plan/do/dynamic_tasks.cue b/tests/plan/do/dynamic_tasks.cue new file mode 100644 index 00000000..b02de097 --- /dev/null +++ b/tests/plan/do/dynamic_tasks.cue @@ -0,0 +1,49 @@ +package main + +import ( + "dagger.io/dagger" + + "universe.dagger.io/alpine" + "universe.dagger.io/bash" +) + +dagger.#Plan & { + outputs: files: andrea: { + dest: "./andrea_do" + contents: actions.test.b.y.export.files["/output.txt"] + } + + actions: { + image: alpine.#Build & { + packages: bash: {} + } + + test: { + a: bash.#Run & { + input: image.output + script: contents: "echo -n 'from andrea with love' > /output.txt" + export: files: "/output.txt": string + } + b: { + x: bash.#Run & { + input: image.output + script: contents: "echo -n testing > /output.txt" + export: files: "/output.txt": string + } + // This fails. Building the Actions lookup table breaks + if x.export.files["/output.txt"] == "testing" { + y: bash.#Run & { + input: a.output + script: contents: "echo -n hello from y" + export: files: "/output.txt": string + } + } + } + } + + // notMe: bash.#Run & { + // input: image.output + // script: contents: "false" + // } + } +}