2021-01-14 22:50:54 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -o errexit -o errtrace -o functrace -o nounset -o pipefail
|
|
|
|
|
|
|
|
# Source the lib
|
|
|
|
readonly d=$(cd "$(dirname "${BASH_SOURCE[0]:-$PWD}")" 2>/dev/null 1>&2 && pwd)
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
. "$d/test-lib.sh"
|
|
|
|
|
|
|
|
# Point this to your dagger binary
|
|
|
|
readonly DAGGER_BINARY="${DAGGER_BINARY:-$d/../../cmd/dagger/dagger}"
|
2021-01-21 00:58:57 +01:00
|
|
|
# The default arguments are a no-op, but having "anything" is a little cheat necessary for "${DAGGER_BINARY_ARGS[@]}" to not be empty down there
|
|
|
|
DAGGER_BINARY_ARGS="${DAGGER_BINARY_ARGS:---log-format json}"
|
|
|
|
read -ra DAGGER_BINARY_ARGS <<< "${DAGGER_BINARY_ARGS:-}"
|
|
|
|
readonly DAGGER_BINARY_ARGS
|
2021-01-14 22:50:54 +01:00
|
|
|
|
|
|
|
test::compute(){
|
|
|
|
local dagger="$1"
|
|
|
|
|
|
|
|
# Compute
|
|
|
|
test::one "Compute: invalid string should fail" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/string
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "Compute: invalid bool should fail" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/bool
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "Compute: invalid int should fail" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/int
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "Compute: invalid struct should fail" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/struct
|
2021-01-15 02:39:16 +01:00
|
|
|
test::one "Compute: noop should succeed" --exit=0 --stdout='{"empty":{},"realempty":{},"withprops":{}}' \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/noop
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "Compute: simple should succeed" --exit=0 --stdout="{}" \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/simple
|
2021-01-16 00:10:28 +01:00
|
|
|
|
|
|
|
disable test::one "Compute: unresolved should fail (FIXME https://github.com/blocklayerhq/dagger/issues/28)" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/undefined_prop
|
2021-01-14 22:50:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
test::fetchcontainer(){
|
|
|
|
local dagger="$1"
|
|
|
|
|
|
|
|
# Fetch container
|
|
|
|
test::one "FetchContainer: missing ref" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-container/invalid
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "FetchContainer: non existent container image" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-container/nonexistent/image
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "FetchContainer: non existent container tag" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-container/nonexistent/tag
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "FetchContainer: non existent container digest" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-container/nonexistent/digest
|
2021-01-16 00:10:28 +01:00
|
|
|
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "FetchContainer: valid containers" --exit=0 \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-container/exist
|
2021-01-16 00:10:28 +01:00
|
|
|
|
|
|
|
disable test::one "FetchContainer: non existent container image with valid digest (FIXME https://github.com/blocklayerhq/dagger/issues/32)" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-container/nonexistent/image-with-valid-digest
|
2021-01-14 22:50:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
test::fetchgit(){
|
|
|
|
local dagger="$1"
|
|
|
|
|
|
|
|
# Fetch git
|
|
|
|
test::one "FetchGit: valid" --exit=0 --stdout="{}" \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-git/exist
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "FetchGit: invalid" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-git/invalid
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "FetchGit: non existent remote" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-git/nonexistent/remote
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "FetchGit: non existent ref" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-git/nonexistent/ref
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "FetchGit: non existent bork" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-git/nonexistent/bork
|
2021-01-14 22:50:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
test::exec(){
|
|
|
|
# Exec
|
|
|
|
test::one "Exec: invalid" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/invalid
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "Exec: error" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/error
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "Exec: simple" --exit=0 --stdout={} \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/simple
|
2021-01-14 22:50:54 +01:00
|
|
|
# XXX should run twice and test that the string "always output" is visible with DOCKER_OUTPUT=1
|
|
|
|
# Alternatively, use export, but this would test multiple things then...
|
|
|
|
test::one "Exec: always" --exit=0 --stdout={} \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/always
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "Exec: env invalid" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/env/invalid
|
2021-01-14 22:50:54 +01:00
|
|
|
test::one "Exec: env valid" --exit=0 --stdout={} \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/env/valid
|
2021-01-15 03:55:23 +01:00
|
|
|
test::one "Exec: env with overlay" --exit=0 \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute --input 'bar: "overlay environment"' "$d"/exec/env/overlay
|
2021-01-16 00:10:28 +01:00
|
|
|
|
|
|
|
disable test::one "Exec: non existent dir (FIXME https://github.com/blocklayerhq/dagger/issues/30)" --exit=0 --stdout={} \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/dir/doesnotexist
|
2021-01-16 00:10:28 +01:00
|
|
|
disable test::one "Exec: valid dir (FIXME https://github.com/blocklayerhq/dagger/issues/30)" --exit=0 --stdout={} \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/exec/dir/exist
|
2021-01-14 22:50:54 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 04:56:48 +01:00
|
|
|
test::export(){
|
|
|
|
test::one "Export: json" --exit=0 --stdout='{"test":{"something":"something"}}' \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/export/json
|
2021-01-15 04:56:48 +01:00
|
|
|
|
|
|
|
test::one "Export: string" --exit=0 --stdout='{"test":"something"}' \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/export/string
|
2021-01-15 04:56:48 +01:00
|
|
|
|
|
|
|
test::one "Export: string with additional constraint success" --exit=0 --stdout='{"test":"something"}' \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/export/withvalidation
|
2021-01-15 04:56:48 +01:00
|
|
|
|
2021-01-16 01:24:17 +01:00
|
|
|
test::one "Export: many concurrent" --exit=0 \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/export/concurrency
|
2021-01-16 01:24:17 +01:00
|
|
|
|
2021-01-15 04:56:48 +01:00
|
|
|
test::one "Export: does not pass additional validation" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/export/invalid/validation
|
2021-01-15 04:56:48 +01:00
|
|
|
|
|
|
|
test::one "Export: invalid format" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/export/invalid/format
|
2021-01-15 04:56:48 +01:00
|
|
|
|
|
|
|
test::one "Export: invalid path" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/export/invalid/path
|
2021-01-16 00:10:28 +01:00
|
|
|
|
|
|
|
disable test::one "Export: number (FIXME https://github.com/blocklayerhq/dagger/issues/36)" --exit=0 --stdout='{"test": -123.5}' \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/export/number
|
2021-01-16 00:10:28 +01:00
|
|
|
disable test::one "Export: yaml (FIXME https://github.com/blocklayerhq/dagger/issues/36)" --exit=0 --stdout='XXXXXX' \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/export/yaml
|
2021-01-16 00:10:28 +01:00
|
|
|
disable test::one "Export: bool (FIXME https://github.com/blocklayerhq/dagger/issues/35)" --exit=0 --stdout='{"test": false}' \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/export/bool
|
2021-01-15 04:56:48 +01:00
|
|
|
}
|
|
|
|
|
2021-01-16 00:10:28 +01:00
|
|
|
test::copy(){
|
|
|
|
test::one "Copy: valid components" --exit=0 --stdout='{"component":{},"test1":"lol","test2":"lol"}' \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/copy/valid/component
|
2021-01-16 01:24:17 +01:00
|
|
|
test::one "Copy: valid script" --exit=0 \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/copy/valid/script
|
2021-01-16 00:10:28 +01:00
|
|
|
|
|
|
|
disable test::one "Copy: invalid caching (FIXME https://github.com/blocklayerhq/dagger/issues/44)" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/copy/invalid/cache
|
2021-01-16 00:10:28 +01:00
|
|
|
}
|
|
|
|
|
2021-01-16 01:24:17 +01:00
|
|
|
test::load(){
|
|
|
|
test::one "Load: valid components" --exit=0 --stdout='{"component":{},"test1":"lol","test2":"lol"}' \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/load/valid/component
|
2021-01-16 01:24:17 +01:00
|
|
|
test::one "Load: valid script" --exit=0 \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/load/valid/script
|
2021-01-16 01:24:17 +01:00
|
|
|
|
|
|
|
test::one "Load: invalid caching (FIXME https://github.com/blocklayerhq/dagger/issues/44)" --exit=1 --stdout= \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/load/invalid/cache
|
2021-01-16 01:24:17 +01:00
|
|
|
}
|
|
|
|
|
2021-01-16 00:10:28 +01:00
|
|
|
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)"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-16 01:24:17 +01:00
|
|
|
test::mount(){
|
|
|
|
disable test::one "Mount: tmpfs (FIXME https://github.com/blocklayerhq/dagger/issues/46)" --exit=0 \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/mount/valid/tmpfs
|
2021-01-16 01:24:17 +01:00
|
|
|
|
|
|
|
disable test::one "Mount: cache (FIXME https://github.com/blocklayerhq/dagger/issues/46)" --exit=0 \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/mount/valid/cache
|
2021-01-16 01:24:17 +01:00
|
|
|
|
|
|
|
disable test::one "Mount: component (FIXME https://github.com/blocklayerhq/dagger/issues/46)" --exit=0 \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/mount/valid/component
|
2021-01-16 01:24:17 +01:00
|
|
|
|
|
|
|
disable test::one "Mount: script (FIXME https://github.com/blocklayerhq/dagger/issues/46)" --exit=0 \
|
2021-01-21 00:58:57 +01:00
|
|
|
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/mount/valid/script
|
2021-01-16 01:24:17 +01:00
|
|
|
}
|
|
|
|
|
2021-01-14 22:50:54 +01:00
|
|
|
test::all(){
|
|
|
|
local dagger="$1"
|
|
|
|
|
2021-01-16 01:24:17 +01:00
|
|
|
test::load "$dagger"
|
|
|
|
test::mount "$dagger"
|
2021-01-16 00:10:28 +01:00
|
|
|
|
2021-01-16 01:24:17 +01:00
|
|
|
test::copy "$dagger"
|
|
|
|
test::local "$dagger"
|
2021-01-14 22:50:54 +01:00
|
|
|
test::compute "$dagger"
|
|
|
|
test::fetchcontainer "$dagger"
|
|
|
|
test::fetchgit "$dagger"
|
|
|
|
test::exec "$dagger"
|
2021-01-15 04:56:48 +01:00
|
|
|
test::export "$dagger"
|
2021-01-14 22:50:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
case "${1:-all}" in
|
|
|
|
# Help
|
|
|
|
--help)
|
|
|
|
echo "Run all known tests:"
|
|
|
|
echo " ./test.sh"
|
|
|
|
echo "Run a specific cue module with expectations (all flags are optional if you just expect the command to succeed with no output validation:"
|
|
|
|
echo " ./test.sh cuefolder --exit=1 --stderr=lala --stdout=foo"
|
|
|
|
;;
|
|
|
|
# Run all tests
|
|
|
|
"all")
|
|
|
|
test::all "$DAGGER_BINARY"
|
|
|
|
;;
|
|
|
|
# Anything else means a single / custom test
|
|
|
|
*)
|
|
|
|
test::one "on demand $1" "$DAGGER_BINARY" compute "$@"
|
|
|
|
;;
|
|
|
|
esac
|