changed workspace to project for tests

Signed-off-by: Richard Jones <richard@dagger.io>
This commit is contained in:
Richard Jones 2021-09-23 12:07:09 -06:00
parent 7061ac816e
commit 68f18887da
No known key found for this signature in database
GPG Key ID: CFB3A382EB166F4C
7 changed files with 116 additions and 116 deletions

View File

@ -15,13 +15,13 @@ setup() {
"$DAGGER_SANDBOX"/import-tutorial-key.sh "$DAGGER_SANDBOX"/import-tutorial-key.sh
# Collect url # Collect url
dagger -w "$DAGGER_SANDBOX" up dagger --project "$DAGGER_SANDBOX" up
url=$(dagger -w "$DAGGER_SANDBOX" query -f text url) url=$(dagger --project "$DAGGER_SANDBOX" query -f text url)
# More commands # More commands
dagger -w "$DAGGER_SANDBOX" list dagger --project "$DAGGER_SANDBOX" list
ls -l "$DAGGER_SANDBOX"/s3 ls -l "$DAGGER_SANDBOX"/s3
dagger -w "$DAGGER_SANDBOX" input list dagger --project "$DAGGER_SANDBOX" input list
# Check output # Check output
run curl "$url" run curl "$url"
@ -33,25 +33,25 @@ setup() {
# Follow tutorial # Follow tutorial
mkdir -p "$DAGGER_SANDBOX"/multibucket mkdir -p "$DAGGER_SANDBOX"/multibucket
cp "$DAGGER_WORKSPACE"/multibucket/source.cue "$DAGGER_SANDBOX"/multibucket cp "$DAGGER_PROJECT"/multibucket/source.cue "$DAGGER_SANDBOX"/multibucket
cp "$DAGGER_WORKSPACE"/multibucket/yarn.cue "$DAGGER_SANDBOX"/multibucket cp "$DAGGER_PROJECT"/multibucket/yarn.cue "$DAGGER_SANDBOX"/multibucket
cp "$DAGGER_WORKSPACE"/multibucket/netlify.cue "$DAGGER_SANDBOX"/multibucket cp "$DAGGER_PROJECT"/multibucket/netlify.cue "$DAGGER_SANDBOX"/multibucket
dagger -w "$DAGGER_SANDBOX" doc alpha.dagger.io/netlify dagger --project "$DAGGER_SANDBOX" doc alpha.dagger.io/netlify
dagger -w "$DAGGER_SANDBOX" doc alpha.dagger.io/js/yarn dagger --project "$DAGGER_SANDBOX" doc alpha.dagger.io/js/yarn
# Initialize new env # Initialize new env
dagger -w "$DAGGER_SANDBOX" new 'multibucket' -p "$DAGGER_SANDBOX"/multibucket dagger --project "$DAGGER_SANDBOX" new 'multibucket' -p "$DAGGER_SANDBOX"/multibucket
# Copy corresponding env # Copy corresponding env
cp -r "$DAGGER_WORKSPACE"/.dagger/env/multibucket "$DAGGER_SANDBOX"/.dagger/env/ cp -r "$DAGGER_PROJECT"/.dagger/env/multibucket "$DAGGER_SANDBOX"/.dagger/env/
# Add missing src input # Add missing src input
dagger -w "$DAGGER_SANDBOX" -e multibucket input dir src "$DAGGER_SANDBOX" dagger --project "$DAGGER_SANDBOX" -e multibucket input dir src "$DAGGER_SANDBOX"
# Run test # Run test
dagger -w "$DAGGER_SANDBOX" -e multibucket up dagger --project "$DAGGER_SANDBOX" -e multibucket up
url=$(dagger -w "$DAGGER_SANDBOX" -e multibucket query -f text site.netlify.deployUrl) url=$(dagger --project "$DAGGER_SANDBOX" -e multibucket query -f text site.netlify.deployUrl)
# Check output # Check output
run curl "$url" run curl "$url"
@ -63,19 +63,19 @@ setup() {
# Follow tutorial # Follow tutorial
mkdir -p "$DAGGER_SANDBOX"/gcpcloudrun mkdir -p "$DAGGER_SANDBOX"/gcpcloudrun
cp "$DAGGER_WORKSPACE"/gcpcloudrun/source.cue "$DAGGER_SANDBOX"/gcpcloudrun cp "$DAGGER_PROJECT"/gcpcloudrun/source.cue "$DAGGER_SANDBOX"/gcpcloudrun
# Initialize new env # Initialize new env
dagger -w "$DAGGER_SANDBOX" new 'gcpcloudrun' -p "$DAGGER_SANDBOX"/gcpcloudrun dagger --project "$DAGGER_SANDBOX" new 'gcpcloudrun' -p "$DAGGER_SANDBOX"/gcpcloudrun
# Copy corresponding env # Copy corresponding env
cp -r "$DAGGER_WORKSPACE"/.dagger/env/gcpcloudrun "$DAGGER_SANDBOX"/.dagger/env/ cp -r "$DAGGER_PROJECT"/.dagger/env/gcpcloudrun "$DAGGER_SANDBOX"/.dagger/env/
# Add missing src input # Add missing src input
dagger -w "$DAGGER_SANDBOX" -e gcpcloudrun input dir src "$DAGGER_SANDBOX" dagger --project "$DAGGER_SANDBOX" -e gcpcloudrun input dir src "$DAGGER_SANDBOX"
# Run test # Run test
run dagger -w "$DAGGER_SANDBOX" -e gcpcloudrun up run dagger --project "$DAGGER_SANDBOX" -e gcpcloudrun up
assert_success assert_success
} }
@ -88,10 +88,10 @@ setup() {
# copy_to_sandbox kube-kind-basic kube-kind # copy_to_sandbox kube-kind-basic kube-kind
# # Add kubeconfig # # Add kubeconfig
# dagger -w "$DAGGER_SANDBOX" -e kube-kind-basic input text kubeconfig -f "$HOME"/.kube/config # dagger --project "$DAGGER_SANDBOX" -e kube-kind-basic input text kubeconfig -f "$HOME"/.kube/config
# # Up deployment # # Up deployment
# dagger -w "$DAGGER_SANDBOX" -e kube-kind-basic up # dagger --project "$DAGGER_SANDBOX" -e kube-kind-basic up
# # Check deployment # # Check deployment
# kubectl describe deployment todoapp | grep 'True' # kubectl describe deployment todoapp | grep 'True'
@ -105,10 +105,10 @@ setup() {
# copy_to_sandbox kube-kind-deployment kube-kind # copy_to_sandbox kube-kind-deployment kube-kind
# # Add kubeconfig # # Add kubeconfig
# dagger -w "$DAGGER_SANDBOX" -e kube-kind-deployment input text kubeconfig -f "$HOME"/.kube/config # dagger --project "$DAGGER_SANDBOX" -e kube-kind-deployment input text kubeconfig -f "$HOME"/.kube/config
# # Up deployment # # Up deployment
# dagger -w "$DAGGER_SANDBOX" -e kube-kind-deployment up # dagger --project "$DAGGER_SANDBOX" -e kube-kind-deployment up
# # Check deployment # # Check deployment
# kubectl describe deployment todoapp | grep 'True' # kubectl describe deployment todoapp | grep 'True'
@ -122,10 +122,10 @@ setup() {
# copy_to_sandbox kube-kind-cue-manifest kube-kind # copy_to_sandbox kube-kind-cue-manifest kube-kind
# # Add kubeconfig # # Add kubeconfig
# dagger -w "$DAGGER_SANDBOX" -e kube-kind-cue-manifest input text kubeconfig -f "$HOME"/.kube/config # dagger --project "$DAGGER_SANDBOX" -e kube-kind-cue-manifest input text kubeconfig -f "$HOME"/.kube/config
# # Up deployment # # Up deployment
# dagger -w "$DAGGER_SANDBOX" -e kube-kind-cue-manifest up # dagger --project "$DAGGER_SANDBOX" -e kube-kind-cue-manifest up
# # Check deployment # # Check deployment
# kubectl describe deployment todoapp | grep 'True' # kubectl describe deployment todoapp | grep 'True'
@ -142,20 +142,20 @@ setup() {
# copy_to_sandbox kube-aws-basic kube-aws # copy_to_sandbox kube-aws-basic kube-aws
# # Up deployment # # Up deployment
# dagger -w "$DAGGER_SANDBOX" -e kube-aws-basic up # dagger --project "$DAGGER_SANDBOX" -e kube-aws-basic up
# #################### DEPLOYMENT #################### # #################### DEPLOYMENT ####################
# # Copy deployment to sandbox # # Copy deployment to sandbox
# copy_to_sandbox kube-aws-deployment kube-aws # copy_to_sandbox kube-aws-deployment kube-aws
# # Up deployment # # Up deployment
# dagger -w "$DAGGER_SANDBOX" -e kube-aws-deployment up # dagger --project "$DAGGER_SANDBOX" -e kube-aws-deployment up
# #################### CUE MANIFEST #################### # #################### CUE MANIFEST ####################
# # Copy deployment to sandbox # # Copy deployment to sandbox
# copy_to_sandbox kube-aws-cue-manifest kube-aws # copy_to_sandbox kube-aws-cue-manifest kube-aws
# # Up deployment # # Up deployment
# dagger -w "$DAGGER_SANDBOX" -e kube-aws-cue-manifest up # dagger --project "$DAGGER_SANDBOX" -e kube-aws-cue-manifest up
} }
@test "doc-1007-kube-gcp" { @test "doc-1007-kube-gcp" {
@ -165,20 +165,20 @@ setup() {
# copy_to_sandbox kube-gcp-basic kube-gcp # copy_to_sandbox kube-gcp-basic kube-gcp
# # Up deployment # # Up deployment
# dagger -w "$DAGGER_SANDBOX" -e kube-gcp-basic up # dagger --project "$DAGGER_SANDBOX" -e kube-gcp-basic up
# #################### DEPLOYMENT #################### # #################### DEPLOYMENT ####################
# # Copy deployment to sandbox # # Copy deployment to sandbox
# copy_to_sandbox kube-gcp-deployment kube-gcp # copy_to_sandbox kube-gcp-deployment kube-gcp
# # Up deployment # # Up deployment
# dagger -w "$DAGGER_SANDBOX" -e kube-gcp-deployment up # dagger --project "$DAGGER_SANDBOX" -e kube-gcp-deployment up
# #################### CUE MANIFEST #################### # #################### CUE MANIFEST ####################
# # Copy deployment to sandbox # # Copy deployment to sandbox
# copy_to_sandbox kube-gcp-cue-manifest kube-gcp # copy_to_sandbox kube-gcp-cue-manifest kube-gcp
# # Up deployment # # Up deployment
# dagger -w "$DAGGER_SANDBOX" -e kube-gcp-cue-manifest up # dagger --project "$DAGGER_SANDBOX" -e kube-gcp-cue-manifest up
} }
@test "doc-1008-aws-cloudformation" { @test "doc-1008-aws-cloudformation" {
@ -188,96 +188,96 @@ setup() {
### Create a basic plan ### Create a basic plan
## Construct ## Construct
mkdir -p "$DAGGER_SANDBOX"/cloudformation mkdir -p "$DAGGER_SANDBOX"/cloudformation
cp "$DAGGER_WORKSPACE"/cloudformation/template.cue "$DAGGER_SANDBOX"/cloudformation cp "$DAGGER_PROJECT"/cloudformation/template.cue "$DAGGER_SANDBOX"/cloudformation
# Cloudformation relay # Cloudformation relay
dagger -w "$DAGGER_SANDBOX" doc alpha.dagger.io/aws/cloudformation dagger --project "$DAGGER_SANDBOX" doc alpha.dagger.io/aws/cloudformation
cp "$DAGGER_WORKSPACE"/cloudformation/source-begin.cue "$DAGGER_SANDBOX"/cloudformation/source.cue cp "$DAGGER_PROJECT"/cloudformation/source-begin.cue "$DAGGER_SANDBOX"/cloudformation/source.cue
# Initialize new env # Initialize new env
dagger -w "$DAGGER_SANDBOX" new 'cloudformation' -p "$DAGGER_SANDBOX"/cloudformation dagger --project "$DAGGER_SANDBOX" new 'cloudformation' -p "$DAGGER_SANDBOX"/cloudformation
# Finish template setup # Finish template setup
cp "$DAGGER_WORKSPACE"/cloudformation/source-end.cue "$DAGGER_SANDBOX"/cloudformation/source.cue cp "$DAGGER_PROJECT"/cloudformation/source-end.cue "$DAGGER_SANDBOX"/cloudformation/source.cue
# Copy corresponding env # Copy corresponding env
cp -r "$DAGGER_WORKSPACE"/.dagger/env/cloudformation "$DAGGER_SANDBOX"/.dagger/env/ cp -r "$DAGGER_PROJECT"/.dagger/env/cloudformation "$DAGGER_SANDBOX"/.dagger/env/
# Run test # Run test
dagger -w "$DAGGER_SANDBOX" -e cloudformation up dagger --project "$DAGGER_SANDBOX" -e cloudformation up
stackName=$(dagger -w "$DAGGER_SANDBOX" -e cloudformation query cfnStackName -f text) stackName=$(dagger --project "$DAGGER_SANDBOX" -e cloudformation query cfnStackName -f text)
## Cleanup ## Cleanup
# Place back empty source # Place back empty source
cp "$DAGGER_WORKSPACE"/cloudformation/source-begin.cue "$DAGGER_SANDBOX"/cloudformation/source.cue cp "$DAGGER_PROJECT"/cloudformation/source-begin.cue "$DAGGER_SANDBOX"/cloudformation/source.cue
cp "$DAGGER_WORKSPACE"/cloudformation/deletion.cue "$DAGGER_SANDBOX"/cloudformation/deletion.cue cp "$DAGGER_PROJECT"/cloudformation/deletion.cue "$DAGGER_SANDBOX"/cloudformation/deletion.cue
# Prepare and run cloudformation cleanup # Prepare and run cloudformation cleanup
dagger -w "$DAGGER_SANDBOX" -e cloudformation input text stackRemoval.stackName "$stackName" dagger --project "$DAGGER_SANDBOX" -e cloudformation input text stackRemoval.stackName "$stackName"
dagger -w "$DAGGER_SANDBOX" -e cloudformation up dagger --project "$DAGGER_SANDBOX" -e cloudformation up
### Template part ### Template part
## Create convert.cue ## Create convert.cue
cp "$DAGGER_WORKSPACE"/cloudformation/template/convert.cue "$DAGGER_SANDBOX"/cloudformation/convert.cue cp "$DAGGER_PROJECT"/cloudformation/template/convert.cue "$DAGGER_SANDBOX"/cloudformation/convert.cue
rm "$DAGGER_SANDBOX"/cloudformation/source.cue "$DAGGER_SANDBOX"/cloudformation/deletion.cue rm "$DAGGER_SANDBOX"/cloudformation/source.cue "$DAGGER_SANDBOX"/cloudformation/deletion.cue
## Retrieve Unmarshalled JSON ## Retrieve Unmarshalled JSON
dagger -w "$DAGGER_SANDBOX" query -e cloudformation s3Template dagger --project "$DAGGER_SANDBOX" query -e cloudformation s3Template
## Remove convert.cue ## Remove convert.cue
rm "$DAGGER_SANDBOX"/cloudformation/convert.cue rm "$DAGGER_SANDBOX"/cloudformation/convert.cue
## Store the output ## Store the output
cp "$DAGGER_WORKSPACE"/cloudformation/template/template-begin.cue "$DAGGER_SANDBOX"/cloudformation/template.cue cp "$DAGGER_PROJECT"/cloudformation/template/template-begin.cue "$DAGGER_SANDBOX"/cloudformation/template.cue
# Inspect conf # Inspect conf
dagger -w "$DAGGER_SANDBOX" query -e cloudformation template -f text dagger --project "$DAGGER_SANDBOX" query -e cloudformation template -f text
cp "$DAGGER_WORKSPACE"/cloudformation/template/deployment.cue "$DAGGER_SANDBOX"/cloudformation/deployment.cue cp "$DAGGER_PROJECT"/cloudformation/template/deployment.cue "$DAGGER_SANDBOX"/cloudformation/deployment.cue
cp "$DAGGER_WORKSPACE"/cloudformation/template/template-end.cue "$DAGGER_SANDBOX"/cloudformation/template.cue cp "$DAGGER_PROJECT"/cloudformation/template/template-end.cue "$DAGGER_SANDBOX"/cloudformation/template.cue
cp "$DAGGER_WORKSPACE"/cloudformation/source-end.cue "$DAGGER_SANDBOX"/cloudformation/source.cue cp "$DAGGER_PROJECT"/cloudformation/source-end.cue "$DAGGER_SANDBOX"/cloudformation/source.cue
# Deploy again # Deploy again
dagger -w "$DAGGER_SANDBOX" -e cloudformation query template -f text dagger --project "$DAGGER_SANDBOX" -e cloudformation query template -f text
dagger -w "$DAGGER_SANDBOX" -e cloudformation up dagger --project "$DAGGER_SANDBOX" -e cloudformation up
dagger -w "$DAGGER_SANDBOX" -e cloudformation output list dagger --project "$DAGGER_SANDBOX" -e cloudformation output list
## Cleanup again ## Cleanup again
stackName=$(dagger -w "$DAGGER_SANDBOX" -e cloudformation query cfnStackName -f text) stackName=$(dagger --project "$DAGGER_SANDBOX" -e cloudformation query cfnStackName -f text)
rm -rf "$DAGGER_SANDBOX"/cloudformation/* rm -rf "$DAGGER_SANDBOX"/cloudformation/*
# Place back empty source # Place back empty source
cp "$DAGGER_WORKSPACE"/cloudformation/source-begin.cue "$DAGGER_SANDBOX"/cloudformation/source.cue cp "$DAGGER_PROJECT"/cloudformation/source-begin.cue "$DAGGER_SANDBOX"/cloudformation/source.cue
cp "$DAGGER_WORKSPACE"/cloudformation/deletion.cue "$DAGGER_SANDBOX"/cloudformation/deletion.cue cp "$DAGGER_PROJECT"/cloudformation/deletion.cue "$DAGGER_SANDBOX"/cloudformation/deletion.cue
# Prepare and run cloudformation cleanup # Prepare and run cloudformation cleanup
dagger -w "$DAGGER_SANDBOX" -e cloudformation input text stackRemoval.stackName "$stackName" dagger --project "$DAGGER_SANDBOX" -e cloudformation input text stackRemoval.stackName "$stackName"
dagger -w "$DAGGER_SANDBOX" -e cloudformation up dagger --project "$DAGGER_SANDBOX" -e cloudformation up
} }
@test "doc-1010-dev-cue-package" { @test "doc-1010-dev-cue-package" {
# Initializing workspace # Initializing project
mkdir -p "$DAGGER_SANDBOX"/workspace mkdir -p "$DAGGER_SANDBOX"/project
# Writing package # Writing package
# dagger init # The sandbox is already init # dagger init # The sandbox is already init
mkdir -p "$DAGGER_SANDBOX"/cue.mod/pkg/github.com/tjovicic/gcpcloudrun mkdir -p "$DAGGER_SANDBOX"/cue.mod/pkg/github.com/tjovicic/gcpcloudrun
cp "$DAGGER_WORKSPACE"/dev-cue-package/source.cue "$DAGGER_SANDBOX"/cue.mod/pkg/github.com/tjovicic/gcpcloudrun/source.cue cp "$DAGGER_PROJECT"/dev-cue-package/source.cue "$DAGGER_SANDBOX"/cue.mod/pkg/github.com/tjovicic/gcpcloudrun/source.cue
cp "$DAGGER_WORKSPACE"/dev-cue-package/script.sh "$DAGGER_SANDBOX"/workspace/script.sh cp "$DAGGER_PROJECT"/dev-cue-package/script.sh "$DAGGER_SANDBOX"/project/script.sh
# We remove the last line of the script, as bats cannot expand dagger # We remove the last line of the script, as bats cannot expand dagger
# to dagger() bats helper func inside bash files # to dagger() bats helper func inside bash files
sed '$d' <"$DAGGER_SANDBOX"/workspace/script.sh >"$DAGGER_SANDBOX"/tmpFile sed '$d' <"$DAGGER_SANDBOX"/project/script.sh >"$DAGGER_SANDBOX"/tmpFile
mv "$DAGGER_SANDBOX"/tmpFile "$DAGGER_SANDBOX"/workspace/script.sh mv "$DAGGER_SANDBOX"/tmpFile "$DAGGER_SANDBOX"/project/script.sh
chmod +x "$DAGGER_SANDBOX"/workspace/script.sh chmod +x "$DAGGER_SANDBOX"/project/script.sh
"$DAGGER_SANDBOX"/workspace/script.sh "$DAGGER_SANDBOX"/project/script.sh
# Sync file from documentation # Sync file from documentation
rsync -a test "$DAGGER_SANDBOX" rsync -a test "$DAGGER_SANDBOX"
# Command removed from script.sh above # Command removed from script.sh above
dagger -w "$DAGGER_SANDBOX" new staging -p "$DAGGER_SANDBOX"/test dagger --project "$DAGGER_SANDBOX" new staging -p "$DAGGER_SANDBOX"/test
run dagger up -w "$DAGGER_SANDBOX" -e staging run dagger up --project "$DAGGER_SANDBOX" -e staging
assert_output --partial "input=run.gcpConfig.serviceKey" assert_output --partial "input=run.gcpConfig.serviceKey"
# Clean script.sh output # Clean script.sh output

View File

@ -10,19 +10,19 @@ common_setup() {
# otherwise infinite recursion when DAGGER_BINARY is not set. # otherwise infinite recursion when DAGGER_BINARY is not set.
export DAGGER="${DAGGER_BINARY:-$(bash -c 'command -v dagger')}" export DAGGER="${DAGGER_BINARY:-$(bash -c 'command -v dagger')}"
# Set the workspace to the universe directory (so tests can run from anywhere) # Set the project to the universe directory (so tests can run from anywhere)
UNIVERSE="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" UNIVERSE="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
DAGGER_WORKSPACE="$UNIVERSE" DAGGER_PROJECT="$UNIVERSE"
export DAGGER_WORKSPACE export DAGGER_PROJECT
# Force pretty printing for error reporting # Force pretty printing for error reporting
DAGGER_LOG_FORMAT="pretty" DAGGER_LOG_FORMAT="pretty"
export DAGGER_LOG_FORMAT export DAGGER_LOG_FORMAT
# Sandbox workspace. # Sandbox project.
DAGGER_SANDBOX="$(mktemp -d -t dagger-workspace-XXXXXX)" DAGGER_SANDBOX="$(mktemp -d -t dagger-project-XXXXXX)"
export DAGGER_SANDBOX export DAGGER_SANDBOX
dagger init -w "$DAGGER_SANDBOX" dagger init --project "$DAGGER_SANDBOX"
# allows the use of `sops` # allows the use of `sops`
SOPS_AGE_KEY_FILE=~/.config/dagger/keys.txt SOPS_AGE_KEY_FILE=~/.config/dagger/keys.txt
@ -43,28 +43,28 @@ setup_example_sandbox() {
} }
# copy an environment from the current workspace to the sandbox. # copy an environment from the current project to the sandbox.
# #
# this is needed if the test requires altering inputs without dirtying the # this is needed if the test requires altering inputs without dirtying the
# current environment. # current environment.
# Usage: # Usage:
# copy_to_sandbox myenv # copy_to_sandbox myenv
# dagger input secret -w "$DAGGER_SANDBOX" -e myenv "temporary change" # dagger input secret -w "$DAGGER_SANDBOX" -e myenv "temporary change"
# dagger up -w "$DAGGER_SANDBOX" -e myenv # dagger up --project "$DAGGER_SANDBOX" -e myenv
# #
# To use testdata directory in tests, add the package name as second flag # To use testdata directory in tests, add the package name as second flag
# Usage: # Usage:
# copy_to_sandbox myenv mypackage # copy_to_sandbox myenv mypackage
copy_to_sandbox() { copy_to_sandbox() {
local name="$1" local name="$1"
local source="$DAGGER_WORKSPACE"/.dagger/env/"$name" local source="$DAGGER_PROJECT"/.dagger/env/"$name"
local target="$DAGGER_SANDBOX"/.dagger/env/"$name" local target="$DAGGER_SANDBOX"/.dagger/env/"$name"
cp -a "$source" "$target" cp -a "$source" "$target"
if [ -d "$2" ]; then if [ -d "$2" ]; then
local package="$2" local package="$2"
local source_package="$DAGGER_WORKSPACE"/"$package" local source_package="$DAGGER_PROJECT"/"$package"
local target_package="$DAGGER_SANDBOX"/ local target_package="$DAGGER_SANDBOX"/
cp -a "$source_package" "$target_package" cp -a "$source_package" "$target_package"

View File

@ -7,19 +7,19 @@ common_setup() {
# otherwise infinite recursion when DAGGER_BINARY is not set. # otherwise infinite recursion when DAGGER_BINARY is not set.
export DAGGER="${DAGGER_BINARY:-$(bash -c 'command -v dagger')}" export DAGGER="${DAGGER_BINARY:-$(bash -c 'command -v dagger')}"
# Set the workspace to the universe directory (so tests can run from anywhere) # Set the project to the universe directory (so tests can run from anywhere)
UNIVERSE="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" UNIVERSE="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
DAGGER_WORKSPACE="$UNIVERSE" DAGGER_PROJECT="$UNIVERSE"
export DAGGER_WORKSPACE export DAGGER_PROJECT
# Force pretty printing for error reporting # Force pretty printing for error reporting
DAGGER_LOG_FORMAT="pretty" DAGGER_LOG_FORMAT="pretty"
export DAGGER_LOG_FORMAT export DAGGER_LOG_FORMAT
# Sandbox workspace. # Sandbox project.
DAGGER_SANDBOX="$(mktemp -d -t dagger-workspace-XXXXXX)" DAGGER_SANDBOX="$(mktemp -d -t dagger-project-XXXXXX)"
export DAGGER_SANDBOX export DAGGER_SANDBOX
dagger init -w "$DAGGER_SANDBOX" dagger init --project "$DAGGER_SANDBOX"
# allows the use of `sops` # allows the use of `sops`
SOPS_AGE_KEY_FILE=~/.config/dagger/keys.txt SOPS_AGE_KEY_FILE=~/.config/dagger/keys.txt
@ -31,28 +31,28 @@ dagger() {
"${DAGGER}" "$@" "${DAGGER}" "$@"
} }
# copy an environment from the current workspace to the sandbox. # copy an environment from the current project to the sandbox.
# #
# this is needed if the test requires altering inputs without dirtying the # this is needed if the test requires altering inputs without dirtying the
# current environment. # current environment.
# Usage: # Usage:
# copy_to_sandbox myenv # copy_to_sandbox myenv
# dagger input secret -w "$DAGGER_SANDBOX" -e myenv "temporary change" # dagger input secret -w "$DAGGER_SANDBOX" -e myenv "temporary change"
# dagger up -w "$DAGGER_SANDBOX" -e myenv # dagger up --project "$DAGGER_SANDBOX" -e myenv
# #
# To use testdata directory in tests, add the package name as second flag # To use testdata directory in tests, add the package name as second flag
# Usage: # Usage:
# copy_to_sandbox myenv mypackage # copy_to_sandbox myenv mypackage
copy_to_sandbox() { copy_to_sandbox() {
local name="$1" local name="$1"
local source="$DAGGER_WORKSPACE"/.dagger/env/"$name" local source="$DAGGER_PROJECT"/.dagger/env/"$name"
local target="$DAGGER_SANDBOX"/.dagger/env/"$name" local target="$DAGGER_SANDBOX"/.dagger/env/"$name"
cp -a "$source" "$target" cp -a "$source" "$target"
if [ -d "$2" ]; then if [ -d "$2" ]; then
local package="$2" local package="$2"
local source_package="$DAGGER_WORKSPACE"/"$package" local source_package="$DAGGER_PROJECT"/"$package"
local target_package="$DAGGER_SANDBOX"/ local target_package="$DAGGER_SANDBOX"/
cp -a "$source_package" "$target_package" cp -a "$source_package" "$target_package"

View File

@ -133,12 +133,12 @@ setup() {
copy_to_sandbox kubernetes-deployment kubernetes copy_to_sandbox kubernetes-deployment kubernetes
# Set kubeconfig # Set kubeconfig
dagger -w "$DAGGER_SANDBOX" -e kubernetes-deployment input text TestKubeconfig -f "$HOME"/.kube/config dagger --project "$DAGGER_SANDBOX" -e kubernetes-deployment input text TestKubeconfig -f "$HOME"/.kube/config
dagger -w "$DAGGER_SANDBOX" -e kubernetes-deployment up dagger --project "$DAGGER_SANDBOX" -e kubernetes-deployment up
# Unset kubeconfig # Unset kubeconfig
dagger -w "$DAGGER_SANDBOX" -e kubernetes-deployment input unset TestKubeconfig dagger --project "$DAGGER_SANDBOX" -e kubernetes-deployment input unset TestKubeconfig
} }
@test "kubernetes: kustomize" { @test "kubernetes: kustomize" {
@ -152,12 +152,12 @@ setup() {
copy_to_sandbox kubernetes-helm kubernetes copy_to_sandbox kubernetes-helm kubernetes
# Set kubeconfig # Set kubeconfig
dagger -w "$DAGGER_SANDBOX" -e kubernetes-helm input text TestKubeconfig -f "$HOME"/.kube/config dagger --project "$DAGGER_SANDBOX" -e kubernetes-helm input text TestKubeconfig -f "$HOME"/.kube/config
dagger -w "$DAGGER_SANDBOX" -e kubernetes-helm up dagger --project "$DAGGER_SANDBOX" -e kubernetes-helm up
# Unset kubeconfig # Unset kubeconfig
dagger -w "$DAGGER_SANDBOX" -e kubernetes-helm input unset TestKubeconfig dagger --project "$DAGGER_SANDBOX" -e kubernetes-helm input unset TestKubeconfig
} }
@test "google cloud: gcr" { @test "google cloud: gcr" {
@ -195,23 +195,23 @@ setup() {
copy_to_sandbox terraform terraform copy_to_sandbox terraform terraform
# Add the var and try again # Add the var and try again
run dagger -w "$DAGGER_SANDBOX" -e terraform input text TestTerraform.apply.tfvars.input "42" run dagger --project "$DAGGER_SANDBOX" -e terraform input text TestTerraform.apply.tfvars.input "42"
run dagger -w "$DAGGER_SANDBOX" -e terraform up run dagger --project "$DAGGER_SANDBOX" -e terraform up
assert_success assert_success
# ensure the tfvar was passed correctly # ensure the tfvar was passed correctly
run dagger -w "$DAGGER_SANDBOX" query -e terraform TestTerraform.apply.output.input.value -f text run dagger --project "$DAGGER_SANDBOX" query -e terraform TestTerraform.apply.output.input.value -f text
assert_success assert_success
assert_output "42" assert_output "42"
# ensure the random value is always the same # ensure the random value is always the same
# this proves we're effectively using the s3 backend # this proves we're effectively using the s3 backend
run dagger -w "$DAGGER_SANDBOX" query -e terraform TestTerraform.apply.output.random.value -f json run dagger --project "$DAGGER_SANDBOX" query -e terraform TestTerraform.apply.output.random.value -f json
assert_success assert_success
assert_output "36" assert_output "36"
# Unset input # Unset input
run dagger -w "$DAGGER_SANDBOX" -e terraform input unset TestTerraform.apply.tfvars.input run dagger --project "$DAGGER_SANDBOX" -e terraform input unset TestTerraform.apply.tfvars.input
assert_success assert_success
} }

View File

@ -42,7 +42,7 @@ setup() {
@test "dagger new: modules" { @test "dagger new: modules" {
"$DAGGER" init "$DAGGER" init
cp -a "$TESTDIR"/cli/input/simple/* "$DAGGER_WORKSPACE" cp -a "$TESTDIR"/cli/input/simple/* "$DAGGER_PROJECT"
"$DAGGER" new "a" "$DAGGER" new "a"
"$DAGGER" new "b" "$DAGGER" new "b"
@ -61,7 +61,7 @@ setup() {
assert_success assert_success
assert_output "b" assert_output "b"
# run ls -la "$DAGGER_WORKSPACE" # run ls -la "$DAGGER_PROJECT"
# assert_failure # assert_failure
} }
@ -70,7 +70,7 @@ setup() {
@test "dagger new: packages" { @test "dagger new: packages" {
"$DAGGER" init "$DAGGER" init
cp -a "$TESTDIR"/cli/packages/* "$DAGGER_WORKSPACE" cp -a "$TESTDIR"/cli/packages/* "$DAGGER_PROJECT"
"$DAGGER" new "a" --package alpha.dagger.io/test/a "$DAGGER" new "a" --package alpha.dagger.io/test/a
"$DAGGER" new "b" --package alpha.dagger.io/test/b "$DAGGER" new "b" --package alpha.dagger.io/test/b
@ -293,13 +293,13 @@ setup() {
dagger_new_with_plan input "$TESTDIR"/cli/input/artifact dagger_new_with_plan input "$TESTDIR"/cli/input/artifact
# input dir outside the workspace # input dir outside the project
run "$DAGGER" input -e "input" dir "source" /tmp run "$DAGGER" input -e "input" dir "source" /tmp
assert_failure assert_failure
# input dir inside the workspace # input dir inside the project
cp -R "$TESTDIR"/cli/input/artifact/testdata/ "$DAGGER_WORKSPACE"/testdata cp -R "$TESTDIR"/cli/input/artifact/testdata/ "$DAGGER_PROJECT"/testdata
"$DAGGER" input -e "input" dir "source" "$DAGGER_WORKSPACE"/testdata "$DAGGER" input -e "input" dir "source" "$DAGGER_PROJECT"/testdata
"$DAGGER" up -e "input" "$DAGGER" up -e "input"
run "$DAGGER" -l error query -e "input" run "$DAGGER" -l error query -e "input"
assert_success assert_success
@ -331,8 +331,8 @@ setup() {
run [ -d "$TESTDIR"/cli/input/ignore/testdata/.dagger ] run [ -d "$TESTDIR"/cli/input/ignore/testdata/.dagger ]
assert_success assert_success
cp -R "$TESTDIR"/cli/input/ignore/testdata/ "$DAGGER_WORKSPACE"/testdata cp -R "$TESTDIR"/cli/input/ignore/testdata/ "$DAGGER_PROJECT"/testdata
"$DAGGER" input -e "input" dir "source" "$DAGGER_WORKSPACE"/testdata "$DAGGER" input -e "input" dir "source" "$DAGGER_PROJECT"/testdata
"$DAGGER" up -e "input" "$DAGGER" up -e "input"
assert_success assert_success
} }

View File

@ -11,7 +11,7 @@ setup() {
# new-style tests: use 'dagger up' # new-style tests: use 'dagger up'
# #
# For new tests, please adopt new-style. # For new tests, please adopt new-style.
# NOTE: you will need to 'unset DAGGER_WORKSPACE' # NOTE: you will need to 'unset DAGGER_PROJECT'
# at the beginning of each new-style test. # at the beginning of each new-style test.
@test "core: inputs & outputs" { @test "core: inputs & outputs" {
@ -26,7 +26,7 @@ setup() {
assert_output --partial 'dir' assert_output --partial 'dir'
# Set dir input # Set dir input
dagger -e test-core input dir dir "$DAGGER_WORKSPACE" dagger -e test-core input dir dir "$DAGGER_PROJECT"
# Set text input # Set text input
dagger -e test-core input text name Bob dagger -e test-core input text name Bob
@ -160,5 +160,5 @@ setup() {
} }
@test "compute: exclude" { @test "compute: exclude" {
"$DAGGER" up -w "$TESTDIR"/compute/exclude "$DAGGER" up --project "$TESTDIR"/compute/exclude
} }

View File

@ -10,8 +10,8 @@ common_setup() {
DAGGER_LOG_FORMAT="pretty" DAGGER_LOG_FORMAT="pretty"
export DAGGER_LOG_FORMAT export DAGGER_LOG_FORMAT
DAGGER_WORKSPACE="$(mktemp -d -t dagger-workspace-XXXXXX)" DAGGER_PROJECT="$(mktemp -d -t dagger-project-XXXXXX)"
export DAGGER_WORKSPACE export DAGGER_PROJECT
SOPS_AGE_KEY_FILE=~/.config/dagger/keys.txt SOPS_AGE_KEY_FILE=~/.config/dagger/keys.txt
export SOPS_AGE_KEY_FILE export SOPS_AGE_KEY_FILE
@ -21,7 +21,7 @@ dagger_new_with_plan() {
local name="$1" local name="$1"
local sourcePlan="$2" local sourcePlan="$2"
cp -a "$sourcePlan"/* "$DAGGER_WORKSPACE" cp -a "$sourcePlan"/* "$DAGGER_PROJECT"
"$DAGGER" new "$name" "$DAGGER" new "$name"
} }
@ -29,8 +29,8 @@ dagger_new_with_plan() {
dagger_new_with_env() { dagger_new_with_env() {
local sourcePlan="$1" local sourcePlan="$1"
"$DAGGER" init -w "$DAGGER_WORKSPACE" "$DAGGER" init --project "$DAGGER_PROJECT"
rsync -av "$sourcePlan"/ "$DAGGER_WORKSPACE" rsync -av "$sourcePlan"/ "$DAGGER_PROJECT"
} }
# dagger helper to execute the right binary # dagger helper to execute the right binary