netlify: enable image customization; improve tests

Signed-off-by: Solomon Hykes <solomon@dagger.io>
This commit is contained in:
Solomon Hykes 2022-02-11 22:28:25 +00:00
parent b52684ff85
commit fbae253f62
3 changed files with 88 additions and 21 deletions

View File

@ -59,7 +59,7 @@ import (
// Run the netlify client in a container // Run the netlify client in a container
container: bash.#Run & { container: bash.#Run & {
input: _build.output input: *_build.output | docker.#Image
script: { script: {
_load: engine.#Source & { _load: engine.#Source & {
path: "." path: "."

View File

@ -1,12 +1,13 @@
package yarn package netlify
import ( import (
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/dagger/engine" "dagger.io/dagger/engine"
"universe.dagger.io/docker"
"universe.dagger.io/netlify" "universe.dagger.io/netlify"
"universe.dagger.io/alpine"
"universe.dagger.io/bash" "universe.dagger.io/netlify/test/testutils"
) )
dagger.#Plan & { dagger.#Plan & {
@ -16,13 +17,16 @@ dagger.#Plan & {
} }
actions: tests: { actions: tests: {
// Test: netlify.#Deploy correctly receives API token
receiveToken: { // Configuration common to all tests
common: {
testSecrets: dagger.#DecodeSecret & { testSecrets: dagger.#DecodeSecret & {
input: inputs.secrets.test.contents input: inputs.secrets.test.contents
format: "yaml" format: "yaml"
} }
token: testSecrets.output.netlifyToken.contents
marker: "hello world" marker: "hello world"
data: engine.#WriteFile & { data: engine.#WriteFile & {
@ -30,29 +34,66 @@ dagger.#Plan & {
path: "index.html" path: "index.html"
contents: marker contents: marker
} }
}
// Test: deploy a simple site to Netlify
simple: {
// Deploy to netlify // Deploy to netlify
deploy: netlify.#Deploy & { deploy: netlify.#Deploy & {
team: "blocklayer" team: "blocklayer"
token: testSecrets.output.netlifyToken.contents token: common.token
site: "dagger-test" site: "dagger-test"
contents: data.output contents: common.data.output
} }
image: alpine.#Build & { verify: testutils.#AssertURL & {
packages: { url: deploy.deployUrl
bash: {} contents: common.marker
curl: {} }
} }
// 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 customImage: docker.#Build & {
verify: bash.#Run & { steps: [
input: image.output docker.#Pull & {
script: contents: #""" source: "alpine"
test "$(curl \#(deploy.deployUrl))" = "\#(marker)" },
"""# 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
} }
} }
} }

View File

@ -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: {}
}
}
}