Merge pull request #1610 from shykes/netlify-image
netlify: enable image customization; improve tests
This commit is contained in:
commit
27aa487b21
@ -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: "."
|
||||
|
@ -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
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the website was deployed
|
||||
verify: bash.#Run & {
|
||||
input: image.output
|
||||
script: contents: #"""
|
||||
test "$(curl \#(deploy.deployUrl))" = "\#(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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
26
pkg/universe.dagger.io/netlify/test/testutils/testutils.cue
Normal file
26
pkg/universe.dagger.io/netlify/test/testutils/testutils.cue
Normal 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: {}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user