Add new Client API
Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
This commit is contained in:
136
tests/plan.bats
136
tests/plan.bats
@@ -10,6 +10,142 @@ setup() {
|
||||
"$DAGGER" "do" -p ./plan/hello-europa test
|
||||
}
|
||||
|
||||
@test "plan/client/filesystem/read/fs/usage" {
|
||||
cd "$TESTDIR/plan/client/filesystem/read/fs"
|
||||
|
||||
"$DAGGER" "do" -p ./usage test valid
|
||||
|
||||
run "$DAGGER" "do" -p ./usage test conflictingValues
|
||||
assert_failure
|
||||
assert_output --partial 'conflicting values "local directory" and "local foobar"'
|
||||
|
||||
run "$DAGGER" "do" -p ./usage test excluded
|
||||
assert_failure
|
||||
assert_line --partial 'test.log: no such file or directory'
|
||||
|
||||
run "$DAGGER" "do" -p ./usage test notExists
|
||||
assert_failure
|
||||
assert_output --partial 'test.json: no such file or directory'
|
||||
}
|
||||
|
||||
@test "plan/client/filesystem/read/fs/not_exists" {
|
||||
cd "$TESTDIR/plan/client/filesystem/read/fs/not_exists"
|
||||
|
||||
run "$DAGGER" "do" -p . test
|
||||
assert_failure
|
||||
assert_output --partial 'path "/foobar" does not exist'
|
||||
}
|
||||
|
||||
@test "plan/client/filesystem/read/fs/relative" {
|
||||
cd "$TESTDIR/plan/client/filesystem/read/fs/relative"
|
||||
|
||||
"$DAGGER" "do" -p . test valid
|
||||
|
||||
run "$DAGGER" "do" -p . test notIncluded
|
||||
assert_failure
|
||||
assert_output --partial 'test.log: no such file or directory'
|
||||
}
|
||||
|
||||
@test "plan/client/filesystem/read/file" {
|
||||
cd "$TESTDIR/plan/client/filesystem/read/file"
|
||||
|
||||
"$DAGGER" "do" -p . test usage
|
||||
|
||||
run "$DAGGER" "do" -p . test concrete
|
||||
assert_failure
|
||||
assert_output --partial "unexpected concrete value"
|
||||
}
|
||||
|
||||
@test "plan/client/filesystem/read/service" {
|
||||
cd "$TESTDIR"
|
||||
"$DAGGER" "do" -p ./plan/client/filesystem/read/service/valid.cue test
|
||||
|
||||
run "$DAGGER" "do" -p ./plan/client/filesystem/read/service/invalid.cue test
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "plan/client/filesystem/write fs" {
|
||||
cd "$TESTDIR/plan/client/filesystem/write"
|
||||
|
||||
rm -rf "./out_fs"
|
||||
|
||||
"$DAGGER" "do" -p . test fs
|
||||
assert [ "$(cat ./out_fs/test)" = "foobar" ]
|
||||
|
||||
rm -rf "./out_fs"
|
||||
}
|
||||
|
||||
@test "plan/client/filesystem/write files" {
|
||||
cd "$TESTDIR/plan/client/filesystem/write"
|
||||
|
||||
mkdir -p ./out_files
|
||||
rm -f ./out_files/*
|
||||
|
||||
# -- string --
|
||||
|
||||
"$DAGGER" "do" -p ./ test file
|
||||
|
||||
assert [ "$(cat ./out_files/test.txt)" = "foobaz" ]
|
||||
run ls -l "./out_files/test.txt"
|
||||
assert_output --partial "-rw-r--r--"
|
||||
|
||||
# -- secret --
|
||||
|
||||
"$DAGGER" "do" -p ./ test secret
|
||||
|
||||
assert [ "$(cat ./out_files/secret.txt)" = "foo-barab-oof" ]
|
||||
run ls -l "./out_files/secret.txt"
|
||||
assert_output --partial "-rw-------"
|
||||
|
||||
rm -rf ./out_files
|
||||
}
|
||||
|
||||
@test "plan/client/filesystem/conflict" {
|
||||
cd "$TESTDIR/plan/client/filesystem/conflict"
|
||||
|
||||
echo -n foo > test.txt
|
||||
run "$DAGGER" "do" --log-level debug -p . test
|
||||
assert_line --regexp "client\.filesystem\..+\.write.+dependency=client\.filesystem\..+\.read"
|
||||
|
||||
rm -f test.txt
|
||||
}
|
||||
|
||||
@test "plan/client/env usage" {
|
||||
cd "${TESTDIR}"
|
||||
|
||||
export TEST_STRING="foo"
|
||||
export TEST_SECRET="bar"
|
||||
|
||||
"$DAGGER" "do" -p ./plan/client/env test usage
|
||||
}
|
||||
|
||||
@test "plan/client/env not exists" {
|
||||
cd "${TESTDIR}"
|
||||
|
||||
run "$DAGGER" "do" -p ./plan/client/env test usage
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "plan/client/env invalid" {
|
||||
cd "${TESTDIR}"
|
||||
|
||||
export TEST_FAIL="foobar"
|
||||
|
||||
run "$DAGGER" "do" -p ./plan/client/env test concrete
|
||||
assert_failure
|
||||
assert_output --partial "TEST_FAIL: unexpected concrete value"
|
||||
}
|
||||
|
||||
@test "plan/client/commands" {
|
||||
cd "${TESTDIR}/plan/client/commands"
|
||||
|
||||
"$DAGGER" "do" -p . test valid
|
||||
|
||||
run "$DAGGER" "do" -p . test invalid
|
||||
assert_failure
|
||||
assert_output --partial 'exec: "foobar": executable file not found'
|
||||
}
|
||||
|
||||
@test "plan/proxy invalid schema" {
|
||||
cd "$TESTDIR"
|
||||
run "$DAGGER" "do" -p ./plan/proxy/invalid_schema.cue verify
|
||||
|
68
tests/plan/client/commands/test.cue
Normal file
68
tests/plan/client/commands/test.cue
Normal file
@@ -0,0 +1,68 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: commands: {
|
||||
normal: {
|
||||
name: "echo"
|
||||
args: ["hello europa"]
|
||||
}
|
||||
relative: {
|
||||
name: "cat"
|
||||
args: ["./test.txt"]
|
||||
}
|
||||
secret: {
|
||||
name: "tee"
|
||||
stdout: dagger.#Secret
|
||||
stdin: "hello secretive europa"
|
||||
}
|
||||
error: {
|
||||
name: "sh"
|
||||
flags: "-c": ">&2 echo 'error'"
|
||||
stderr: string
|
||||
}
|
||||
invalid: name: "foobar"
|
||||
}
|
||||
actions: {
|
||||
image: dagger.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
test: {
|
||||
invalid: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["echo", client.commands.invalid.stdout]
|
||||
}
|
||||
valid: {
|
||||
normal: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["test", strings.TrimSpace(client.commands.normal.stdout), "=", "hello europa"]
|
||||
}
|
||||
relative: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["test", strings.TrimSpace(client.commands.relative.stdout), "=", "test"]
|
||||
}
|
||||
error: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["test", strings.TrimSpace(client.commands.error.stderr), "=", "error"]
|
||||
}
|
||||
secret: dagger.#Exec & {
|
||||
input: image.output
|
||||
mounts: secret: {
|
||||
dest: "/run/secrets/test"
|
||||
contents: client.commands.secret.stdout
|
||||
}
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
test "$(cat /run/secrets/test)" = "hello secretive europa"
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
tests/plan/client/commands/test.txt
Normal file
1
tests/plan/client/commands/test.txt
Normal file
@@ -0,0 +1 @@
|
||||
test
|
44
tests/plan/client/env/test.cue
vendored
Normal file
44
tests/plan/client/env/test.cue
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: env: {
|
||||
TEST_STRING: string
|
||||
TEST_SECRET: dagger.#Secret
|
||||
TEST_FAIL: "env"
|
||||
}
|
||||
actions: {
|
||||
image: dagger.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
test: {
|
||||
concrete: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: [client.env.TEST_FAIL]
|
||||
}
|
||||
usage: {
|
||||
string: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["test", client.env.TEST_STRING, "=", "foo"]
|
||||
}
|
||||
secret: dagger.#Exec & {
|
||||
input: image.output
|
||||
mounts: secret: {
|
||||
dest: "/run/secrets/test"
|
||||
contents: client.env.TEST_SECRET
|
||||
}
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
test "$(cat /run/secrets/test)" = "bar"
|
||||
ls -l /run/secrets/test | grep -- "-r--------"
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
41
tests/plan/client/filesystem/conflict/test.cue
Normal file
41
tests/plan/client/filesystem/conflict/test.cue
Normal file
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: filesystem: "test.txt": {
|
||||
// no dependencies between these two, one must be forced
|
||||
read: contents: string
|
||||
write: contents: actions.test.export.contents
|
||||
}
|
||||
actions: {
|
||||
image: dagger.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
test: {
|
||||
read: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["echo", client.filesystem."test.txt".read.contents]
|
||||
}
|
||||
write: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["sh", "-c",
|
||||
#"""
|
||||
echo -n bar > /out.txt
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
export: dagger.#ReadFile & {
|
||||
input: write.output
|
||||
path: "out.txt"
|
||||
}
|
||||
// FIXME: hack until we can do outputs with `dagger do`
|
||||
verify: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["echo", client.filesystem."test.txt".write.contents]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
tests/plan/client/filesystem/read/file/cmd.sh
Normal file
3
tests/plan/client/filesystem/read/file/cmd.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
env
|
1
tests/plan/client/filesystem/read/file/secret.txt
Normal file
1
tests/plan/client/filesystem/read/file/secret.txt
Normal file
@@ -0,0 +1 @@
|
||||
bar
|
44
tests/plan/client/filesystem/read/file/test.cue
Normal file
44
tests/plan/client/filesystem/read/file/test.cue
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: filesystem: {
|
||||
"cmd.sh": read: contents: "env"
|
||||
"test.txt": read: contents: string
|
||||
"secret.txt": read: contents: dagger.#Secret
|
||||
}
|
||||
actions: {
|
||||
image: dagger.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
test: {
|
||||
concrete: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["sh", "-c", client.filesystem."cmd.sh".read.contents]
|
||||
}
|
||||
usage: {
|
||||
string: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["test", client.filesystem."test.txt".read.contents, "=", "foo"]
|
||||
}
|
||||
secret: dagger.#Exec & {
|
||||
input: image.output
|
||||
mounts: secret: {
|
||||
dest: "/run/secrets/test"
|
||||
contents: client.filesystem."secret.txt".read.contents
|
||||
}
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
test "$(cat /run/secrets/test)" = "bar"
|
||||
ls -l /run/secrets/test | grep -- "-r--------"
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
tests/plan/client/filesystem/read/file/test.txt
Normal file
1
tests/plan/client/filesystem/read/file/test.txt
Normal file
@@ -0,0 +1 @@
|
||||
foo
|
11
tests/plan/client/filesystem/read/fs/not_exists/test.cue
Normal file
11
tests/plan/client/filesystem/read/fs/not_exists/test.cue
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: filesystem: "/foobar": read: contents: dagger.#FS
|
||||
actions: test: {
|
||||
}
|
||||
}
|
22
tests/plan/client/filesystem/read/fs/relative/test.cue
Normal file
22
tests/plan/client/filesystem/read/fs/relative/test.cue
Normal file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: filesystem: "../rootfs": read: {
|
||||
contents: dagger.#FS
|
||||
include: ["*.txt"]
|
||||
}
|
||||
actions: test: {
|
||||
[string]: dagger.#ReadFile & {
|
||||
input: client.filesystem."../rootfs".read.contents
|
||||
}
|
||||
valid: {
|
||||
path: "test.txt"
|
||||
contents: "local directory"
|
||||
}
|
||||
notIncluded: path: "test.log"
|
||||
}
|
||||
}
|
1
tests/plan/client/filesystem/read/fs/rootfs/test.log
Normal file
1
tests/plan/client/filesystem/read/fs/rootfs/test.log
Normal file
@@ -0,0 +1 @@
|
||||
excluded
|
1
tests/plan/client/filesystem/read/fs/rootfs/test.txt
Normal file
1
tests/plan/client/filesystem/read/fs/rootfs/test.txt
Normal file
@@ -0,0 +1 @@
|
||||
local directory
|
27
tests/plan/client/filesystem/read/fs/usage/test.cue
Normal file
27
tests/plan/client/filesystem/read/fs/usage/test.cue
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: filesystem: rootfs: read: {
|
||||
contents: dagger.#FS
|
||||
exclude: ["*.log"]
|
||||
}
|
||||
actions: test: {
|
||||
[string]: dagger.#ReadFile & {
|
||||
input: client.filesystem.rootfs.read.contents
|
||||
}
|
||||
valid: {
|
||||
path: "test.txt"
|
||||
contents: "local directory"
|
||||
}
|
||||
conflictingValues: {
|
||||
path: "test.txt"
|
||||
contents: "local foobar"
|
||||
}
|
||||
excluded: path: "test.log"
|
||||
notExists: path: "test.json"
|
||||
}
|
||||
}
|
29
tests/plan/client/filesystem/read/service/invalid.cue
Normal file
29
tests/plan/client/filesystem/read/service/invalid.cue
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: filesystem: "/var/run/docker.soc": read: contents: dagger.#Service
|
||||
|
||||
actions: {
|
||||
image: dagger.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
imageWithDocker: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["apk", "add", "--no-cache", "docker-cli"]
|
||||
}
|
||||
|
||||
test: dagger.#Exec & {
|
||||
input: imageWithDocker.output
|
||||
mounts: docker: {
|
||||
dest: "/var/run/docker.sock"
|
||||
contents: client.filesystem."/var/run/docker.soc".read.contents
|
||||
}
|
||||
args: ["docker", "info"]
|
||||
}
|
||||
}
|
||||
}
|
29
tests/plan/client/filesystem/read/service/valid.cue
Normal file
29
tests/plan/client/filesystem/read/service/valid.cue
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: filesystem: "/var/run/docker.sock": read: contents: dagger.#Service
|
||||
|
||||
actions: {
|
||||
image: dagger.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
imageWithDocker: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["apk", "add", "--no-cache", "docker-cli"]
|
||||
}
|
||||
|
||||
test: dagger.#Exec & {
|
||||
input: imageWithDocker.output
|
||||
mounts: docker: {
|
||||
dest: "/var/run/docker.sock"
|
||||
contents: client.filesystem."/var/run/docker.sock".read.contents
|
||||
}
|
||||
args: ["docker", "info"]
|
||||
}
|
||||
}
|
||||
}
|
29
tests/plan/client/filesystem/read/service/windows.cue
Normal file
29
tests/plan/client/filesystem/read/service/windows.cue
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: filesystem: "//./pipe/docker_engine": read: contents: dagger.#Service
|
||||
|
||||
actions: {
|
||||
image: dagger.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
imageWithDocker: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["apk", "add", "--no-cache", "docker-cli"]
|
||||
}
|
||||
|
||||
test: dagger.#Exec & {
|
||||
input: imageWithDocker.output
|
||||
mounts: docker: {
|
||||
dest: "/var/run/docker.sock"
|
||||
contents: client.filesystem."//./pipe/docker_engine".read.contents
|
||||
}
|
||||
args: ["docker", "info"]
|
||||
}
|
||||
}
|
||||
}
|
69
tests/plan/client/filesystem/write/test.cue
Normal file
69
tests/plan/client/filesystem/write/test.cue
Normal file
@@ -0,0 +1,69 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
client: filesystem: {
|
||||
out_fs: write: contents: actions.test.fs.data.output
|
||||
"out_files/test.txt": write: contents: actions.test.file.data.contents
|
||||
"out_files/secret.txt": write: {
|
||||
contents: actions.test.secret.data.output
|
||||
permissions: 0o600
|
||||
}
|
||||
}
|
||||
|
||||
actions: {
|
||||
image: dagger.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
test: {
|
||||
fs: {
|
||||
data: dagger.#WriteFile & {
|
||||
input: dagger.#Scratch
|
||||
path: "/test"
|
||||
contents: "foobar"
|
||||
}
|
||||
// FIXME: hack until we can do outputs with `dagger do`
|
||||
verify: dagger.#ReadFile & {
|
||||
input: client.filesystem."out_fs".write.contents
|
||||
path: "test"
|
||||
}
|
||||
}
|
||||
file: {
|
||||
// Only using contents for reference in client
|
||||
data: dagger.#WriteFile & {
|
||||
input: dagger.#Scratch
|
||||
path: "/test"
|
||||
contents: "foobaz"
|
||||
}
|
||||
// FIXME: hack until we can do outputs with `dagger do`
|
||||
verify: dagger.#Exec & {
|
||||
input: image.output
|
||||
args: ["echo", "-c", client.filesystem."out_files/test.txt".write.contents]
|
||||
}
|
||||
}
|
||||
secret: {
|
||||
create: dagger.#WriteFile & {
|
||||
input: dagger.#Scratch
|
||||
path: "/test"
|
||||
contents: "foo-barab-oof"
|
||||
}
|
||||
data: dagger.#NewSecret & {
|
||||
input: create.output
|
||||
path: "/test"
|
||||
}
|
||||
// FIXME: hack until we can do outputs with `dagger do`
|
||||
verify: dagger.#Exec & {
|
||||
input: image.output
|
||||
mounts: secret: {
|
||||
dest: "/run/secrets/test"
|
||||
contents: client.filesystem."out_files/secret.txt".write.contents
|
||||
}
|
||||
args: ["id"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user