@@ -23,4 +23,19 @@ setup() {
|
||||
cd "$TESTDIR"/tasks/writefile
|
||||
run "$DAGGER" --europa up ./writefile_failure_diff_contents.cue
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "task: #Exec" {
|
||||
cd "$TESTDIR"/tasks/exec
|
||||
"$DAGGER" --europa up ./args.cue
|
||||
"$DAGGER" --europa up ./env.cue
|
||||
"$DAGGER" --europa up ./hosts.cue
|
||||
|
||||
"$DAGGER" --europa up ./mount_cache.cue
|
||||
"$DAGGER" --europa up ./mount_fs.cue
|
||||
TESTSECRET="hello world" "$DAGGER" --europa up ./mount_secret.cue
|
||||
"$DAGGER" --europa up ./mount_tmp.cue
|
||||
|
||||
"$DAGGER" --europa up ./user.cue
|
||||
"$DAGGER" --europa up ./workdir.cue
|
||||
}
|
26
tests/tasks/exec/args.cue
Normal file
26
tests/tasks/exec/args.cue
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
exec: engine.#Exec & {
|
||||
input: image.output
|
||||
args: ["sh", "-c", "echo -n hello world > /output.txt"]
|
||||
}
|
||||
|
||||
verify: engine.#ReadFile & {
|
||||
input: exec.output
|
||||
path: "/output.txt"
|
||||
} & {
|
||||
// assert result
|
||||
contents: "hello world"
|
||||
}
|
||||
}
|
||||
}
|
1
tests/tasks/exec/cue.mod/module.cue
Normal file
1
tests/tasks/exec/cue.mod/module.cue
Normal file
@@ -0,0 +1 @@
|
||||
module: ""
|
3
tests/tasks/exec/cue.mod/pkg/.gitignore
vendored
Normal file
3
tests/tasks/exec/cue.mod/pkg/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# generated by dagger
|
||||
alpha.dagger.io
|
||||
dagger.lock
|
24
tests/tasks/exec/env.cue
Normal file
24
tests/tasks/exec/env.cue
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
verify: engine.#Exec & {
|
||||
input: image.output
|
||||
env: TEST: "hello world"
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
test "$TEST" = "hello world"
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
25
tests/tasks/exec/hosts.cue
Normal file
25
tests/tasks/exec/hosts.cue
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
verify: engine.#Exec & {
|
||||
input: image.output
|
||||
hosts: "unit.test": "1.2.3.4"
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
grep -q "unit.test" /etc/hosts
|
||||
grep -q "1.2.3.4" /etc/hosts
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
63
tests/tasks/exec/mount_cache.cue
Normal file
63
tests/tasks/exec/mount_cache.cue
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
sharedCache: engine.#CacheDir & {
|
||||
id: "mycache"
|
||||
}
|
||||
|
||||
exec: engine.#Exec & {
|
||||
input: image.output
|
||||
mounts: cache: {
|
||||
dest: "/cache"
|
||||
contents: sharedCache
|
||||
}
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
echo -n hello world > /cache/output.txt
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
|
||||
verify: engine.#Exec & {
|
||||
input: image.output
|
||||
mounts: cache: {
|
||||
dest: "/cache"
|
||||
contents: sharedCache
|
||||
}
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
test -f /cache/output.txt
|
||||
test "$(cat /cache/output.txt)" = "hello world"
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
|
||||
otherCache: engine.#CacheDir & {
|
||||
id: "othercache"
|
||||
}
|
||||
verifyOtherCache: engine.#Exec & {
|
||||
input: image.output
|
||||
mounts: cache: {
|
||||
dest: "/cache"
|
||||
contents: otherCache
|
||||
}
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
test ! -f /cache/output.txt
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
37
tests/tasks/exec/mount_fs.cue
Normal file
37
tests/tasks/exec/mount_fs.cue
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
exec: engine.#Exec & {
|
||||
input: image.output
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
echo -n hello world > /output.txt
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
|
||||
verify: engine.#Exec & {
|
||||
input: image.output
|
||||
mounts: fs: {
|
||||
dest: "/target"
|
||||
contents: exec.output
|
||||
}
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
test "$(cat /target/output.txt)" = "hello world"
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
28
tests/tasks/exec/mount_secret.cue
Normal file
28
tests/tasks/exec/mount_secret.cue
Normal file
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
context: secrets: testSecret: envvar: "TESTSECRET"
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
verify: engine.#Exec & {
|
||||
input: image.output
|
||||
mounts: secret: {
|
||||
dest: "/run/secrets/test"
|
||||
contents: context.secrets.testSecret.contents
|
||||
}
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
test "$(cat /run/secrets/test)" = "hello world"
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
37
tests/tasks/exec/mount_tmp.cue
Normal file
37
tests/tasks/exec/mount_tmp.cue
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
exec: engine.#Exec & {
|
||||
input: image.output
|
||||
mounts: temp: {
|
||||
dest: "/temp"
|
||||
contents: engine.#TempDir
|
||||
}
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
echo -n hello world > /temp/output.txt
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
|
||||
verify: engine.#Exec & {
|
||||
input: exec.output
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
test ! -f /temp/output.txt
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
41
tests/tasks/exec/user.cue
Normal file
41
tests/tasks/exec/user.cue
Normal file
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
addUser: engine.#Exec & {
|
||||
input: image.output
|
||||
args: ["adduser", "-D", "test"]
|
||||
}
|
||||
|
||||
verifyUsername: engine.#Exec & {
|
||||
input: addUser.output
|
||||
user: "test"
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
test "$(whoami)" = "test"
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
|
||||
verifyUserID: engine.#Exec & {
|
||||
input: addUser.output
|
||||
user: "1000"
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
test "$(whoami)" = "test"
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
24
tests/tasks/exec/workdir.cue
Normal file
24
tests/tasks/exec/workdir.cue
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/europa/dagger/engine"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
actions: {
|
||||
image: engine.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
|
||||
verify: engine.#Exec & {
|
||||
input: image.output
|
||||
workdir: "/tmp"
|
||||
args: [
|
||||
"sh", "-c",
|
||||
#"""
|
||||
test "$(pwd)" = "/tmp"
|
||||
"""#,
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user