From fbae253f628b0f6de585be70513e808902821355 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 11 Feb 2022 22:28:25 +0000 Subject: [PATCH] netlify: enable image customization; improve tests Signed-off-by: Solomon Hykes --- pkg/universe.dagger.io/netlify/netlify.cue | 2 +- pkg/universe.dagger.io/netlify/test/test.cue | 81 ++++++++++++++----- .../netlify/test/testutils/testutils.cue | 26 ++++++ 3 files changed, 88 insertions(+), 21 deletions(-) create mode 100644 pkg/universe.dagger.io/netlify/test/testutils/testutils.cue diff --git a/pkg/universe.dagger.io/netlify/netlify.cue b/pkg/universe.dagger.io/netlify/netlify.cue index 0984a233..efa04beb 100644 --- a/pkg/universe.dagger.io/netlify/netlify.cue +++ b/pkg/universe.dagger.io/netlify/netlify.cue @@ -59,7 +59,7 @@ import ( // Run the netlify client in a container container: bash.#Run & { - input: _build.output + input: *_build.output | docker.#Image script: { _load: engine.#Source & { path: "." diff --git a/pkg/universe.dagger.io/netlify/test/test.cue b/pkg/universe.dagger.io/netlify/test/test.cue index 3a486b1d..dbe892fa 100644 --- a/pkg/universe.dagger.io/netlify/test/test.cue +++ b/pkg/universe.dagger.io/netlify/test/test.cue @@ -1,12 +1,13 @@ -package yarn +package netlify import ( "dagger.io/dagger" "dagger.io/dagger/engine" + "universe.dagger.io/docker" "universe.dagger.io/netlify" - "universe.dagger.io/alpine" - "universe.dagger.io/bash" + + "universe.dagger.io/netlify/test/testutils" ) dagger.#Plan & { @@ -16,13 +17,16 @@ dagger.#Plan & { } actions: tests: { - // Test: netlify.#Deploy correctly receives API token - receiveToken: { + + // Configuration common to all tests + common: { testSecrets: dagger.#DecodeSecret & { input: inputs.secrets.test.contents format: "yaml" } + token: testSecrets.output.netlifyToken.contents + marker: "hello world" data: engine.#WriteFile & { @@ -30,29 +34,66 @@ dagger.#Plan & { path: "index.html" contents: marker } + } + // Test: deploy a simple site to Netlify + simple: { // Deploy to netlify deploy: netlify.#Deploy & { - team: "blocklayer" - token: testSecrets.output.netlifyToken.contents - + team: "blocklayer" + token: common.token site: "dagger-test" - contents: data.output + contents: common.data.output } - image: alpine.#Build & { - packages: { - bash: {} - curl: {} - } + verify: testutils.#AssertURL & { + url: deploy.deployUrl + contents: common.marker + } + } + + // Test: deploy to Netlify with a custom image + swapImage: { + // Deploy to netlify + deploy: netlify.#Deploy & { + team: "blocklayer" + token: common.token + site: "dagger-test" + contents: common.data.output + container: input: customImage.output } - // Check if the website was deployed - verify: bash.#Run & { - input: image.output - script: contents: #""" - test "$(curl \#(deploy.deployUrl))" = "\#(marker)" - """# + customImage: docker.#Build & { + steps: [ + docker.#Pull & { + source: "alpine" + }, + docker.#Run & { + command: { + name: "apk" + args: [ + "add", + "--no-cache", + "yarn", + "bash", + "rsync", + "curl", + "jq", + ] + } + }, + docker.#Run & { + command: { + name: "yarn" + args: ["global", "add", "netlify-cli"] + } + }, + ] + } + + verify: testutils.#AssertURL & { + url: deploy.deployUrl + contents: common.marker } } } diff --git a/pkg/universe.dagger.io/netlify/test/testutils/testutils.cue b/pkg/universe.dagger.io/netlify/test/testutils/testutils.cue new file mode 100644 index 00000000..70a72ace --- /dev/null +++ b/pkg/universe.dagger.io/netlify/test/testutils/testutils.cue @@ -0,0 +1,26 @@ +package testutils + +import ( + "universe.dagger.io/bash" + "universe.dagger.io/alpine" +) + +// Assert the text contents available at a URL +#AssertURL: { + url: string + contents: string + + run: bash.#Run & { + input: image.output + script: "contents": """ + test "$(curl \(url))" = "\(contents)" + """ + } + + image: alpine.#Build & { + packages: { + bash: {} + curl: {} + } + } +}