2021-06-17 16:11:10 +02:00
|
|
|
# Test core Dagger features & types
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
load 'helpers'
|
|
|
|
|
|
|
|
common_setup
|
|
|
|
}
|
|
|
|
|
2021-06-22 17:07:15 +02:00
|
|
|
# This file combines 2 types of tests:
|
|
|
|
# old-style tests: use 'dagger compute'
|
|
|
|
# new-style tests: use 'dagger up'
|
|
|
|
#
|
|
|
|
# For new tests, please adopt new-style.
|
2021-09-23 20:07:09 +02:00
|
|
|
# NOTE: you will need to 'unset DAGGER_PROJECT'
|
2021-06-22 17:07:15 +02:00
|
|
|
# at the beginning of each new-style test.
|
|
|
|
|
2021-06-21 11:07:18 +02:00
|
|
|
@test "core: inputs & outputs" {
|
2021-07-01 19:42:52 +02:00
|
|
|
dagger init
|
|
|
|
|
|
|
|
dagger_new_with_plan test-core "$TESTDIR"/core/inputs-outputs
|
|
|
|
|
|
|
|
# List available inputs
|
2021-08-17 16:58:29 +02:00
|
|
|
run dagger -e test-core input list --show-optional
|
2021-07-01 19:42:52 +02:00
|
|
|
assert_success
|
|
|
|
assert_output --partial 'name'
|
|
|
|
assert_output --partial 'dir'
|
|
|
|
|
|
|
|
# Set dir input
|
2021-09-23 20:07:09 +02:00
|
|
|
dagger -e test-core input dir dir "$DAGGER_PROJECT"
|
2021-07-01 19:42:52 +02:00
|
|
|
|
|
|
|
# Set text input
|
|
|
|
dagger -e test-core input text name Bob
|
|
|
|
run dagger -e test-core up
|
|
|
|
assert_success
|
|
|
|
assert_output --partial 'Hello, Bob!'
|
|
|
|
|
|
|
|
run dagger -e test-core output list
|
|
|
|
assert_success
|
|
|
|
assert_output --partial 'message "Hello, Bob!"'
|
|
|
|
|
|
|
|
# Unset text input
|
|
|
|
dagger -e test-core input unset name
|
|
|
|
run dagger -e test-core up
|
|
|
|
assert_success
|
|
|
|
assert_output --partial 'Hello, world!'
|
2021-06-17 16:11:10 +02:00
|
|
|
}
|
2021-06-21 11:07:18 +02:00
|
|
|
|
2021-06-22 17:07:15 +02:00
|
|
|
|
|
|
|
@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"}'
|
|
|
|
|
|
|
|
run "$DAGGER" compute --input-string=foobar "$TESTDIR"/compute/input/default
|
|
|
|
assert_failure
|
|
|
|
assert_output --partial 'failed to parse input: input-string'
|
|
|
|
|
|
|
|
run "$DAGGER" compute --input-dir=foobar "$TESTDIR"/compute/input/default
|
|
|
|
assert_failure
|
|
|
|
assert_output --partial 'failed to parse input: input-dir'
|
|
|
|
|
|
|
|
run "$DAGGER" compute --input-git=foobar "$TESTDIR"/compute/input/default
|
|
|
|
assert_failure
|
|
|
|
assert_output --partial 'failed to parse input: input-git'
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "compute: secrets" {
|
|
|
|
# secrets used as environment variables must fail
|
|
|
|
run "$DAGGER" compute "$TESTDIR"/compute/secrets/invalid/env
|
|
|
|
assert_failure
|
|
|
|
assert_line --partial "conflicting values"
|
|
|
|
|
|
|
|
# strings passed as secrets must fail
|
|
|
|
run "$DAGGER" compute "$TESTDIR"/compute/secrets/invalid/string
|
|
|
|
assert_failure
|
|
|
|
|
|
|
|
# Setting a text input for a secret value should fail
|
|
|
|
run "$DAGGER" compute --input-string 'mySecret=SecretValue' "$TESTDIR"/compute/secrets/simple
|
|
|
|
assert_failure
|
|
|
|
|
|
|
|
# Now test with an actual secret and make sure it works
|
|
|
|
"$DAGGER" init
|
|
|
|
dagger_new_with_plan secrets "$TESTDIR"/compute/secrets/simple
|
|
|
|
"$DAGGER" input secret mySecret SecretValue
|
|
|
|
run "$DAGGER" up
|
|
|
|
assert_success
|
|
|
|
|
|
|
|
# Make sure the secret doesn't show in dagger query
|
|
|
|
run "$DAGGER" query mySecret.id -f text
|
|
|
|
assert_success
|
2021-09-10 23:36:17 +02:00
|
|
|
assert_output --partial "secret=mySecret;hash="
|
2021-06-22 17:07:15 +02:00
|
|
|
}
|
|
|
|
|
2021-09-18 00:17:28 +02:00
|
|
|
@test "core: stream" {
|
2021-09-17 20:51:06 +02:00
|
|
|
dagger init
|
|
|
|
|
2021-09-18 00:17:28 +02:00
|
|
|
dagger_new_with_plan test-stream "$TESTDIR"/core/stream
|
2021-09-17 20:51:06 +02:00
|
|
|
|
|
|
|
# Set dir input
|
|
|
|
"$DAGGER" input socket dockersocket /var/run/docker.sock
|
|
|
|
|
|
|
|
"$DAGGER" up
|
2021-06-22 17:07:15 +02:00
|
|
|
}
|
|
|
|
|
2021-10-22 21:55:00 +02:00
|
|
|
@test "core: arch config" {
|
|
|
|
dagger init
|
|
|
|
|
|
|
|
# Test for amd64 architecture
|
|
|
|
dagger_new_with_plan test-amd "$TESTDIR"/core/arch-config "linux/amd64"
|
|
|
|
|
|
|
|
# Set arch expected value
|
|
|
|
"$DAGGER" -e test-amd input text targetArch "x86_64"
|
|
|
|
|
|
|
|
# Up amd
|
|
|
|
"$DAGGER" -e test-amd up
|
|
|
|
|
|
|
|
# Test for amd64 architecture
|
|
|
|
dagger_new_with_plan test-arm "$TESTDIR"/core/arch-config "linux/arm64"
|
|
|
|
|
|
|
|
# Set arch expected value
|
|
|
|
"$DAGGER" -e test-arm input text targetArch "aarch64"
|
|
|
|
|
|
|
|
# Up arm
|
|
|
|
"$DAGGER" -e test-arm up
|
|
|
|
}
|
|
|
|
|
2021-06-22 17:07:15 +02:00
|
|
|
@test "compute: exclude" {
|
2021-09-23 20:07:09 +02:00
|
|
|
"$DAGGER" up --project "$TESTDIR"/compute/exclude
|
2021-06-22 17:07:15 +02:00
|
|
|
}
|