implements dagger do

Signed-off-by: Richard Jones <richard@dagger.io>
This commit is contained in:
Richard Jones
2022-02-22 14:04:54 -07:00
parent 621edd6b2f
commit 6cdf13223c
23 changed files with 486 additions and 335 deletions

View File

@@ -7,154 +7,77 @@ setup() {
@test "plan/hello" {
# Europa loader handles the cwd differently, therefore we need to CD into the tree at or below the parent of cue.mod
cd "$TESTDIR"
"$DAGGER" up ./plan/hello-europa
"$DAGGER" "do" -p ./plan/hello-europa test
}
@test "plan/proxy invalid schema" {
cd "$TESTDIR"
run "$DAGGER" up ./plan/proxy/invalid_schema.cue
run "$DAGGER" "do" -p ./plan/proxy/invalid_schema.cue verify
assert_failure
}
@test "plan/proxy invalid value" {
cd "$TESTDIR"
run "$DAGGER" up ./plan/proxy/invalid_value.cue
run "$DAGGER" "do" -p ./plan/proxy/invalid_value.cue verify
assert_failure
}
@test "plan/proxy incomplete unix" {
cd "$TESTDIR"
run "$DAGGER" up ./plan/proxy/incomplete_unix.cue
run "$DAGGER" "do" -p ./plan/proxy/incomplete_unix.cue verify
assert_failure
}
@test "plan/proxy incomplete service" {
cd "$TESTDIR"
run "$DAGGER" up ./plan/proxy/incomplete_service.cue
run "$DAGGER" "do" -p ./plan/proxy/incomplete_service.cue verify
assert_output --partial 'mount "docker" is not concrete'
}
@test "plan/proxy unix" {
cd "$TESTDIR"
"$DAGGER" up ./plan/proxy/unix.cue
"$DAGGER" "do" -p ./plan/proxy/unix.cue verify
}
@test "plan/inputs/directories exists" {
@test "plan/inputs/directories" {
cd "$TESTDIR"
"$DAGGER" up ./plan/inputs/directories/exists.cue
}
"$DAGGER" "do" -p ./plan/inputs/directories/valid exists
@test "plan/inputs/directories relative directories" {
cd "$TESTDIR"
cd "$TESTDIR"/plan/inputs
"$DAGGER" up ./directories/exists.cue
}
@test "plan/inputs/directories not exists" {
cd "$TESTDIR"
run "$DAGGER" up ./plan/inputs/directories/not_exists.cue
run "$DAGGER" "do" -p ./plan/inputs/directories/invalid notExists
assert_failure
assert_output --partial 'fasdfsdfs" does not exist'
}
@test "plan/inputs/directories conflicting values" {
cd "$TESTDIR"
run "$DAGGER" up ./plan/inputs/directories/conflicting_values.cue
run "$DAGGER" "do" -p ./plan/inputs/directories/valid conflictingValues
assert_failure
assert_output --partial 'conflicting values "local directory" and "local dfsadf"'
}
@test "plan/inputs/secrets" {
cd "$TESTDIR"
"$DAGGER" up ./plan/inputs/secrets/exec.cue
"$DAGGER" up ./plan/inputs/secrets/exec_relative.cue
"$DAGGER" "do" -p ./plan/inputs/secrets test valid
"$DAGGER" "do" -p ./plan/inputs/secrets test relative
run "$DAGGER" up ./plan/inputs/secrets/invalid_command.cue
run "$DAGGER" "do" -p ./plan/inputs/secrets test badCommand
assert_failure
assert_output --partial 'failed: exec: "rtyet": executable file not found'
run "$DAGGER" up ./plan/inputs/secrets/invalid_command_options.cue
run "$DAGGER" "do" -p ./plan/inputs/secrets test badArgs
assert_failure
assert_output --partial 'option'
}
@test "plan/with" {
cd "$TESTDIR"
"$DAGGER" up --with 'inputs: params: foo:"bar"' ./plan/with/params.cue
"$DAGGER" up --with 'actions: verify: env: FOO: "bar"' ./plan/with/actions.cue
"$DAGGER" "do" --with 'inputs: params: foo:"bar"' -p ./plan/with test params
"$DAGGER" "do" --with 'actions: test: direct: env: FOO: "bar"' -p ./plan/with test direct
run "$DAGGER" up --with 'inputs: params: foo:1' ./plan/with/params.cue
run "$DAGGER" "do" --with 'inputs: params: foo:1' -p ./plan/with test params
assert_failure
assert_output --partial "conflicting values string and 1"
run "$DAGGER" up ./plan/with/params.cue
run "$DAGGER" "do" -p ./plan/with test params
assert_failure
assert_output --partial "actions.verify.env.FOO: non-concrete value string"
}
@test "plan/outputs/directories" {
cd "$TESTDIR"/plan/outputs/directories
"$DAGGER" up ./outputs.cue
assert [ -f "./out/test_outputs" ]
rm -f "./out/test_outputs"
}
@test "plan/outputs/directories relative paths" {
cd "$TESTDIR"/plan
"$DAGGER" up ./outputs/directories/relative.cue
assert [ -f "./outputs/directories/out/test_relative" ]
rm -f "./outputs/directories/out/test_relative"
}
@test "plan/outputs/files normal usage" {
cd "$TESTDIR"/plan/outputs/files
"$DAGGER" up ./usage.cue
run ./test_usage
assert_output "Hello World!"
run ls -l "./test_usage"
assert_output --partial "-rwxr-x---"
rm -f "./test_usage"
}
@test "plan/outputs/files relative path" {
cd "$TESTDIR"/plan
"$DAGGER" up ./outputs/files/relative.cue
assert [ -f "./outputs/files/test_relative" ]
rm -f "./outputs/files/test_relative"
}
@test "plan/outputs/files default permissions" {
cd "$TESTDIR"/plan/outputs/files
"$DAGGER" up ./default_permissions.cue
run ls -l "./test_default_permissions"
assert_output --partial "-rw-r--r--"
rm -f "./test_default_permissions"
}
@test "plan/outputs/files no contents" {
cd "$TESTDIR"/plan/outputs/files
run "$DAGGER" up ./no_contents.cue
assert_failure
assert_output --partial "contents is not set"
assert [ ! -f "./test_no_contents" ]
rm -f "./test_no_contents"
assert_output --partial "actions.test.params.env.FOO: non-concrete value string"
}
@test "plan/platform" {

74
tests/plan/do/actions.cue Normal file
View File

@@ -0,0 +1,74 @@
package main
import (
"dagger.io/dagger"
"universe.dagger.io/yarn"
"universe.dagger.io/docker"
)
dagger.#Plan & {
// All the things!
actions: {
// Run core integration tests
"core-integration": _
// Format all cue files
cuefmt: _
// Lint and format all cue files
cuelint: _
// Build a debug version of the dev dagger binary
"dagger-debug": _
// Test docs
"doc-test": _
// Generate docs
docs: _
// Generate & lint docs
docslint: _
// Run Europa universe tests
"europa-universe-test": _
// Go lint
golint: _
// Show how to get started & what targets are available
help: _
// Install a dev dagger binary
install: _
// Run all integration tests
integration: _
// Lint everything
lint: _
// Run shellcheck
shellcheck: _
// Run all tests
test: _
// Find all TODO items
todo: _
// Run universe tests
"universe-test": _
// Build, test and deploy frontend web client
frontend: {
// Build via yarn
build: yarn.#Build
// Test via headless browser
test: docker.#Run
}
}
}

View File

@@ -6,18 +6,18 @@ import (
)
dagger.#Plan & {
actions: {
image: dagger.#Pull & {
actions: test: {
_image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
exec: dagger.#Exec & {
input: image.output
_exec: dagger.#Exec & {
input: _image.output
args: ["sh", "-c", "echo -n Hello Europa > /out.txt"]
}
verify: dagger.#ReadFile & {
input: exec.output
_verify: dagger.#ReadFile & {
input: _exec.output
path: "/out.txt"
} & {
// assert result

View File

@@ -1,15 +0,0 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
inputs: directories: test: path: "."
actions: verify: dagger.#ReadFile & {
input: inputs.directories.test.contents
path: "test.txt"
} & {
contents: "local dfsadf" // should fail with conflicting values
}
}

View File

@@ -1,15 +0,0 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
inputs: directories: test: path: "."
actions: verify: dagger.#ReadFile & {
input: inputs.directories.test.contents
path: "test.txt"
} & {
contents: "local directory"
}
}

