From 3be2865a565e7acf226351836bb4ae1fb499a6f3 Mon Sep 17 00:00:00 2001 From: dubo-dubon-duponey Date: Fri, 15 Jan 2021 15:10:28 -0800 Subject: [PATCH] Tests tests tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tests for #Copy - added a “disable” helper to disable specific tests instead of just commenting them out - “disable” will print out warnings about disabled tests (hopefully with links to corresponding issues) - cleanup bug repro that has been subsumed into tests Signed-off-by: dubo-dubon-duponey --- examples/repro-14/main.cue | 13 ---- examples/tests/copy/invalid/cache/main.cue | 49 ++++++++++++++ examples/tests/copy/valid/component/main.cue | 69 ++++++++++++++++++++ examples/tests/copy/valid/script/main.cue | 25 +++++++ examples/tests/test-lib.sh | 4 ++ examples/tests/test.sh | 60 ++++++++++------- 6 files changed, 184 insertions(+), 36 deletions(-) delete mode 100644 examples/repro-14/main.cue create mode 100644 examples/tests/copy/invalid/cache/main.cue create mode 100644 examples/tests/copy/valid/component/main.cue create mode 100644 examples/tests/copy/valid/script/main.cue diff --git a/examples/repro-14/main.cue b/examples/repro-14/main.cue deleted file mode 100644 index b2ebe7df..00000000 --- a/examples/repro-14/main.cue +++ /dev/null @@ -1,13 +0,0 @@ -package main - -www: { - - source: { - #dagger: compute: [ - { - do: "fetch-container" - ref: "lalalalala", - }, - ] - } -} diff --git a/examples/tests/copy/invalid/cache/main.cue b/examples/tests/copy/invalid/cache/main.cue new file mode 100644 index 00000000..f9699c12 --- /dev/null +++ b/examples/tests/copy/invalid/cache/main.cue @@ -0,0 +1,49 @@ +package testing + +test1: { + string + + #dagger: { + compute: [ + { + do: "fetch-container" + ref: "busybox" + }, + { + do: "copy" + from: [{do: "fetch-container", ref: "alpine"}] + src: "/etc/issue" + dest: "/" + }, + { + do: "export" + source: "/issue" + format: "string" + }, + ] + } +} + +test2: { + string + + #dagger: { + compute: [ + { + do: "fetch-container" + ref: "busybox" + }, + { + do: "copy" + from: [{do: "fetch-container", ref: "busybox"}] + src: "/etc/issue" + dest: "/" + }, + { + do: "export" + source: "/issue" + format: "string" + }, + ] + } +} diff --git a/examples/tests/copy/valid/component/main.cue b/examples/tests/copy/valid/component/main.cue new file mode 100644 index 00000000..0ba7d1a4 --- /dev/null +++ b/examples/tests/copy/valid/component/main.cue @@ -0,0 +1,69 @@ +package testing + +component: #dagger: compute: [{ + do: "fetch-container" + ref: "alpine" +}, { + do: "exec" + args: ["sh", "-c", """ + printf lol > /id + """] + dir: "/" +}] + +test1: { + string + + #dagger: { + compute: [ + { + do: "fetch-container" + ref: "busybox" + }, + { + do: "copy" + from: component + src: "/id" + dest: "/" + }, + { + do: "export" + source: "/id" + format: "string" + }, + ] + } +} + +test2: { + string + + #dagger: { + compute: [ + { + do: "fetch-container" + ref: "busybox" + }, + { + do: "copy" + from: #dagger: compute: [{ + do: "fetch-container" + ref: "alpine" + }, { + do: "exec" + args: ["sh", "-c", """ + printf lol > /id + """] + dir: "/" + }] + src: "/id" + dest: "/" + }, + { + do: "export" + source: "/id" + format: "string" + }, + ] + } +} diff --git a/examples/tests/copy/valid/script/main.cue b/examples/tests/copy/valid/script/main.cue new file mode 100644 index 00000000..48f68903 --- /dev/null +++ b/examples/tests/copy/valid/script/main.cue @@ -0,0 +1,25 @@ +package testing + +test: { + string + + #dagger: { + compute: [ + { + do: "fetch-container" + ref: "busybox" + }, + { + do: "copy" + from: [{do: "fetch-container", ref: "busybox"}] + src: "/etc/issue" + dest: "/" + }, + { + do: "export" + source: "/issue" + format: "string" + }, + ] + } +} diff --git a/examples/tests/test-lib.sh b/examples/tests/test-lib.sh index 721b1b4b..34f5780e 100644 --- a/examples/tests/test-lib.sh +++ b/examples/tests/test-lib.sh @@ -126,3 +126,7 @@ test::one(){ [ "$ret" != 0 ] || logger::info " -> Success" return "$ret" } + +disable(){ + logger::warning "Test \"$2\" has been disabled." +} diff --git a/examples/tests/test.sh b/examples/tests/test.sh index 4e1fb474..3147f301 100755 --- a/examples/tests/test.sh +++ b/examples/tests/test.sh @@ -24,11 +24,11 @@ test::compute(){ "$dagger" compute "$d"/compute/invalid/struct test::one "Compute: noop should succeed" --exit=0 --stdout='{"empty":{},"realempty":{},"withprops":{}}' \ "$dagger" compute "$d"/compute/noop - # XXX https://github.com/blocklayerhq/dagger/issues/28 - #test::one "Compute: unresolved should fail" --exit=1 --stdout= \ - # "$dagger" compute "$d"/compute/invalid/undefined_prop test::one "Compute: simple should succeed" --exit=0 --stdout="{}" \ "$dagger" compute "$d"/compute/simple + + disable test::one "Compute: unresolved should fail (FIXME https://github.com/blocklayerhq/dagger/issues/28)" --exit=1 --stdout= \ + "$dagger" compute "$d"/compute/invalid/undefined_prop } test::fetchcontainer(){ @@ -43,11 +43,12 @@ test::fetchcontainer(){ "$dagger" compute "$d"/fetch-container/nonexistent/tag test::one "FetchContainer: non existent container digest" --exit=1 --stdout= \ "$dagger" compute "$d"/fetch-container/nonexistent/digest - # XXX https://github.com/blocklayerhq/dagger/issues/32 - this will fail once cached by buildkit - # test::one "FetchContainer: non existent container image with valid digest" --exit=1 --stdout= \ - # "$dagger" compute "$d"/fetch-container/nonexistent/image-with-valid-digest + test::one "FetchContainer: valid containers" --exit=0 \ "$dagger" compute "$d"/fetch-container/exist + + disable test::one "FetchContainer: non existent container image with valid digest (FIXME https://github.com/blocklayerhq/dagger/issues/32)" --exit=1 --stdout= \ + "$dagger" compute "$d"/fetch-container/nonexistent/image-with-valid-digest } test::fetchgit(){ @@ -84,23 +85,14 @@ test::exec(){ "$dagger" compute "$d"/exec/env/valid test::one "Exec: env with overlay" --exit=0 \ "$dagger" compute --input 'bar: "overlay environment"' "$d"/exec/env/overlay - # XXX broken right now: https://github.com/blocklayerhq/dagger/issues/30 - #test::one "Exec: non existent dir" --exit=0 --stdout={} \ - # "$dagger" compute "$d"/exec/dir/doesnotexist - #test::one "Exec: valid dir" --exit=0 --stdout={} \ - # "$dagger" compute "$d"/exec/dir/exist + + disable test::one "Exec: non existent dir (FIXME https://github.com/blocklayerhq/dagger/issues/30)" --exit=0 --stdout={} \ + "$dagger" compute "$d"/exec/dir/doesnotexist + disable test::one "Exec: valid dir (FIXME https://github.com/blocklayerhq/dagger/issues/30)" --exit=0 --stdout={} \ + "$dagger" compute "$d"/exec/dir/exist } test::export(){ - # XXX https://github.com/blocklayerhq/dagger/issues/36 - #test::one "Export: number" --exit=0 --stdout='{"test": -123.5}' \ - # "$dagger" compute "$d"/export/number - #test::one "Export: yaml" --exit=0 --stdout='XXXXXX' \ - # "$dagger" compute "$d"/export/yaml - # XXX https://github.com/blocklayerhq/dagger/issues/35 - #test::one "Export: bool" --exit=0 --stdout='{"test": false}' \ - # "$dagger" compute "$d"/export/bool - test::one "Export: json" --exit=0 --stdout='{"test":{"something":"something"}}' \ "$dagger" compute "$d"/export/json @@ -118,22 +110,44 @@ test::export(){ test::one "Export: invalid path" --exit=1 --stdout= \ "$dagger" compute "$d"/export/invalid/path + + disable test::one "Export: number (FIXME https://github.com/blocklayerhq/dagger/issues/36)" --exit=0 --stdout='{"test": -123.5}' \ + "$dagger" compute "$d"/export/number + disable test::one "Export: yaml (FIXME https://github.com/blocklayerhq/dagger/issues/36)" --exit=0 --stdout='XXXXXX' \ + "$dagger" compute "$d"/export/yaml + disable test::one "Export: bool (FIXME https://github.com/blocklayerhq/dagger/issues/35)" --exit=0 --stdout='{"test": false}' \ + "$dagger" compute "$d"/export/bool } +test::copy(){ + test::one "Copy: valid components" --exit=0 --stdout='{"component":{},"test1":"lol","test2":"lol"}' \ + "$dagger" compute "$d"/copy/valid/component + test::one "Copy: valid script" --exit=0 --stdout='{"component":{},"test1":"lol","test2":"lol"}' \ + "$dagger" compute "$d"/copy/valid/component + + disable test::one "Copy: invalid caching (FIXME https://github.com/blocklayerhq/dagger/issues/44)" --exit=1 --stdout= \ + "$dagger" compute "$d"/copy/invalid/cache +} + +test::local(){ + disable "" "There are no local tests right now (the feature is possibly not functioning at all: see https://github.com/blocklayerhq/dagger/issues/41)" +} + + test::all(){ local dagger="$1" + test::local "$dagger" + test::compute "$dagger" test::fetchcontainer "$dagger" test::fetchgit "$dagger" test::exec "$dagger" test::export "$dagger" + test::copy "$dagger" # TODO: exec mounts - # TODO: copy # TODO: load - # TODO: local - # TODO: export } case "${1:-all}" in