This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/tests/cli.bats

307 lines
7.7 KiB
Plaintext
Raw Normal View History

setup() {
load 'helpers'
common_setup
}
@test "dagger list" {
run "$DAGGER" list
assert_success
assert_output ""
"$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
run "$DAGGER" list
assert_success
assert_output --partial "simple"
}
@test "dagger new --plan-dir" {
run "$DAGGER" list
assert_success
assert_output ""
"$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
# duplicate name
run "$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
assert_failure
# verify the plan works
"$DAGGER" up -e "simple"
# verify we have the right plan
run "$DAGGER" query -f cue -e "simple" -c -f json
assert_success
assert_output --partial '{
"bar": "another value",
"computed": "test",
"foo": "value"
}'
}
@test "dagger new --plan-git" {
"$DAGGER" new --plan-git https://github.com/samalba/dagger-test.git simple
"$DAGGER" up -e "simple"
run "$DAGGER" query -f cue -e "simple" -c
assert_success
assert_output --partial '{
foo: "value"
bar: "another value"
}'
}
@test "dagger query" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
run "$DAGGER" query -l error -e "simple"
assert_success
assert_output '{
"bar": "another value",
"foo": "value"
}'
# concrete should fail at this point since we haven't up'd
run "$DAGGER" query -e "simple" -c
assert_failure
# target
run "$DAGGER" -l error query -e "simple" foo
assert_success
assert_output '"value"'
# ensure computed values show up
"$DAGGER" up -e "simple"
run "$DAGGER" -l error query -e "simple"
assert_success
assert_output --partial '"computed": "test"'
# concrete should now work
"$DAGGER" query -e "simple" -c
# --no-computed should yield the same result as before
run "$DAGGER" query -l error --no-computed -e "simple"
assert_success
assert_output '{
"bar": "another value",
"foo": "value"
}'
# --no-plan should give us only the computed values
run "$DAGGER" query -l error --no-plan -e "simple"
assert_success
assert_output '{
"computed": "test"
}'
}
@test "dagger plan" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/simple simple
# plan dir
"$DAGGER" -e "simple" plan dir "$TESTDIR"/cli/simple
run "$DAGGER" -e "simple" query
assert_success
assert_output --partial '"foo": "value"'
# plan git
"$DAGGER" -e "simple" plan git https://github.com/samalba/dagger-test.git
run "$DAGGER" -e "simple" query
assert_success
assert_output --partial '"foo": "value"'
}
@test "dagger input text" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
# simple input
"$DAGGER" input -e "input" text "input" "my input"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" input
assert_success
assert_output '"my input"'
# unset simple input
"$DAGGER" input -e "input" unset "input"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" input
assert_success
assert_output 'null'
# nested input
"$DAGGER" input -e "input" text "nested.input" "nested input"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" nested
assert_success
assert_output '{
"input": "nested input"
}'
# unset nested input
"$DAGGER" input -e "input" unset "nested.input"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" nested
assert_success
assert_output 'null'
# file input
"$DAGGER" input -e "input" text "input" -f "$TESTDIR"/cli/input/simple/testdata/input.txt
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" input
assert_success
assert_output '"from file\n"'
# unset file input
"$DAGGER" input -e "input" unset "input"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" input
assert_success
assert_output 'null'
# invalid file
run "$DAGGER" input -e "input" text "input" -f "$TESTDIR"/cli/input/simple/testdata/notexist
assert_failure
# stdin input
echo -n "from stdin" | "$DAGGER" input -e "input" text "input" -f -
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" input
assert_success
assert_output '"from stdin"'
# unset stdin input
"$DAGGER" input -e "input" unset "input"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" input
assert_success
assert_output 'null'
}
@test "dagger input json" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
# simple json
"$DAGGER" input -e "input" json "structured" '{"a": "foo", "b": 42}'
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" structured
assert_success
assert_output '{
"a": "foo",
"b": 42
}'
# unset simple json
"$DAGGER" input -e "input" unset "structured"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" structured
assert_success
assert_output 'null'
# json from file
"$DAGGER" input -e "input" json "structured" -f "$TESTDIR"/cli/input/simple/testdata/input.json
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" structured
assert_success
assert_output '{
"a": "from file",
"b": 42
}'
# unset json from file
"$DAGGER" input -e "input" unset "structured"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" structured
assert_success
assert_output 'null'
}
@test "dagger input yaml" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
# simple yaml
"$DAGGER" input -e "input" yaml "structured" '{"a": "foo", "b": 42}'
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" structured
assert_success
assert_output '{
"a": "foo",
"b": 42
}'
# unset simple yaml
"$DAGGER" input -e "input" unset "structured"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" structured
assert_success
assert_output 'null'
# yaml from file
"$DAGGER" input -e "input" yaml "structured" -f "$TESTDIR"/cli/input/simple/testdata/input.yaml
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" structured
assert_success
assert_output '{
"a": "from file",
"b": 42
}'
# unset yaml from file
"$DAGGER" input -e "input" unset "structured"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" structured
assert_success
assert_output 'null'
}
@test "dagger input dir" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
# input dir
"$DAGGER" input -e "input" dir "source" "$TESTDIR"/cli/input/artifact/testdata
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input"
assert_success
assert_output '{
"bar": "thisisatest\n",
"foo": "bar",
"source": {}
}'
# unset dir
"$DAGGER" input -e "input" unset "source"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input"
assert_success
assert_output '{
"foo": "bar"
}'
}
@test "dagger input git" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
# input git
"$DAGGER" input -e "input" git "source" https://github.com/samalba/dagger-test-simple.git
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input"
assert_output '{
"bar": "testgit\n",
"foo": "bar",
"source": {}
}'
# unset input git
"$DAGGER" input -e "input" unset "source"
"$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input"
assert_output '{
"foo": "bar"
}'
}
@test "dagger input scan" {
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/scan "scan"
# TODO "scan" option isn't implemented
run "$DAGGER" input scan -e "input"
assert_success
}