View File

@@ -0,0 +1,3 @@
package main
inputs: directories: test: path: "./fasdfsdfs"

View File

@@ -0,0 +1,31 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
inputs: directories: test: path: string
actions: {
_readFile: dagger.#ReadFile & {
input: inputs.directories.test.contents
path: "test.txt"
}
// Test that file exists and contains correct content
exists: _readFile & {
contents: "local directory"
}
// Test that file does NOT exist
notExists: _readFile & {
contents: "local directory"
}
// Test that file exists and contains conflicting content
conflictingValues: _readFile & {
contents: "local dfsadf"
}
}
}

View File

@@ -1,16 +0,0 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
// should fail because path does not exist locally
inputs: directories: test: path: "./fasdfsdfs"
actions: verify: dagger.#ReadFile & {
input: inputs.directories.test.contents
path: "test.txt"
} & {
contents: "local directory"
}
}

View File

@@ -0,0 +1,3 @@
package main
inputs: directories: test: path: "."

View File

@@ -1,34 +0,0 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
inputs: secrets: echo: command: {
name: "echo"
args: ["hello europa"]
}
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
verify: dagger.#Exec & {
input: image.output
mounts: secret: {
dest: "/run/secrets/test"
contents: inputs.secrets.echo.contents
}
args: [
"sh", "-c",
#"""
test "$(cat /run/secrets/test)" = "hello europa"
ls -l /run/secrets/test | grep -- "-r--------"
"""#,
]
}
}
}

View File

@@ -1,33 +0,0 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
inputs: secrets: echo: command: {
name: "cat"
args: ["./test.txt"]
}
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
verify: dagger.#Exec & {
input: image.output
mounts: secret: {
dest: "/run/secrets/test"
contents: inputs.secrets.echo.contents
}
args: [
"sh", "-c",
#"""
test "$(cat /run/secrets/test)" = "test"
"""#,
]
}
}
}

View File

@@ -1,34 +0,0 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
inputs: secrets: echo: command: {
name: "rtyet" // should fail because command doesn't exist
args: ["hello europa"]
}
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
verify: dagger.#Exec & {
input: image.output
mounts: secret: {
dest: "/run/secrets/test"
contents: inputs.secrets.echo.contents
}
args: [
"sh", "-c",
#"""
test "$(cat /run/secrets/test)" = "hello europa"
ls -l /run/secrets/test | grep -- "-r--------"
"""#,
]
}
}
}

View File

@@ -1,33 +0,0 @@
package main
import (
)
dagger.#Plan & {
inputs: secrets: echo: command: {
name: "cat"
args: ["--sfgjkhf"] // // should fail because invalid option
}
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
verify: dagger.#Exec & {
input: image.output
mounts: secret: {
dest: "/run/secrets/test"
contents: inputs.secrets.echo.contents
}
args: [
"sh", "-c",
#"""
test "$(cat /run/secrets/test)" = "hello europa"
ls -l /run/secrets/test | grep -- "-r--------"
"""#,
]
}
}
}

View File

@@ -0,0 +1,59 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
inputs: secrets: {
echo: command: {
name: "echo"
args: ["hello europa"]
}
relative: command: {
name: "cat"
args: ["./test.txt"]
}
badCommand: command: {
name: "rtyet" // should fail because command doesn't exist
args: ["hello europa"]
}
badArgs: command: {
name: "cat"
args: ["--sfgjkhf"] // // should fail because invalid option
}
}
actions: {
_image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
test: {
[string]: dagger.#Exec & {
input: _image.output
mounts: secret: {
dest: "/run/secrets/test"
// contents: inputs.secrets.echo.contents
}
args: [
"sh", "-c",
#"""
test "$(cat /run/secrets/test)" = "hello europa"
ls -l /run/secrets/test | grep -- "-r--------"
"""#,
]
}
valid: mounts: secret: contents: inputs.secrets.echo.contents
relative: mounts: secret: contents: inputs.secrets.relative.contents
badCommand: mounts: secret: contents: inputs.secrets.badCommand.contents
badArgs: mounts: secret: contents: inputs.secrets.badArgs.contents
}
}
}

View File

@@ -1 +1 @@
test
hello europa

View File

@@ -1,25 +0,0 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
verify: dagger.#Exec & {
input: image.output
env: FOO: string
args: [
"sh", "-c",
#"""
test -n "$FOO"
"""#,
]
}
}
}

View File

@@ -1,26 +0,0 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
inputs: params: foo: string
actions: {
image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
verify: dagger.#Exec & {
input: image.output
env: FOO: inputs.params.foo
args: [
"sh", "-c",
#"""
test "$FOO" = "bar"
"""#,
]
}
}
}

31
tests/plan/with/with.cue Normal file
View File

@@ -0,0 +1,31 @@
package main
import (
"dagger.io/dagger"
)
dagger.#Plan & {
inputs: params: foo: string
actions: {
_image: dagger.#Pull & {
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
test: {
[string]: dagger.#Exec & {
input: _image.output
env: FOO: string
args: [
"sh", "-c",
#"""
test -n "$FOO"
"""#,
]
}
direct: {}
params: env: FOO: inputs.params.foo
}
}
}