From 82d45985a5553b8c7dfb707de08e56916258e356 Mon Sep 17 00:00:00 2001 From: Guillaume de Rouville Date: Fri, 13 Aug 2021 01:47:59 +0200 Subject: [PATCH] 1004 test implementation Signed-off-by: Guillaume de Rouville --- docs/learn/1004-first-env.md | 36 +++---------------- .../tests/.dagger/env/multibucket/.gitignore | 2 ++ .../tests/.dagger/env/multibucket/values.yaml | 28 +++++++++++++++ docs/learn/tests/doc.bats | 32 +++++++++++++++++ docs/learn/tests/multibucket/netlify.cue | 10 ++++++ docs/learn/tests/multibucket/source.cue | 8 +++++ docs/learn/tests/multibucket/yarn.cue | 10 ++++++ 7 files changed, 94 insertions(+), 32 deletions(-) create mode 100644 docs/learn/tests/.dagger/env/multibucket/.gitignore create mode 100644 docs/learn/tests/.dagger/env/multibucket/values.yaml create mode 100644 docs/learn/tests/multibucket/netlify.cue create mode 100644 docs/learn/tests/multibucket/source.cue create mode 100644 docs/learn/tests/multibucket/yarn.cue diff --git a/docs/learn/1004-first-env.md b/docs/learn/1004-first-env.md index 11b31665..c1307338 100644 --- a/docs/learn/1004-first-env.md +++ b/docs/learn/1004-first-env.md @@ -68,7 +68,7 @@ Although not strictly necessary, for an optimal development experience, we recom If you are new to Cue, we recommend keeping the following resources in browser tabs: -The unofficial but excellent [Cuetorials](https://cuetorials.com/overview/foundations/) in a browser tab, to look up Cue concepts as they appear. +- The unofficial but excellent [Cuetorials](https://cuetorials.com/overview/foundations/) in a browser tab, to look up Cue concepts as they appear. - The official [Cue interactive sandbox](https://cuelang.org/play) for easy experimentation. @@ -130,15 +130,7 @@ In Dagger terms, this component has two essential properties: Let's write the corresponding Cue code to a new file in our package: -```cue title="todoapp/multibucket/source.cue" -package multibucket - -import ( - "alpha.dagger.io/dagger" -) - -// Source code of the sample application -src: dagger.#Artifact & dagger.#Input +```cue file=./tests/multibucket/source.cue title="todoapp/cue.mod/multibucket/source.cue" ``` This code defines a component at the key `src` and specifies that it is both an artifact and an input. @@ -147,17 +139,7 @@ This code defines a component at the key `src` and specifies that it is both an The second component of our plan is the Yarn package built from the app source code: -```cue title="todoapp/multibucket/yarn.cue" -package multibucket - -import ( - "alpha.dagger.io/js/yarn" -) - -// Build the source code using Yarn -app: yarn.#Package & { - source: src -} +```cue file=./tests/multibucket/yarn.cue title="todoapp/cue.mod/multibucket/yarn.cue" ``` Let's break it down: @@ -176,17 +158,7 @@ _FIXME_: this section is not yet available because the [Amazon S3 package](https The third component of our plan is the Netlify site to which the app will be deployed: -```cue title="todoapp/multibucket/netlify.cue" -package multibucket - -import ( - "alpha.dagger.io/netlify" -) - -// Netlify site -site: "netlify": netlify.#Site & { - contents: app.build -} +```cue file=./tests/multibucket/netlify.cue title="todoapp/cue.mod/multibucket/netlify.cue" ``` This component is very similar to the previous one: diff --git a/docs/learn/tests/.dagger/env/multibucket/.gitignore b/docs/learn/tests/.dagger/env/multibucket/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/docs/learn/tests/.dagger/env/multibucket/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/docs/learn/tests/.dagger/env/multibucket/values.yaml b/docs/learn/tests/.dagger/env/multibucket/values.yaml new file mode 100644 index 00000000..1fafe75a --- /dev/null +++ b/docs/learn/tests/.dagger/env/multibucket/values.yaml @@ -0,0 +1,28 @@ +plan: + package: ./multibucket +name: multibucket +inputs: + site.netlify.account.token: + secret: ENC[AES256_GCM,data:e5cILcdqbaFdz6ZMM4sNYrChQS+VSMJTZA9cJ0kPvNEDlQj2n7ldlBeO9A==,iv:4SlRRlXyJ8/9ewAPXJ9KdhdVo4FrvVeRwSip2FfMTIM=,tag:JdxkVTR6SOLgzHUWtoSjyw==,type:str] + site.netlify.name: + text: dagger-test-doc-102 +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBOVFI4NU40NXF1Um4vR1No + MTByOC9HVWJYUCtzYUc4WGh2UG1EQnJCSm5FCnFrZ1BaMEZJLzBIRUVTUUdhWWRv + N2xRYTR4NlhwclBYME9ZZ3JQejJoUFkKLS0tIDEwa0dXbVhzRWMrMFc3U0FtaEdr + RERQRVp2VjR3K0VwQlZRWEJrQUNpNkUK78CsKmOJp1kKUcytprs0SKLLuo0YDucp + oLuxQQd0X3/8x2c/YfJ3R15e1EQDC73HjSXDbhlgOScR9bxGVqn36A== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-08-12T23:19:07Z" + mac: ENC[AES256_GCM,data:9jc3lwlbsJ6CdiSBF4ALNiv/zD7Rv5ZodftuEQpZuJVEpjJCKSq3C7LNyJKxV7fTg/tZ+RDx/q+x0xN9reRRrmvUCsbmLRL2h20rrfsVj3npCSkRiQFcmoHd6ULjf/kbkgUanLt8YmncDzJqNTQfafCxTo1RY3+U2WH/QSIIebQ=,iv:dcXQsq5de6LElOoqvGfs7nmHELkoTs0jddeY3vf4fJg=,tag:j0Eeu5NrNyhBYUzMwarj+w==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/docs/learn/tests/doc.bats b/docs/learn/tests/doc.bats index 1aaf017e..ed9821e6 100644 --- a/docs/learn/tests/doc.bats +++ b/docs/learn/tests/doc.bats @@ -26,4 +26,36 @@ setup() { # Check output run curl $url assert_output --partial "My Todo app" +} + +@test "doc-1004-first-env" { + setup_example_sandbox "doc" + + # Follow tutorial + mkdir multibucket + cp $CODEBLOC_SRC/multibucket/source.cue multibucket + cp $CODEBLOC_SRC/multibucket/yarn.cue multibucket + cp $CODEBLOC_SRC/multibucket/netlify.cue multibucket + + dagger doc alpha.dagger.io/netlify + dagger doc alpha.dagger.io/js/yarn + + # Initialize new env + dagger new 'multibucket' -p ./multibucket + + # Check inputs + dagger input list -e multibucket + + # Copy corresponding env + cp -r $CODEBLOC_SRC/.dagger/env/multibucket .dagger/env/ + # Add missing src input + dagger -e multibucket input dir src . + + # Run test + dagger -e multibucket up + url=$(dagger -e multibucket query -f text site.netlify.deployUrl) + + # Check output : + run curl $url + assert_output --partial "./static/css/main.9149988f.chunk.css" } \ No newline at end of file diff --git a/docs/learn/tests/multibucket/netlify.cue b/docs/learn/tests/multibucket/netlify.cue new file mode 100644 index 00000000..f133b0b5 --- /dev/null +++ b/docs/learn/tests/multibucket/netlify.cue @@ -0,0 +1,10 @@ +package multibucket + +import ( + "alpha.dagger.io/netlify" +) + +// Netlify site +site: "netlify": netlify.#Site & { + contents: app.build +} diff --git a/docs/learn/tests/multibucket/source.cue b/docs/learn/tests/multibucket/source.cue new file mode 100644 index 00000000..638c2dcc --- /dev/null +++ b/docs/learn/tests/multibucket/source.cue @@ -0,0 +1,8 @@ +package multibucket + +import ( + "alpha.dagger.io/dagger" +) + +// Source code of the sample application +src: dagger.#Artifact & dagger.#Input diff --git a/docs/learn/tests/multibucket/yarn.cue b/docs/learn/tests/multibucket/yarn.cue new file mode 100644 index 00000000..951ae321 --- /dev/null +++ b/docs/learn/tests/multibucket/yarn.cue @@ -0,0 +1,10 @@ +package multibucket + +import ( + "alpha.dagger.io/js/yarn" +) + +// Build the source code using Yarn +app: yarn.#Package & { + source: src +}