Improve test policy for examples
Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
parent
02e7cd3f59
commit
e7a738211f
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
mkdir test
|
mkdir -p test
|
||||||
|
|
||||||
cat > test/source.cue << EOF
|
cat > test/source.cue << EOF
|
||||||
package test
|
package test
|
||||||
|
@ -9,70 +9,73 @@ setup() {
|
|||||||
|
|
||||||
# Test 1003-get-started
|
# Test 1003-get-started
|
||||||
@test "doc-1003-get-started" {
|
@test "doc-1003-get-started" {
|
||||||
setup_example_sandbox "doc"
|
setup_example_sandbox
|
||||||
|
|
||||||
# Set examples private key
|
# Set examples private key
|
||||||
./import-tutorial-key.sh
|
"$DAGGER_SANDBOX"/import-tutorial-key.sh
|
||||||
|
|
||||||
# Collect url
|
# Collect url
|
||||||
dagger up
|
dagger -w "$DAGGER_SANDBOX" up
|
||||||
url=$(dagger query -f text url)
|
url=$(dagger -w "$DAGGER_SANDBOX" query -f text url)
|
||||||
|
|
||||||
# More commands
|
# More commands
|
||||||
dagger list
|
dagger -w "$DAGGER_SANDBOX" list
|
||||||
ls -l ./s3
|
ls -l "$DAGGER_SANDBOX"/s3
|
||||||
dagger input list
|
dagger -w "$DAGGER_SANDBOX" input list
|
||||||
|
|
||||||
# Check output
|
# Check output
|
||||||
run curl $url
|
run curl "$url"
|
||||||
assert_output --partial "My Todo app"
|
assert_output --partial "My Todo app"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "doc-1004-first-env" {
|
@test "doc-1004-first-env" {
|
||||||
setup_example_sandbox "doc"
|
setup_example_sandbox
|
||||||
|
|
||||||
# Follow tutorial
|
# Follow tutorial
|
||||||
mkdir multibucket
|
mkdir -p "$DAGGER_SANDBOX"/multibucket
|
||||||
cp $CODEBLOC_SRC/multibucket/source.cue multibucket
|
cp "$DAGGER_WORKSPACE"/multibucket/source.cue "$DAGGER_SANDBOX"/multibucket
|
||||||
cp $CODEBLOC_SRC/multibucket/yarn.cue multibucket
|
cp "$DAGGER_WORKSPACE"/multibucket/yarn.cue "$DAGGER_SANDBOX"/multibucket
|
||||||
cp $CODEBLOC_SRC/multibucket/netlify.cue multibucket
|
cp "$DAGGER_WORKSPACE"/multibucket/netlify.cue "$DAGGER_SANDBOX"/multibucket
|
||||||
|
|
||||||
dagger doc alpha.dagger.io/netlify
|
dagger -w "$DAGGER_SANDBOX" doc alpha.dagger.io/netlify
|
||||||
dagger doc alpha.dagger.io/js/yarn
|
dagger -w "$DAGGER_SANDBOX" doc alpha.dagger.io/js/yarn
|
||||||
|
|
||||||
# Initialize new env
|
# Initialize new env
|
||||||
dagger new 'multibucket' -p ./multibucket
|
dagger -w "$DAGGER_SANDBOX" new 'multibucket' -p "$DAGGER_SANDBOX"/multibucket
|
||||||
|
|
||||||
# Copy corresponding env
|
# Copy corresponding env
|
||||||
cp -r $CODEBLOC_SRC/.dagger/env/multibucket .dagger/env/
|
cp -r "$DAGGER_WORKSPACE"/.dagger/env/multibucket "$DAGGER_SANDBOX"/.dagger/env/
|
||||||
|
|
||||||
# Add missing src input
|
# Add missing src input
|
||||||
dagger -e multibucket input dir src .
|
dagger -w "$DAGGER_SANDBOX" -e multibucket input dir src "$DAGGER_SANDBOX"
|
||||||
|
|
||||||
# Run test
|
# Run test
|
||||||
dagger -e multibucket up
|
dagger -w "$DAGGER_SANDBOX" -e multibucket up
|
||||||
url=$(dagger -e multibucket query -f text site.netlify.deployUrl)
|
url=$(dagger -w "$DAGGER_SANDBOX" -e multibucket query -f text site.netlify.deployUrl)
|
||||||
|
|
||||||
# Check output :
|
# Check output
|
||||||
run curl $url
|
run curl "$url"
|
||||||
assert_output --partial "./static/css/main.9149988f.chunk.css"
|
assert_output --partial "./static/css/main.9149988f.chunk.css"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "doc-1006-google-cloud-run" {
|
@test "doc-1006-google-cloud-run" {
|
||||||
setup_example_sandbox "doc"
|
setup_example_sandbox
|
||||||
|
|
||||||
mkdir gcpcloudrun
|
# Follow tutorial
|
||||||
cp $CODEBLOC_SRC/gcpcloudrun/source.cue gcpcloudrun
|
mkdir -p "$DAGGER_SANDBOX"/gcpcloudrun
|
||||||
|
cp "$DAGGER_WORKSPACE"/gcpcloudrun/source.cue "$DAGGER_SANDBOX"/gcpcloudrun
|
||||||
|
|
||||||
# Initialize new env
|
# Initialize new env
|
||||||
dagger new 'gcpcloudrun' -p gcpcloudrun
|
dagger -w "$DAGGER_SANDBOX" new 'gcpcloudrun' -p "$DAGGER_SANDBOX"/gcpcloudrun
|
||||||
|
|
||||||
# Copy corresponding env
|
# Copy corresponding env
|
||||||
cp -r $CODEBLOC_SRC/.dagger/env/gcpcloudrun .dagger/env/
|
cp -r "$DAGGER_WORKSPACE"/.dagger/env/gcpcloudrun "$DAGGER_SANDBOX"/.dagger/env/
|
||||||
|
|
||||||
# Add missing src input
|
# Add missing src input
|
||||||
dagger -e gcpcloudrun input dir src .
|
dagger -w "$DAGGER_SANDBOX" -e gcpcloudrun input dir src "$DAGGER_SANDBOX"
|
||||||
|
|
||||||
# Run test
|
# Run test
|
||||||
run dagger -e gcpcloudrun up
|
run dagger -w "$DAGGER_SANDBOX" -e gcpcloudrun up
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,93 +180,103 @@ setup() {
|
|||||||
|
|
||||||
@test "doc-1008-aws-cloudformation" {
|
@test "doc-1008-aws-cloudformation" {
|
||||||
skip_unless_local_localstack
|
skip_unless_local_localstack
|
||||||
setup_example_sandbox "doc"
|
setup_example_sandbox
|
||||||
|
|
||||||
### Create a basic plan
|
### Create a basic plan
|
||||||
## Construct
|
## Construct
|
||||||
mkdir cloudformation
|
mkdir -p "$DAGGER_SANDBOX"/cloudformation
|
||||||
cp $CODEBLOC_SRC/cloudformation/template.cue cloudformation
|
cp "$DAGGER_WORKSPACE"/cloudformation/template.cue "$DAGGER_SANDBOX"/cloudformation
|
||||||
|
|
||||||
# Cloudformation relay
|
# Cloudformation relay
|
||||||
dagger doc alpha.dagger.io/aws/cloudformation
|
dagger -w "$DAGGER_SANDBOX" doc alpha.dagger.io/aws/cloudformation
|
||||||
cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue
|
cp "$DAGGER_WORKSPACE"/cloudformation/source-begin.cue "$DAGGER_SANDBOX"/cloudformation/source.cue
|
||||||
|
|
||||||
# Initialize new env
|
# Initialize new env
|
||||||
dagger new 'cloudformation' -p cloudformation
|
dagger -w "$DAGGER_SANDBOX" new 'cloudformation' -p "$DAGGER_SANDBOX"/cloudformation
|
||||||
|
|
||||||
# Finish template setup
|
# Finish template setup
|
||||||
cp $CODEBLOC_SRC/cloudformation/source-end.cue cloudformation/source.cue
|
cp "$DAGGER_WORKSPACE"/cloudformation/source-end.cue "$DAGGER_SANDBOX"/cloudformation/source.cue
|
||||||
|
|
||||||
# Copy corresponding env
|
# Copy corresponding env
|
||||||
cp -r $CODEBLOC_SRC/.dagger/env/cloudformation .dagger/env/
|
cp -r "$DAGGER_WORKSPACE"/.dagger/env/cloudformation "$DAGGER_SANDBOX"/.dagger/env/
|
||||||
|
|
||||||
# Run test
|
# Run test
|
||||||
dagger -e cloudformation up
|
dagger -w "$DAGGER_SANDBOX" -e cloudformation up
|
||||||
stackName=$(dagger -e cloudformation query cfnStackName -f text)
|
stackName=$(dagger -w "$DAGGER_SANDBOX" -e cloudformation query cfnStackName -f text)
|
||||||
|
|
||||||
## Cleanup
|
## Cleanup
|
||||||
# Place back empty source
|
# Place back empty source
|
||||||
cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue
|
cp "$DAGGER_WORKSPACE"/cloudformation/source-begin.cue "$DAGGER_SANDBOX"/cloudformation/source.cue
|
||||||
cp $CODEBLOC_SRC/cloudformation/deletion.cue cloudformation/deletion.cue
|
cp "$DAGGER_WORKSPACE"/cloudformation/deletion.cue "$DAGGER_SANDBOX"/cloudformation/deletion.cue
|
||||||
# Prepare and run cloudformation cleanup
|
# Prepare and run cloudformation cleanup
|
||||||
dagger -e cloudformation input text stackRemoval.stackName $stackName
|
dagger -w "$DAGGER_SANDBOX" -e cloudformation input text stackRemoval.stackName "$stackName"
|
||||||
dagger -e cloudformation up
|
dagger -w "$DAGGER_SANDBOX" -e cloudformation up
|
||||||
|
|
||||||
### Template part
|
### Template part
|
||||||
## Create convert.cue
|
## Create convert.cue
|
||||||
cp $CODEBLOC_SRC/cloudformation/template/convert.cue cloudformation/convert.cue
|
cp "$DAGGER_WORKSPACE"/cloudformation/template/convert.cue "$DAGGER_SANDBOX"/cloudformation/convert.cue
|
||||||
rm cloudformation/source.cue cloudformation/deletion.cue
|
rm "$DAGGER_SANDBOX"/cloudformation/source.cue "$DAGGER_SANDBOX"/cloudformation/deletion.cue
|
||||||
|
|
||||||
## Retrieve Unmarshalled JSON
|
## Retrieve Unmarshalled JSON
|
||||||
dagger query -e cloudformation s3Template
|
dagger -w "$DAGGER_SANDBOX" query -e cloudformation s3Template
|
||||||
|
|
||||||
## Remove convert.cue
|
## Remove convert.cue
|
||||||
rm cloudformation/convert.cue
|
rm "$DAGGER_SANDBOX"/cloudformation/convert.cue
|
||||||
## Store the output
|
|
||||||
cp $CODEBLOC_SRC/cloudformation/template/template-begin.cue cloudformation/template.cue
|
|
||||||
# Inspect conf
|
|
||||||
dagger query -e cloudformation template -f text
|
|
||||||
|
|
||||||
cp $CODEBLOC_SRC/cloudformation/template/deployment.cue cloudformation/deployment.cue
|
## Store the output
|
||||||
cp $CODEBLOC_SRC/cloudformation/template/template-end.cue cloudformation/template.cue
|
cp "$DAGGER_WORKSPACE"/cloudformation/template/template-begin.cue "$DAGGER_SANDBOX"/cloudformation/template.cue
|
||||||
cp $CODEBLOC_SRC/cloudformation/source-end.cue cloudformation/source.cue
|
|
||||||
|
# Inspect conf
|
||||||
|
dagger -w "$DAGGER_SANDBOX" query -e cloudformation template -f text
|
||||||
|
|
||||||
|
cp "$DAGGER_WORKSPACE"/cloudformation/template/deployment.cue "$DAGGER_SANDBOX"/cloudformation/deployment.cue
|
||||||
|
cp "$DAGGER_WORKSPACE"/cloudformation/template/template-end.cue "$DAGGER_SANDBOX"/cloudformation/template.cue
|
||||||
|
cp "$DAGGER_WORKSPACE"/cloudformation/source-end.cue "$DAGGER_SANDBOX"/cloudformation/source.cue
|
||||||
|
|
||||||
# Deploy again
|
# Deploy again
|
||||||
dagger -e cloudformation query template -f text
|
dagger -w "$DAGGER_SANDBOX" -e cloudformation query template -f text
|
||||||
dagger -e cloudformation up
|
dagger -w "$DAGGER_SANDBOX" -e cloudformation up
|
||||||
dagger -e cloudformation output list
|
dagger -w "$DAGGER_SANDBOX" -e cloudformation output list
|
||||||
|
|
||||||
## Cleanup again
|
## Cleanup again
|
||||||
stackName=$(dagger -e cloudformation query cfnStackName -f text)
|
stackName=$(dagger -w "$DAGGER_SANDBOX" -e cloudformation query cfnStackName -f text)
|
||||||
rm -rf cloudformation/*
|
rm -rf "$DAGGER_SANDBOX"/cloudformation/*
|
||||||
|
|
||||||
# Place back empty source
|
# Place back empty source
|
||||||
cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue
|
cp "$DAGGER_WORKSPACE"/cloudformation/source-begin.cue "$DAGGER_SANDBOX"/cloudformation/source.cue
|
||||||
cp $CODEBLOC_SRC/cloudformation/deletion.cue cloudformation/deletion.cue
|
cp "$DAGGER_WORKSPACE"/cloudformation/deletion.cue "$DAGGER_SANDBOX"/cloudformation/deletion.cue
|
||||||
|
|
||||||
# Prepare and run cloudformation cleanup
|
# Prepare and run cloudformation cleanup
|
||||||
dagger -e cloudformation input text stackRemoval.stackName $stackName
|
dagger -w "$DAGGER_SANDBOX" -e cloudformation input text stackRemoval.stackName "$stackName"
|
||||||
dagger -e cloudformation up
|
dagger -w "$DAGGER_SANDBOX" -e cloudformation up
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "doc-1010-dev-cue-package" {
|
@test "doc-1010-dev-cue-package" {
|
||||||
setup_example_sandbox ""
|
|
||||||
|
|
||||||
# Initializing workspace
|
# Initializing workspace
|
||||||
mkdir workspace
|
mkdir -p "$DAGGER_SANDBOX"/workspace
|
||||||
cd workspace
|
|
||||||
|
|
||||||
# Writing package
|
# Writing package
|
||||||
dagger init
|
# dagger init # The sandbox is already init
|
||||||
mkdir -p cue.mod/pkg/github.com/tjovicic/gcpcloudrun
|
mkdir -p "$DAGGER_SANDBOX"/cue.mod/pkg/github.com/tjovicic/gcpcloudrun
|
||||||
cp $CODEBLOC_SRC/dev-cue-package/source.cue cue.mod/pkg/github.com/tjovicic/gcpcloudrun/source.cue
|
cp "$DAGGER_WORKSPACE"/dev-cue-package/source.cue "$DAGGER_SANDBOX"/cue.mod/pkg/github.com/tjovicic/gcpcloudrun/source.cue
|
||||||
cp $CODEBLOC_SRC/dev-cue-package/script.sh .
|
cp "$DAGGER_WORKSPACE"/dev-cue-package/script.sh "$DAGGER_SANDBOX"/workspace/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' < script.sh > tmpFile ; mv tmpFile script.sh
|
sed '$d' <"$DAGGER_SANDBOX"/workspace/script.sh >"$DAGGER_SANDBOX"/tmpFile
|
||||||
|
mv "$DAGGER_SANDBOX"/tmpFile "$DAGGER_SANDBOX"/workspace/script.sh
|
||||||
|
|
||||||
|
chmod +x "$DAGGER_SANDBOX"/workspace/script.sh
|
||||||
|
"$DAGGER_SANDBOX"/workspace/script.sh
|
||||||
|
|
||||||
|
# Sync file from documentation
|
||||||
|
rsync -a test "$DAGGER_SANDBOX"
|
||||||
|
|
||||||
chmod +x script.sh
|
|
||||||
./script.sh
|
|
||||||
# Command removed from script.sh above
|
# Command removed from script.sh above
|
||||||
dagger new staging -p ./test
|
dagger -w "$DAGGER_SANDBOX" new staging -p "$DAGGER_SANDBOX"/test
|
||||||
run dagger up -e staging
|
run dagger up -w "$DAGGER_SANDBOX" -e staging
|
||||||
assert_output --partial "input=run.gcpConfig.serviceKey"
|
assert_output --partial "input=run.gcpConfig.serviceKey"
|
||||||
|
|
||||||
|
# Clean script.sh output
|
||||||
|
rm -rf ./test
|
||||||
}
|
}
|
||||||
|
@ -34,21 +34,15 @@ dagger() {
|
|||||||
"${DAGGER}" "$@"
|
"${DAGGER}" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# dagger helper to run doc examples in clean environment
|
# Setup sandbox for dagger example
|
||||||
|
# It clones the example repository and update Sandbox to
|
||||||
setup_example_sandbox() {
|
setup_example_sandbox() {
|
||||||
# Tell Dagger not to use DAGGER WORKSPACE env var
|
git -C "$DAGGER_SANDBOX" clone https://github.com/dagger/examples
|
||||||
unset DAGGER_WORKSPACE
|
|
||||||
|
|
||||||
export CODEBLOC_SRC="$(pwd)"
|
export DAGGER_SANDBOX="$DAGGER_SANDBOX"/examples/todoapp
|
||||||
local tmpdir=$(mktemp -d)
|
|
||||||
cd $tmpdir
|
|
||||||
if [ "$1" = "doc" ]; then
|
|
||||||
git clone https://github.com/dagger/examples
|
|
||||||
cd examples/todoapp
|
|
||||||
cue mod init
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# copy an environment from the current workspace to the sandbox.
|
# copy an environment from the current workspace 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
|
||||||
|
Reference in New Issue
Block a user