1003 test implementation
Signed-off-by: Guillaume de Rouville <guillaume.derouville@gmail.com>
This commit is contained in:
parent
6f0a0b4e0f
commit
ad2f9b3f17
5
Makefile
5
Makefile
@ -48,6 +48,11 @@ universe-test: dagger-debug
|
|||||||
yarn --cwd "./universe" install
|
yarn --cwd "./universe" install
|
||||||
DAGGER_BINARY="../cmd/dagger/dagger-debug" yarn --cwd "./universe" test
|
DAGGER_BINARY="../cmd/dagger/dagger-debug" yarn --cwd "./universe" test
|
||||||
|
|
||||||
|
.PHONY: doc-test
|
||||||
|
doc-test: dagger-debug
|
||||||
|
yarn --cwd "./docs/learn/tests" install
|
||||||
|
DAGGER_BINARY="$(shell pwd)/cmd/dagger/dagger-debug" yarn --cwd "./docs/learn/tests" test
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: dagger
|
install: dagger
|
||||||
go install ./cmd/dagger
|
go install ./cmd/dagger
|
||||||
|
1
docs/learn/tests/cue.mod/module.cue
Normal file
1
docs/learn/tests/cue.mod/module.cue
Normal file
@ -0,0 +1 @@
|
|||||||
|
module: ""
|
2
docs/learn/tests/cue.mod/pkg/.gitignore
vendored
Normal file
2
docs/learn/tests/cue.mod/pkg/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# dagger universe
|
||||||
|
alpha.dagger.io
|
29
docs/learn/tests/doc.bats
Normal file
29
docs/learn/tests/doc.bats
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
## Doc commands are being extracted from this file and helpers.
|
||||||
|
## Indentation is important, please append at the end
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
load 'helpers'
|
||||||
|
|
||||||
|
common_setup
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test 1003-get-started
|
||||||
|
@test "doc-1003-get-started" {
|
||||||
|
setup_example_sandbox "doc"
|
||||||
|
|
||||||
|
# Set examples private key
|
||||||
|
./import-tutorial-key.sh
|
||||||
|
|
||||||
|
# Collect url
|
||||||
|
dagger up
|
||||||
|
url=$(dagger query -f text url)
|
||||||
|
|
||||||
|
# More commands
|
||||||
|
dagger list
|
||||||
|
ls -l ./s3
|
||||||
|
dagger input list
|
||||||
|
|
||||||
|
# Check output
|
||||||
|
run curl $url
|
||||||
|
assert_output --partial "My Todo app"
|
||||||
|
}
|
89
docs/learn/tests/helpers.bash
Normal file
89
docs/learn/tests/helpers.bash
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
## Doc commands are being extracted from this file and helpers.
|
||||||
|
## Indentation is important, please append at the end
|
||||||
|
|
||||||
|
common_setup() {
|
||||||
|
load 'node_modules/bats-support/load'
|
||||||
|
load 'node_modules/bats-assert/load'
|
||||||
|
|
||||||
|
# Dagger Binary
|
||||||
|
# FIXME: `command -v` must be wrapped in a sub-bash,
|
||||||
|
# otherwise infinite recursion when DAGGER_BINARY is not set.
|
||||||
|
export DAGGER="${DAGGER_BINARY:-$(bash -c 'command -v dagger')}"
|
||||||
|
|
||||||
|
# Set the workspace to the universe directory (so tests can run from anywhere)
|
||||||
|
UNIVERSE="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
DAGGER_WORKSPACE="$UNIVERSE"
|
||||||
|
export DAGGER_WORKSPACE
|
||||||
|
|
||||||
|
# Force pretty printing for error reporting
|
||||||
|
DAGGER_LOG_FORMAT="pretty"
|
||||||
|
export DAGGER_LOG_FORMAT
|
||||||
|
|
||||||
|
# Sandbox workspace.
|
||||||
|
DAGGER_SANDBOX="$(mktemp -d -t dagger-workspace-XXXXXX)"
|
||||||
|
export DAGGER_SANDBOX
|
||||||
|
dagger init -w "$DAGGER_SANDBOX"
|
||||||
|
|
||||||
|
# allows the use of `sops`
|
||||||
|
SOPS_AGE_KEY_FILE=~/.config/dagger/keys.txt
|
||||||
|
export SOPS_AGE_KEY_FILE
|
||||||
|
}
|
||||||
|
|
||||||
|
# dagger helper to execute the right binary
|
||||||
|
dagger() {
|
||||||
|
"${DAGGER}" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# dagger helper to run doc examples in clean environment
|
||||||
|
setup_example_sandbox() {
|
||||||
|
# Tell Dagger not to use DAGGER WORKSPACE env var
|
||||||
|
unset DAGGER_WORKSPACE
|
||||||
|
|
||||||
|
export CODEBLOC_SRC="$(pwd)"
|
||||||
|
local tmpdir=$(mktemp -d)
|
||||||
|
cd $tmpdir
|
||||||
|
git clone https://github.com/dagger/examples
|
||||||
|
if [ "$1" = "doc" ]; then
|
||||||
|
cd examples/todoapp
|
||||||
|
cue mod init
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# copy an environment from the current workspace to the sandbox.
|
||||||
|
#
|
||||||
|
# this is needed if the test requires altering inputs without dirtying the
|
||||||
|
# current environment.
|
||||||
|
# Usage:
|
||||||
|
# copy_to_sandbox myenv
|
||||||
|
# dagger input secret -w "$DAGGER_SANDBOX" -e myenv "temporary change"
|
||||||
|
# dagger up -w "$DAGGER_SANDBOX" -e myenv
|
||||||
|
#
|
||||||
|
# To use testdata directory in tests, add the package name as second flag
|
||||||
|
# Usage:
|
||||||
|
# copy_to_sandbox myenv mypackage
|
||||||
|
copy_to_sandbox() {
|
||||||
|
local name="$1"
|
||||||
|
local source="$DAGGER_WORKSPACE"/.dagger/env/"$name"
|
||||||
|
local target="$DAGGER_SANDBOX"/.dagger/env/"$name"
|
||||||
|
|
||||||
|
cp -a "$source" "$target"
|
||||||
|
|
||||||
|
if [ -d "$2" ]; then
|
||||||
|
local package="$2"
|
||||||
|
local source_package="$DAGGER_WORKSPACE"/"$package"
|
||||||
|
local target_package="$DAGGER_SANDBOX"/
|
||||||
|
|
||||||
|
cp -a "$source_package" "$target_package"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if there is a local kubernetes cluster.
|
||||||
|
#
|
||||||
|
# This is need to do kubernetes test in the CI.
|
||||||
|
skip_unless_local_kube() {
|
||||||
|
if [ -f ~/.kube/config ] && grep -q "127.0.0.1" ~/.kube/config &> /dev/null; then
|
||||||
|
echo "Kubernetes available"
|
||||||
|
else
|
||||||
|
skip "local kubernetes cluster not available"
|
||||||
|
fi
|
||||||
|
}
|
12
docs/learn/tests/package.json
Normal file
12
docs/learn/tests/package.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"scripts": {
|
||||||
|
"test": "bats --report-formatter junit --jobs 4 ."
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"bats": "https://github.com/bats-core/bats-core#master",
|
||||||
|
"bats-assert": "https://github.com/bats-core/bats-assert",
|
||||||
|
"bats-support": "https://github.com/bats-core/bats-support"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user