From 707dbd0256c29fd370f9b55eabc1f8327518da76 Mon Sep 17 00:00:00 2001 From: dubo-dubon-duponey Date: Tue, 26 Jan 2021 11:33:10 -0800 Subject: [PATCH] Work on integration tests - add new entries for #70 and #74 - cleaned-up / enriched a little bit compute and exec tests Signed-off-by: dubo-dubon-duponey --- .../compute/invalid/overload/new_def/main.cue | 16 +++++++++ .../invalid/overload/new_prop/main.cue | 16 +++++++++ .../tests/compute/{ => success}/noop/main.cue | 0 .../compute/success/overload/flat/main.cue | 17 ++++++++++ .../compute/success/overload/wrapped/main.cue | 19 +++++++++++ .../compute/{ => success}/simple/main.cue | 2 +- .../tests/compute/undefined_prop/main.cue | 17 ---------- examples/tests/exec/exit_code/main.cue | 14 ++++++++ .../non_concrete_not_referenced/main.cue | 20 +++++++++++ .../non_concrete_referenced/main.cue | 20 +++++++++++ .../undefined/with_pkg_def/cue.mod/module.cue | 1 + .../cue.mod/pkg/dagger.cloud/def/main.cue | 19 +++++++++++ .../exec/undefined/with_pkg_def/main.cue | 14 ++++++++ .../with_pkg_mandatory/cue.mod/module.cue | 1 + .../pkg/dagger.cloud/nonoptional/main.cue | 20 +++++++++++ .../undefined/with_pkg_mandatory/main.cue | 14 ++++++++ .../with_pkg_optional/cue.mod/module.cue | 1 + .../pkg/dagger.cloud/optional/main.cue | 19 +++++++++++ .../exec/undefined/with_pkg_optional/main.cue | 14 ++++++++ examples/tests/test.sh | 33 ++++++++++++++++--- 20 files changed, 254 insertions(+), 23 deletions(-) create mode 100644 examples/tests/compute/invalid/overload/new_def/main.cue create mode 100644 examples/tests/compute/invalid/overload/new_prop/main.cue rename examples/tests/compute/{ => success}/noop/main.cue (100%) create mode 100644 examples/tests/compute/success/overload/flat/main.cue create mode 100644 examples/tests/compute/success/overload/wrapped/main.cue rename examples/tests/compute/{ => success}/simple/main.cue (87%) delete mode 100644 examples/tests/compute/undefined_prop/main.cue create mode 100644 examples/tests/exec/exit_code/main.cue create mode 100644 examples/tests/exec/undefined/non_concrete_not_referenced/main.cue create mode 100644 examples/tests/exec/undefined/non_concrete_referenced/main.cue create mode 100644 examples/tests/exec/undefined/with_pkg_def/cue.mod/module.cue create mode 100644 examples/tests/exec/undefined/with_pkg_def/cue.mod/pkg/dagger.cloud/def/main.cue create mode 100644 examples/tests/exec/undefined/with_pkg_def/main.cue create mode 100644 examples/tests/exec/undefined/with_pkg_mandatory/cue.mod/module.cue create mode 100644 examples/tests/exec/undefined/with_pkg_mandatory/cue.mod/pkg/dagger.cloud/nonoptional/main.cue create mode 100644 examples/tests/exec/undefined/with_pkg_mandatory/main.cue create mode 100644 examples/tests/exec/undefined/with_pkg_optional/cue.mod/module.cue create mode 100644 examples/tests/exec/undefined/with_pkg_optional/cue.mod/pkg/dagger.cloud/optional/main.cue create mode 100644 examples/tests/exec/undefined/with_pkg_optional/main.cue diff --git a/examples/tests/compute/invalid/overload/new_def/main.cue b/examples/tests/compute/invalid/overload/new_def/main.cue new file mode 100644 index 00000000..dfec98af --- /dev/null +++ b/examples/tests/compute/invalid/overload/new_def/main.cue @@ -0,0 +1,16 @@ +package testing + +bar: #dagger: { + + #new_def: "lala" + + compute: [{ + do: "fetch-container" + ref: "busybox" + }, + { + do: "exec" + args: ["true"] + dir: "/" + }] +} diff --git a/examples/tests/compute/invalid/overload/new_prop/main.cue b/examples/tests/compute/invalid/overload/new_prop/main.cue new file mode 100644 index 00000000..3bd29f9f --- /dev/null +++ b/examples/tests/compute/invalid/overload/new_prop/main.cue @@ -0,0 +1,16 @@ +package testing + +bar: #dagger: { + + new_prop: "lala" + + compute: [{ + do: "fetch-container" + ref: "busybox" + }, + { + do: "exec" + args: ["true"] + dir: "/" + }] +} diff --git a/examples/tests/compute/noop/main.cue b/examples/tests/compute/success/noop/main.cue similarity index 100% rename from examples/tests/compute/noop/main.cue rename to examples/tests/compute/success/noop/main.cue diff --git a/examples/tests/compute/success/overload/flat/main.cue b/examples/tests/compute/success/overload/flat/main.cue new file mode 100644 index 00000000..7bac1cf9 --- /dev/null +++ b/examples/tests/compute/success/overload/flat/main.cue @@ -0,0 +1,17 @@ +package testing + +new_prop: "lala" +#new_def: "lala" + +new_prop_too: string +#new_def_too: string + +#dagger: compute: [{ + do: "fetch-container" + ref: "busybox" +}, + { + do: "exec" + args: ["true"] + dir: "/" + }] diff --git a/examples/tests/compute/success/overload/wrapped/main.cue b/examples/tests/compute/success/overload/wrapped/main.cue new file mode 100644 index 00000000..4275220a --- /dev/null +++ b/examples/tests/compute/success/overload/wrapped/main.cue @@ -0,0 +1,19 @@ +package testing + +foo: { + new_prop: "lala" + #new_def: "lala" + + new_prop_too: string + #new_def_too: string + + #dagger: compute: [{ + do: "fetch-container" + ref: "busybox" + }, + { + do: "exec" + args: ["true"] + dir: "/" + }] +} diff --git a/examples/tests/compute/simple/main.cue b/examples/tests/compute/success/simple/main.cue similarity index 87% rename from examples/tests/compute/simple/main.cue rename to examples/tests/compute/success/simple/main.cue index 9c6fca88..90657450 100644 --- a/examples/tests/compute/simple/main.cue +++ b/examples/tests/compute/success/simple/main.cue @@ -3,7 +3,7 @@ package testing #dagger: compute: [ { do: "fetch-container" - ref: "alpine" + ref: "busybox" }, { do: "exec" diff --git a/examples/tests/compute/undefined_prop/main.cue b/examples/tests/compute/undefined_prop/main.cue deleted file mode 100644 index 42bf7b8a..00000000 --- a/examples/tests/compute/undefined_prop/main.cue +++ /dev/null @@ -1,17 +0,0 @@ -package testing - -hello: "world" - -bar: string - -#dagger: compute: [ - { - do: "fetch-container" - ref: "alpine" - }, - { - do: "exec" - dir: "/" - args: ["sh", "-c", "echo \(bar)"] - }, -] diff --git a/examples/tests/exec/exit_code/main.cue b/examples/tests/exec/exit_code/main.cue new file mode 100644 index 00000000..901739b0 --- /dev/null +++ b/examples/tests/exec/exit_code/main.cue @@ -0,0 +1,14 @@ +package testing + +#dagger: compute: [ + { + do: "fetch-container" + ref: "alpine" + }, + { + do: "exec" + args: ["sh", "-c", "exit 123"] + // XXX Blocked by https://github.com/blocklayerhq/dagger/issues/19 + dir: "/" + }, +] diff --git a/examples/tests/exec/undefined/non_concrete_not_referenced/main.cue b/examples/tests/exec/undefined/non_concrete_not_referenced/main.cue new file mode 100644 index 00000000..ad6bda78 --- /dev/null +++ b/examples/tests/exec/undefined/non_concrete_not_referenced/main.cue @@ -0,0 +1,20 @@ +package testing + +hello: "world" +bar: string + +#dagger: compute: [ + { + do: "fetch-container" + ref: "alpine" + }, + { + do: "exec" + dir: "/" + args: ["sh", "-c", """ + echo \(hello) + echo "This test SHOULD fail, because this script SHOULD execute, since bar is not referenced" + exit 1 + """] + }, +] diff --git a/examples/tests/exec/undefined/non_concrete_referenced/main.cue b/examples/tests/exec/undefined/non_concrete_referenced/main.cue new file mode 100644 index 00000000..45267375 --- /dev/null +++ b/examples/tests/exec/undefined/non_concrete_referenced/main.cue @@ -0,0 +1,20 @@ +package testing + +hello: "world" +bar: string + +#dagger: compute: [ + { + do: "fetch-container" + ref: "alpine" + }, + { + do: "exec" + dir: "/" + args: ["sh", "-c", """ + echo \(bar) + echo "This test SHOULD succeed, because this is never going to be executed, as \(bar) is not concrete" + exit 1 + """] + }, +] diff --git a/examples/tests/exec/undefined/with_pkg_def/cue.mod/module.cue b/examples/tests/exec/undefined/with_pkg_def/cue.mod/module.cue new file mode 100644 index 00000000..c099c45a --- /dev/null +++ b/examples/tests/exec/undefined/with_pkg_def/cue.mod/module.cue @@ -0,0 +1 @@ +module: "dagger.cloud/testing" diff --git a/examples/tests/exec/undefined/with_pkg_def/cue.mod/pkg/dagger.cloud/def/main.cue b/examples/tests/exec/undefined/with_pkg_def/cue.mod/pkg/dagger.cloud/def/main.cue new file mode 100644 index 00000000..28a78e60 --- /dev/null +++ b/examples/tests/exec/undefined/with_pkg_def/cue.mod/pkg/dagger.cloud/def/main.cue @@ -0,0 +1,19 @@ +package def + +#dang: string + +#dagger: { + compute: [ + { + do: "fetch-container" + ref: "alpine" + }, + { + do: "exec" + dir: "/" + args: ["sh", "-c", """ + echo success + """] + }, + ] +} diff --git a/examples/tests/exec/undefined/with_pkg_def/main.cue b/examples/tests/exec/undefined/with_pkg_def/main.cue new file mode 100644 index 00000000..3d5c069d --- /dev/null +++ b/examples/tests/exec/undefined/with_pkg_def/main.cue @@ -0,0 +1,14 @@ +package testing + +import ( + "dagger.cloud/def" +) + +#dagger: { + compute: [ + { + do: "load", + from: def + }, + ] +} diff --git a/examples/tests/exec/undefined/with_pkg_mandatory/cue.mod/module.cue b/examples/tests/exec/undefined/with_pkg_mandatory/cue.mod/module.cue new file mode 100644 index 00000000..c099c45a --- /dev/null +++ b/examples/tests/exec/undefined/with_pkg_mandatory/cue.mod/module.cue @@ -0,0 +1 @@ +module: "dagger.cloud/testing" diff --git a/examples/tests/exec/undefined/with_pkg_mandatory/cue.mod/pkg/dagger.cloud/nonoptional/main.cue b/examples/tests/exec/undefined/with_pkg_mandatory/cue.mod/pkg/dagger.cloud/nonoptional/main.cue new file mode 100644 index 00000000..a10eb681 --- /dev/null +++ b/examples/tests/exec/undefined/with_pkg_mandatory/cue.mod/pkg/dagger.cloud/nonoptional/main.cue @@ -0,0 +1,20 @@ +package nonoptional + +dang: string + +#dagger: { + compute: [ + { + do: "fetch-container" + ref: "alpine" + }, + { + do: "exec" + dir: "/" + args: ["sh", "-c", """ + echo "This test SHOULD fail, because this SHOULD be executed" + exit 1 + """] + }, + ] +} diff --git a/examples/tests/exec/undefined/with_pkg_mandatory/main.cue b/examples/tests/exec/undefined/with_pkg_mandatory/main.cue new file mode 100644 index 00000000..e1c1b332 --- /dev/null +++ b/examples/tests/exec/undefined/with_pkg_mandatory/main.cue @@ -0,0 +1,14 @@ +package testing + +import ( + "dagger.cloud/nonoptional" +) + +#dagger: { + compute: [ + { + do: "load", + from: nonoptional + }, + ] +} diff --git a/examples/tests/exec/undefined/with_pkg_optional/cue.mod/module.cue b/examples/tests/exec/undefined/with_pkg_optional/cue.mod/module.cue new file mode 100644 index 00000000..c099c45a --- /dev/null +++ b/examples/tests/exec/undefined/with_pkg_optional/cue.mod/module.cue @@ -0,0 +1 @@ +module: "dagger.cloud/testing" diff --git a/examples/tests/exec/undefined/with_pkg_optional/cue.mod/pkg/dagger.cloud/optional/main.cue b/examples/tests/exec/undefined/with_pkg_optional/cue.mod/pkg/dagger.cloud/optional/main.cue new file mode 100644 index 00000000..681e7aa1 --- /dev/null +++ b/examples/tests/exec/undefined/with_pkg_optional/cue.mod/pkg/dagger.cloud/optional/main.cue @@ -0,0 +1,19 @@ +package optional + +dang?: string + +#dagger: { + compute: [ + { + do: "fetch-container" + ref: "alpine" + }, + { + do: "exec" + dir: "/" + args: ["sh", "-c", """ + echo success + """] + }, + ] +} diff --git a/examples/tests/exec/undefined/with_pkg_optional/main.cue b/examples/tests/exec/undefined/with_pkg_optional/main.cue new file mode 100644 index 00000000..acf1624b --- /dev/null +++ b/examples/tests/exec/undefined/with_pkg_optional/main.cue @@ -0,0 +1,14 @@ +package testing + +import ( + "dagger.cloud/optional" +) + +#dagger: { + compute: [ + { + do: "load", + from: optional + }, + ] +} diff --git a/examples/tests/test.sh b/examples/tests/test.sh index 338ef92e..7251326d 100755 --- a/examples/tests/test.sh +++ b/examples/tests/test.sh @@ -16,7 +16,7 @@ readonly DAGGER_BINARY_ARGS test::compute(){ local dagger="$1" - # Compute + # Compute: invalid syntax test::one "Compute: invalid string should fail" --exit=1 --stdout= \ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/string test::one "Compute: invalid bool should fail" --exit=1 --stdout= \ @@ -25,12 +25,20 @@ test::compute(){ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/int test::one "Compute: invalid struct should fail" --exit=1 --stdout= \ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/struct + test::one "Compute: overloading #ComponentScript with new prop should fail" --exit=1 \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/overload/new_prop + test::one "Compute: overloading #ComponentScript with new def should fail" --exit=1 \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/overload/new_def + + # Compute: success test::one "Compute: noop should succeed" --exit=0 --stdout='{"empty":{},"realempty":{}}' \ - "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/noop + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/success/noop test::one "Compute: simple should succeed" --exit=0 --stdout="{}" \ - "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/simple - test::one "Compute: script with undefined values should not fail" --exit=0 --stdout='{"hello":"world"}' \ - "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/undefined_prop + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/success/simple + test::one "Compute: overloading #Component should work" --exit=0 \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/success/overload/flat + test::one "Compute: overloading #Component should work" --exit=0 \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/success/overload/wrapped } test::fetchcontainer(){ @@ -92,6 +100,21 @@ test::exec(){ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/dir/doesnotexist test::one "Exec: valid dir" --exit=0 --stdout={} \ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/dir/exist + + disable test::one "Exec: exit code propagation (FIXME https://github.com/blocklayerhq/dagger/issues/74)" --exit=123 \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/exit_code + + test::one "Exec: script with referenced non-concrete property should not be executed, and should succeed overall" --exit=0 --stdout='{"hello":"world"}' \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/undefined/non_concrete_referenced + # NOTE: the exec is meant to fail - and we test that as a way to confirm it has been executed + test::one "Exec: script with unreferenced undefined properties should be executed" --exit=1 \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/undefined/non_concrete_not_referenced + test::one "Exec: package with optional def, not referenced, should be executed" --exit=0 \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/undefined/with_pkg_def + test::one "Exec: script with optional prop, not referenced, should be executed" --exit=0 \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/undefined/with_pkg_optional + disable test::one "Exec: script with non-optional prop, not referenced, should be executed (FIXME https://github.com/blocklayerhq/dagger/issues/70)" --exit=1 \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/undefined/with_pkg_mandatory } test::export(){