From 5afaedc9ab2dca4049b1cd54b59b733fbc3c1a72 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Mon, 7 Mar 2022 16:53:50 -0700 Subject: [PATCH 01/10] 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" + // } + } +} From 1a555315b2df6712da41d0b8a5228925b40c002d Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Tue, 8 Mar 2022 09:07:00 -0700 Subject: [PATCH 02/10] Add comment re disconnected outputs test Signed-off-by: Joel Longtine --- tests/plan/do/disconnected_outputs_weirdness.cue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/plan/do/disconnected_outputs_weirdness.cue b/tests/plan/do/disconnected_outputs_weirdness.cue index 4c786d9e..dc290770 100644 --- a/tests/plan/do/disconnected_outputs_weirdness.cue +++ b/tests/plan/do/disconnected_outputs_weirdness.cue @@ -7,6 +7,8 @@ import ( "universe.dagger.io/bash" ) +// NOTE: This is NOT working. Just an interesting/weird case. + dagger.#Plan & { // This is acting weird... // I don't understand why `cue/flow` thinks that outputs.files.test has a dependency From 648e508c60585f9677d76107ae173a4ff21ec012 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Tue, 8 Mar 2022 09:07:52 -0700 Subject: [PATCH 03/10] cue fmt Signed-off-by: Joel Longtine --- tests/plan/do/do_not_run_unspecified_tasks.cue | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/plan/do/do_not_run_unspecified_tasks.cue b/tests/plan/do/do_not_run_unspecified_tasks.cue index 977a7c32..bb43b5ae 100644 --- a/tests/plan/do/do_not_run_unspecified_tasks.cue +++ b/tests/plan/do/do_not_run_unspecified_tasks.cue @@ -45,12 +45,10 @@ dagger.#Plan & { } } - dependent: { - one: bash.#Run & { - input: test.one.output - script: contents: "cat /output.txt" - export: files: "/output.txt": string - } + dependent: one: bash.#Run & { + input: test.one.output + script: contents: "cat /output.txt" + export: files: "/output.txt": string } notMe: bash.#Run & { From cf2538e1b254e3fb2d3457dbba609ba942cf5c80 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Tue, 8 Mar 2022 09:41:34 -0700 Subject: [PATCH 04/10] Clean up tests Signed-off-by: Joel Longtine --- tests/plan.bats | 9 ++++----- tests/plan/do/dynamic_tasks.cue | 14 +++++++------- tests/project/init/cue.mod/module.cue | 1 + 3 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 tests/project/init/cue.mod/module.cue diff --git a/tests/plan.bats b/tests/plan.bats index 03e95f44..aed5b3f8 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -7,19 +7,18 @@ 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" + 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 + refute_output --partial "actions.test.b" } @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' + refute_output --partial 'actions.test.b.y' } @test "plan/do don't run unspecified tasks" { - run "$DAGGER" "do" -p ./plan/do/do_not_run_unspecified_tasks.cue "test" + 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" diff --git a/tests/plan/do/dynamic_tasks.cue b/tests/plan/do/dynamic_tasks.cue index b02de097..7b44cf61 100644 --- a/tests/plan/do/dynamic_tasks.cue +++ b/tests/plan/do/dynamic_tasks.cue @@ -8,8 +8,8 @@ import ( ) dagger.#Plan & { - outputs: files: andrea: { - dest: "./andrea_do" + outputs: files: dagger: { + dest: "./dagger_do" contents: actions.test.b.y.export.files["/output.txt"] } @@ -21,7 +21,7 @@ dagger.#Plan & { test: { a: bash.#Run & { input: image.output - script: contents: "echo -n 'from andrea with love' > /output.txt" + script: contents: "echo -n 'from dagger with love' > /output.txt" export: files: "/output.txt": string } b: { @@ -41,9 +41,9 @@ dagger.#Plan & { } } - // notMe: bash.#Run & { - // input: image.output - // script: contents: "false" - // } + notMe: bash.#Run & { + input: image.output + script: contents: "false" + } } } diff --git a/tests/project/init/cue.mod/module.cue b/tests/project/init/cue.mod/module.cue new file mode 100644 index 00000000..83ddb3bc --- /dev/null +++ b/tests/project/init/cue.mod/module.cue @@ -0,0 +1 @@ +module: "github.com/foo/bar" \ No newline at end of file From c9f9fd66d7bfd81384965ea2b28098108000a7ba Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Tue, 8 Mar 2022 09:47:17 -0700 Subject: [PATCH 05/10] do -> "do" Signed-off-by: Joel Longtine --- tests/plan.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plan.bats b/tests/plan.bats index aed5b3f8..8c4f5d2c 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -7,7 +7,7 @@ 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 + 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 --partial "actions.test.b" } From 58dd2ab1d3a0c392f8b66294c32d7547331aad6e Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Tue, 8 Mar 2022 09:56:39 -0700 Subject: [PATCH 06/10] outputs -> client Signed-off-by: Joel Longtine --- tests/plan.bats | 3 ++- tests/plan/do/do_not_run_unspecified_tasks.cue | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/plan.bats b/tests/plan.bats index 8c4f5d2c..44a3cddf 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -27,7 +27,8 @@ setup() { 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" + assert_output --partial 'client.filesystem."./test_do".write' + refute_output --partial "actions.notMe" refute_output --partial "actions.notMe" } diff --git a/tests/plan/do/do_not_run_unspecified_tasks.cue b/tests/plan/do/do_not_run_unspecified_tasks.cue index bb43b5ae..549ae046 100644 --- a/tests/plan/do/do_not_run_unspecified_tasks.cue +++ b/tests/plan/do/do_not_run_unspecified_tasks.cue @@ -8,10 +8,8 @@ import ( ) dagger.#Plan & { - outputs: files: test: { - dest: "./test_do" - contents: actions.test.one.export.files["/output.txt"] - } + client: filesystem: "./test_do": write: contents: actions.test.one.export.files["/output.txt"] + client: filesystem: "./dependent_do": write: contents: actions.dependent.one.export.files["/output.txt"] outputs: files: dependent: { dest: "./dependent_do" From baeb19bfe23d7d79f50a6f13504be9050898364d Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Tue, 8 Mar 2022 09:59:07 -0700 Subject: [PATCH 07/10] Fix refute Signed-off-by: Joel Longtine --- tests/plan.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plan.bats b/tests/plan.bats index 44a3cddf..c4dbef51 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -29,7 +29,7 @@ setup() { assert_output --partial "actions.test.one.export" assert_output --partial 'client.filesystem."./test_do".write' refute_output --partial "actions.notMe" - refute_output --partial "actions.notMe" + refute_output --partial 'client.filesystem."./dependent_do".write' } From 8017b29abd2647b74f0c02d77fbed577f5391d1b Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Tue, 8 Mar 2022 13:05:03 -0700 Subject: [PATCH 08/10] More outputs -> client Signed-off-by: Joel Longtine --- tests/plan/do/disconnected_outputs_weirdness.cue | 5 +---- tests/plan/do/dynamic_tasks.cue | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/plan/do/disconnected_outputs_weirdness.cue b/tests/plan/do/disconnected_outputs_weirdness.cue index dc290770..b9561c1d 100644 --- a/tests/plan/do/disconnected_outputs_weirdness.cue +++ b/tests/plan/do/disconnected_outputs_weirdness.cue @@ -19,10 +19,7 @@ dagger.#Plan & { // 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"] - } + client: filesystem: "./test_do": write: contents: actions.test1.one.export.files["/output.txt"] actions: { image: alpine.#Build & { diff --git a/tests/plan/do/dynamic_tasks.cue b/tests/plan/do/dynamic_tasks.cue index 7b44cf61..47d75baf 100644 --- a/tests/plan/do/dynamic_tasks.cue +++ b/tests/plan/do/dynamic_tasks.cue @@ -8,10 +8,7 @@ import ( ) dagger.#Plan & { - outputs: files: dagger: { - dest: "./dagger_do" - contents: actions.test.b.y.export.files["/output.txt"] - } + client: filesystem: "./dagger_do": write: contents: actions.test.b.y.export.files["/output.txt"] actions: { image: alpine.#Build & { From 69208b7c7d2eae2a744e547d880b07369ef33ba0 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Tue, 8 Mar 2022 13:53:52 -0700 Subject: [PATCH 09/10] Remove extraneous module.cue Signed-off-by: Joel Longtine --- tests/project/init/cue.mod/module.cue | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tests/project/init/cue.mod/module.cue diff --git a/tests/project/init/cue.mod/module.cue b/tests/project/init/cue.mod/module.cue deleted file mode 100644 index 83ddb3bc..00000000 --- a/tests/project/init/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "github.com/foo/bar" \ No newline at end of file From 9dfa81a7376875fb78cc9e0cde8026dc5bc9cb69 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Tue, 8 Mar 2022 13:57:40 -0700 Subject: [PATCH 10/10] Remove test that refers to old code paths Signed-off-by: Joel Longtine --- .../do/disconnected_outputs_weirdness.cue | 56 ------------------- 1 file changed, 56 deletions(-) delete mode 100644 tests/plan/do/disconnected_outputs_weirdness.cue diff --git a/tests/plan/do/disconnected_outputs_weirdness.cue b/tests/plan/do/disconnected_outputs_weirdness.cue deleted file mode 100644 index b9561c1d..00000000 --- a/tests/plan/do/disconnected_outputs_weirdness.cue +++ /dev/null @@ -1,56 +0,0 @@ -package main - -import ( - "dagger.io/dagger" - - "universe.dagger.io/alpine" - "universe.dagger.io/bash" -) - -// NOTE: This is NOT working. Just an interesting/weird case. - -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 - client: filesystem: "./test_do": write: 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" - } - } -}