This commit is contained in:
Morten Olsen
2022-04-03 22:15:45 +02:00
parent 56235d8f5e
commit cc7b7c6849
105 changed files with 15694 additions and 6 deletions

View File

@@ -0,0 +1,9 @@
setup() {
load '../../bats_helpers'
common_setup
}
@test "netlify" {
dagger "do" test
}

View File

@@ -0,0 +1,101 @@
package netlify
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
"universe.dagger.io/netlify"
"universe.dagger.io/netlify/test/testutils"
)
dagger.#Plan & {
client: commands: sops: {
name: "sops"
args: ["-d", "../../test_secrets.yaml"]
stdout: dagger.#Secret
}
actions: test: {
// Configuration common to all tests
common: {
testSecrets: core.#DecodeSecret & {
input: client.commands.sops.stdout
format: "yaml"
}
token: testSecrets.output.netlifyToken.contents
marker: "hello world"
data: core.#WriteFile & {
input: dagger.#Scratch
path: "index.html"
contents: marker
}
}
// Test: deploy a simple site to Netlify
simple: {
// Deploy to netlify
deploy: netlify.#Deploy & {
team: "blocklayer"
token: common.token
site: "dagger-test"
contents: common.data.output
}
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
}
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
}
}
}
}

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