Add new Client API
Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
This commit is contained in:
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