Add basic test for kubernetes kind documentation

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-08-13 16:35:53 +02:00 committed by Guillaume de Rouville
parent 6a442fae6c
commit a8e218d808
6 changed files with 185 additions and 113 deletions

3
.gitignore vendored
View File

@ -12,7 +12,7 @@
# Test binary, build with `go test -c` # Test binary, build with `go test -c`
*.test *.test
tests/report.xml **/*/report.xml
# Output of the go coverage tool, specifically when used with LiteIDE # Output of the go coverage tool, specifically when used with LiteIDE
*.out *.out
@ -26,3 +26,4 @@ tests/report.xml
# node_modules # node_modules
tests/node_modules tests/node_modules
dist/ dist/
docs/learn/tests/node_modules

View File

@ -0,0 +1,2 @@
# dagger state
state/**

View File

@ -0,0 +1,23 @@
plan:
package: ./kube-kind/basic
name: kube-kind-basic
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
age:
- recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSAwZ3FnR0NRay9TM1FaZXhT
T2hvQ1ZDRkNLMHpMMnh6a3QrZUpRcHhkQVVBCm5NWXdRZXVPVWhEQXdwSnQwQkZ3
NE1wL3VyNjlVbmdqM2t2MDc1ZHVNd2sKLS0tIEZNUUtnUFVBOTEyMGVWbXgycHo4
Z0RqSGxzN3pyc1RLcGN5b29GbHpkbWsKhNI37Ws2sWSW2ZKZSSFH5a2LD9meOQrH
MM2Xd0+Kh4OwYIfMXmCU1CmNRP/W1MUf6Eq/21uM3fDU8GDbpOV/pA==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2021-08-13T12:56:16Z"
mac: ENC[AES256_GCM,data:ODBv7782ofOQzVtETFu9wdMdmK/22jl1CqPzTqdOu6oZFWklbQ4grJ3N1cemE2Ud1Awb/x41QgpSuvVHaO2dHkVEF1FmlVDIqhqm6BNQlDg81RFuvs86FP60cW8rfr4K2dhCnQ1mRKGdTLsNUjUqBd3uwPDu5f49o3Ai/EpOg0A=,iv:1UdjtEKhKyFEnkjUOPAYlyIp8xYieDBIXKGxmxcYUbs=,tag:e6YcVmSVdsfLLMOPQXrN8A==,type:str]
pgp: []
encrypted_suffix: secret
version: 3.7.1

View File

@ -2,162 +2,182 @@
## Indentation is important, please append at the end ## Indentation is important, please append at the end
setup() { setup() {
load 'helpers' load 'helpers'
common_setup common_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 "doc"
# Set examples private key # Set examples private key
./import-tutorial-key.sh ./import-tutorial-key.sh
# Collect url # Collect url
dagger up dagger up
url=$(dagger query -f text url) url=$(dagger query -f text url)
# More commands # More commands
dagger list dagger list
ls -l ./s3 ls -l ./s3
dagger input list dagger 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 "doc"
# Follow tutorial # Follow tutorial
mkdir multibucket mkdir multibucket
cp $CODEBLOC_SRC/multibucket/source.cue multibucket cp $CODEBLOC_SRC/multibucket/source.cue multibucket
cp $CODEBLOC_SRC/multibucket/yarn.cue multibucket cp $CODEBLOC_SRC/multibucket/yarn.cue multibucket
cp $CODEBLOC_SRC/multibucket/netlify.cue multibucket cp $CODEBLOC_SRC/multibucket/netlify.cue multibucket
dagger doc alpha.dagger.io/netlify dagger doc alpha.dagger.io/netlify
dagger doc alpha.dagger.io/js/yarn dagger doc alpha.dagger.io/js/yarn
# Initialize new env # Initialize new env
dagger new 'multibucket' -p ./multibucket dagger new 'multibucket' -p ./multibucket
# Copy corresponding env # Copy corresponding env
cp -r $CODEBLOC_SRC/.dagger/env/multibucket .dagger/env/ cp -r $CODEBLOC_SRC/.dagger/env/multibucket .dagger/env/
# Add missing src input # Add missing src input
dagger -e multibucket input dir src . dagger -e multibucket input dir src .
# Run test # Run test
dagger -e multibucket up dagger -e multibucket up
url=$(dagger -e multibucket query -f text site.netlify.deployUrl) url=$(dagger -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 "doc"
mkdir gcpcloudrun mkdir gcpcloudrun
cp $CODEBLOC_SRC/gcpcloudrun/source.cue gcpcloudrun cp $CODEBLOC_SRC/gcpcloudrun/source.cue gcpcloudrun
# Initialize new env # Initialize new env
dagger new 'gcpcloudrun' -p gcpcloudrun dagger new 'gcpcloudrun' -p gcpcloudrun
# Copy corresponding env # Copy corresponding env
cp -r $CODEBLOC_SRC/.dagger/env/gcpcloudrun .dagger/env/ cp -r $CODEBLOC_SRC/.dagger/env/gcpcloudrun .dagger/env/
# Add missing src input # Add missing src input
dagger -e gcpcloudrun input dir src . dagger -e gcpcloudrun input dir src .
# Run test # Run test
run dagger -e gcpcloudrun up run dagger -e gcpcloudrun up
assert_success assert_success
}
@test "doc-1007-kube-kind" {
skip_unless_local_kube
#################### BASIC ####################
# Copy deployment to sendbox
copy_to_sandbox kube-kind-basic kube-kind
# Add kubeconfig
dagger -w "$DAGGER_SANDBOX" -e kube-kind-basic input text kubeconfig -f "$HOME"/.kube/config
# Up deployment
dagger -w "$DAGGER_SANDBOX" -e kube-kind-basic up
# Check deployment
kubectl get deployment
# Clean
kubectl delete deployments --all
} }
@test "doc-1008-aws-cloudformation" { @test "doc-1008-aws-cloudformation" {
setup_example_sandbox "doc" setup_example_sandbox "doc"
### Create a basic plan ### Create a basic plan
## Construct ## Construct
mkdir cloudformation mkdir cloudformation
cp $CODEBLOC_SRC/cloudformation/template.cue cloudformation cp $CODEBLOC_SRC/cloudformation/template.cue cloudformation
# Cloudformation relay # Cloudformation relay
dagger doc alpha.dagger.io/aws/cloudformation dagger doc alpha.dagger.io/aws/cloudformation
cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue
# Initialize new env # Initialize new env
dagger new 'cloudformation' -p cloudformation dagger new 'cloudformation' -p cloudformation
# Finish template setup # Finish template setup
cp $CODEBLOC_SRC/cloudformation/source-end.cue cloudformation/source.cue cp $CODEBLOC_SRC/cloudformation/source-end.cue cloudformation/source.cue
# Copy corresponding env # Copy corresponding env
cp -r $CODEBLOC_SRC/.dagger/env/cloudformation .dagger/env/ cp -r $CODEBLOC_SRC/.dagger/env/cloudformation .dagger/env/
# Run test # Run test
dagger -e cloudformation up dagger -e cloudformation up
stackName=$(dagger -e cloudformation query cfnStackName -f text) stackName=$(dagger -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 $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue
cp $CODEBLOC_SRC/cloudformation/deletion.cue cloudformation/deletion.cue cp $CODEBLOC_SRC/cloudformation/deletion.cue cloudformation/deletion.cue
# Prepare and run cloudformation cleanup # Prepare and run cloudformation cleanup
dagger -e cloudformation input text stackRemoval.stackName $stackName dagger -e cloudformation input text stackRemoval.stackName $stackName
dagger -e cloudformation up dagger -e cloudformation up
### Template part ### Template part
## Create convert.cue ## Create convert.cue
cp $CODEBLOC_SRC/cloudformation/template/convert.cue cloudformation/convert.cue cp $CODEBLOC_SRC/cloudformation/template/convert.cue cloudformation/convert.cue
rm cloudformation/source.cue cloudformation/deletion.cue rm cloudformation/source.cue cloudformation/deletion.cue
## Retrieve Unmarshalled JSON ## Retrieve Unmarshalled JSON
dagger query -e cloudformation s3Template dagger query -e cloudformation s3Template
## Remove convert.cue ## Remove convert.cue
rm cloudformation/convert.cue rm cloudformation/convert.cue
## Store the output ## Store the output
cp $CODEBLOC_SRC/cloudformation/template/template-begin.cue cloudformation/template.cue cp $CODEBLOC_SRC/cloudformation/template/template-begin.cue cloudformation/template.cue
# Inspect conf # Inspect conf
dagger query -e cloudformation template -f text dagger query -e cloudformation template -f text
cp $CODEBLOC_SRC/cloudformation/template/deployment.cue cloudformation/deployment.cue cp $CODEBLOC_SRC/cloudformation/template/deployment.cue cloudformation/deployment.cue
cp $CODEBLOC_SRC/cloudformation/template/template-end.cue cloudformation/template.cue cp $CODEBLOC_SRC/cloudformation/template/template-end.cue cloudformation/template.cue
cp $CODEBLOC_SRC/cloudformation/source-end.cue cloudformation/source.cue cp $CODEBLOC_SRC/cloudformation/source-end.cue cloudformation/source.cue
# Deploy again # Deploy again
dagger -e cloudformation query template -f text dagger -e cloudformation query template -f text
dagger -e cloudformation up dagger -e cloudformation up
dagger -e cloudformation output list dagger -e cloudformation output list
## Cleanup again ## Cleanup again
stackName=$(dagger -e cloudformation query cfnStackName -f text) stackName=$(dagger -e cloudformation query cfnStackName -f text)
rm -rf cloudformation/* rm -rf cloudformation/*
# Place back empty source # Place back empty source
cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue cp $CODEBLOC_SRC/cloudformation/source-begin.cue cloudformation/source.cue
cp $CODEBLOC_SRC/cloudformation/deletion.cue cloudformation/deletion.cue cp $CODEBLOC_SRC/cloudformation/deletion.cue cloudformation/deletion.cue
# Prepare and run cloudformation cleanup # Prepare and run cloudformation cleanup
dagger -e cloudformation input text stackRemoval.stackName $stackName dagger -e cloudformation input text stackRemoval.stackName $stackName
dagger -e cloudformation up dagger -e cloudformation up
} }
@test "doc-1010-dev-cue-package" { @test "doc-1010-dev-cue-package" {
setup_example_sandbox "" setup_example_sandbox ""
# Initializing workspace # Initializing workspace
mkdir workspace mkdir workspace
cd workspace cd workspace
# Writing the package # Writing the package
dagger init dagger init
mkdir -p cue.mod/pkg/github.com/tjovicic/gcpcloudrun mkdir -p 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 $CODEBLOC_SRC/dev-cue-package/source.cue cue.mod/pkg/github.com/tjovicic/gcpcloudrun/source.cue
cp $CODEBLOC_SRC/dev-cue-package/script.sh . cp $CODEBLOC_SRC/dev-cue-package/script.sh .
chmod +x script.sh chmod +x script.sh
./script.sh ./script.sh
run dagger up -e staging run dagger up -e staging
assert_output --partial "environment=staging input=run.gcpConfig.serviceKey" assert_output --partial "environment=staging input=run.gcpConfig.serviceKey"
} }

View File

@ -0,0 +1,11 @@
package main
import (
"alpha.dagger.io/git"
)
manifest: git.#Repository & {
remote: "https://github.com/dagger/examples.git"
ref: "main"
subdir: "todoapp/k8s"
}

View File

@ -0,0 +1,15 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"bats-assert@https://github.com/bats-core/bats-assert":
version "2.0.0"
resolved "https://github.com/bats-core/bats-assert#e0de84e9c011223e7f88b7ccf1c929f4327097ba"
"bats-support@https://github.com/bats-core/bats-support":
version "0.3.0"
resolved "https://github.com/bats-core/bats-support#d140a65044b2d6810381935ae7f0c94c7023c8c3"
"bats@https://github.com/bats-core/bats-core#master":
version "1.4.1"
resolved "https://github.com/bats-core/bats-core#7ff2f3efc738976feaccfdf374164b61599f9e36"