tests: migrate compute tests to bats
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
54ba2a2688
commit
ce2e00cfa2
72
tests/compute.bats
Normal file
72
tests/compute.bats
Normal file
@ -0,0 +1,72 @@
|
||||
setup() {
|
||||
load 'helpers'
|
||||
|
||||
common_setup
|
||||
}
|
||||
|
||||
@test "compute: simple" {
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/invalid/string
|
||||
assert_failure
|
||||
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/invalid/bool
|
||||
assert_failure
|
||||
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/invalid/int
|
||||
assert_failure
|
||||
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/invalid/struct
|
||||
assert_failure
|
||||
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/success/noop
|
||||
assert_success
|
||||
assert_line '{"empty":{}}'
|
||||
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/success/simple
|
||||
assert_success
|
||||
assert_line '{}'
|
||||
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/success/overload/flat
|
||||
assert_success
|
||||
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/success/overload/wrapped
|
||||
assert_success
|
||||
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/success/exec-nocache
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "compute: dependencies" {
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/dependencies/simple
|
||||
assert_success
|
||||
assert_line '{"A":{"result":"from A"},"B":{"result":"dependency from A"}}'
|
||||
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/dependencies/interpolation
|
||||
assert_success
|
||||
assert_line '{"A":{"result":"from A"},"B":{"result":"dependency from A"}}'
|
||||
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/dependencies/unmarshal
|
||||
assert_success
|
||||
assert_line '{"A":"{\"hello\": \"world\"}\n","B":{"result":"unmarshalled.hello=world"},"unmarshalled":{"hello":"world"}}'
|
||||
}
|
||||
|
||||
@test "compute: inputs" {
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/input/simple
|
||||
assert_success
|
||||
assert_line '{}'
|
||||
|
||||
run "$DAGGER" compute --input-string 'in=foobar' "$TESTDIR"/compute/input/simple
|
||||
assert_success
|
||||
assert_line '{"in":"foobar","test":"received: foobar"}'
|
||||
|
||||
run "$DAGGER" compute "$TESTDIR"/compute/input/default
|
||||
assert_success
|
||||
assert_line '{"in":"default input","test":"received: default input"}'
|
||||
|
||||
run "$DAGGER" compute --input-string 'in=foobar' "$TESTDIR"/compute/input/default
|
||||
assert_success
|
||||
assert_line '{"in":"foobar","test":"received: foobar"}'
|
||||
}
|
||||
|
||||
@test ".daggerignore" {
|
||||
"$DAGGER" compute --input-dir TestData="$TESTDIR"/compute/ignore/testdata "$TESTDIR"/compute/ignore
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o errexit -o errtrace -o functrace -o nounset -o pipefail
|
||||
|
||||
# Test Directory
|
||||
d=$(cd "$(dirname "${BASH_SOURCE[0]:-$PWD}")" 2>/dev/null 1>&2 && pwd)
|
||||
|
||||
test::compute(){
|
||||
local dagger="$1"
|
||||
|
||||
test::compute::simple "$dagger"
|
||||
test::compute::dependencies "$dagger"
|
||||
test::compute::input "$dagger"
|
||||
test::compute::daggerignore "$dagger"
|
||||
}
|
||||
|
||||
test::compute::simple(){
|
||||
local dagger="$1"
|
||||
|
||||
# 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= \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/bool
|
||||
test::one "Compute: invalid int should fail" --exit=1 --stdout= \
|
||||
"$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
|
||||
|
||||
# Compute: success
|
||||
test::one "Compute: noop should succeed" --exit=0 --stdout='{"empty":{}}' \
|
||||
"$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/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::one "Compute: Disabling the cache on exec should not compute twice when referenced by another key" --exit=0 \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/success/exec-nocache
|
||||
}
|
||||
|
||||
test::compute::dependencies(){
|
||||
local dagger="$1"
|
||||
|
||||
test::one "Dependencies: simple direct dependency" --exit=0 --stdout='{"A":{"result":"from A"},"B":{"result":"dependency from A"}}' \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/dependencies/simple
|
||||
test::one "Dependencies: interpolation" --exit=0 --stdout='{"A":{"result":"from A"},"B":{"result":"dependency from A"}}' \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/dependencies/interpolation
|
||||
test::one "Dependencies: json.Unmarshal" --exit=0 --stdout='{"A":"{\"hello\": \"world\"}\n","B":{"result":"unmarshalled.hello=world"},"unmarshalled":{"hello":"world"}}' \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/dependencies/unmarshal
|
||||
}
|
||||
|
||||
test::compute::input(){
|
||||
local dagger="$1"
|
||||
|
||||
# Compute: `--input-*`
|
||||
test::one "Compute: Input: missing input should skip execution" --exit=0 --stdout='{}' \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/input/simple
|
||||
|
||||
test::one "Compute: Input: simple input" --exit=0 --stdout='{"in":"foobar","test":"received: foobar"}' \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute --input-string 'in=foobar' "$d"/compute/input/simple
|
||||
|
||||
test::one "Compute: Input: default values" --exit=0 --stdout='{"in":"default input","test":"received: default input"}' \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/input/default
|
||||
|
||||
test::one "Compute: Input: override default value" --exit=0 --stdout='{"in":"foobar","test":"received: foobar"}' \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute --input-string 'in=foobar' "$d"/compute/input/default
|
||||
}
|
||||
|
||||
test::compute::daggerignore() {
|
||||
test::one "Dagger Ignore" --exit=0 \
|
||||
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute --input-dir TestData="$d"/compute/ignore/testdata "$d"/compute/ignore
|
||||
}
|
@ -16,14 +16,11 @@ d=$(cd "$(dirname "${BASH_SOURCE[0]:-$PWD}")" 2>/dev/null 1>&2 && pwd)
|
||||
# shellcheck source=/dev/null
|
||||
. "$d/test-lib.sh"
|
||||
# shellcheck source=/dev/null
|
||||
. "$d/test-compute.sh"
|
||||
# shellcheck source=/dev/null
|
||||
. "$d/test-stdlib.sh"
|
||||
|
||||
test::all(){
|
||||
local dagger="$1"
|
||||
|
||||
test::suite "compute" && test::compute "$dagger"
|
||||
test::suite "stdlib" && test::stdlib "$dagger"
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user