docker: cleanup tests

Signed-off-by: Solomon Hykes <solomon@dagger.io>
This commit is contained in:
Solomon Hykes 2022-02-09 00:20:11 +00:00
parent 090ecfb9f2
commit 20e1ac9d7f
15 changed files with 321 additions and 428 deletions

View File

@ -1,52 +0,0 @@
package test
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
)
// This test verify that we can correctly build an image
// using docker.#Build with multiple steps executed during
// the building process
dagger.#Plan & {
actions: {
image: docker.#Build & {
steps: [
alpine.#Build,
docker.#Run & {
command: {
name: "sh"
flags: "-c": """
echo -n hello > /bar.txt
"""
}
},
docker.#Run & {
command: {
name: "sh"
flags: "-c": """
echo -n $(cat /bar.txt) world > /foo.txt
"""
}
},
docker.#Run & {
command: {
name: "sh"
flags: "-c": """
echo -n $(cat /foo.txt) >> /test.txt
"""
}
},
]
}
verify: engine.#ReadFile & {
input: image.output.rootfs
path: "/test.txt"
} & {
contents: "hello world"
}
}
}

View File

@ -1,36 +0,0 @@
package test
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
)
// This test verify that we can correctly build a simplistic image
// using docker.#Build
dagger.#Plan & {
#testValue: "hello world"
actions: {
image: docker.#Build & {
steps: [
alpine.#Build,
docker.#Run & {
command: {
name: "sh"
flags: "-c": "echo -n $TEST >> /test.txt"
}
env: TEST: #testValue
},
]
}
verify: engine.#ReadFile & {
input: image.output.rootfs
path: "/test.txt"
} & {
contents: #testValue
}
}
}

View File

@ -0,0 +1,120 @@
package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/alpine"
"universe.dagger.io/docker"
)
dagger.#Plan & {
actions: tests: build: {
// Test: simple docker.#Build
simple: {
#testValue: "hello world"
image: docker.#Build & {
steps: [
alpine.#Build,
docker.#Run & {
command: {
name: "sh"
flags: "-c": "echo -n $TEST >> /test.txt"
}
env: TEST: #testValue
},
]
}
verify: engine.#ReadFile & {
input: image.output.rootfs
path: "/test.txt"
}
verify: contents: #testValue
}
// Test: docker.#Build with multiple steps
multiSteps: {
image: docker.#Build & {
steps: [
alpine.#Build,
docker.#Run & {
command: {
name: "sh"
flags: "-c": "echo -n hello > /bar.txt"
}
},
docker.#Run & {
command: {
name: "sh"
flags: "-c": "echo -n $(cat /bar.txt) world > /foo.txt"
}
},
docker.#Run & {
command: {
name: "sh"
flags: "-c": "echo -n $(cat /foo.txt) >> /test.txt"
}
},
]
}
verify: engine.#ReadFile & {
input: image.output.rootfs
path: "/test.txt"
}
verify: contents: "hello world"
}
// Test: simple nesting of docker.#Build
nested: {
build: docker.#Build & {
steps: [
docker.#Build & {
steps: [
docker.#Pull & {
source: "alpine"
},
docker.#Run & {
command: name: "ls"
},
]
},
docker.#Run & {
command: name: "ls"
},
]
}
}
// Test: nested docker.#Build with 3+ levels of depth
// FIXME: this test currently fails.
nestedDeep: {
// build: docker.#Build & {
// steps: [
// docker.#Build & {
// steps: [
// docker.#Build & {
// steps: [
// docker.#Pull & {
// source: "alpine"
// },
// docker.#Run & {
// command: name: "ls"
// },
// ]
// },
// docker.#Run & {
// command: name: "ls"
// },
// ]
// },
// docker.#Run & {
// command: name: "ls"
// },
// ]
// }
}
}
}

View File

@ -1,28 +0,0 @@
setup() {
load '../../bats_helpers'
common_setup
}
@test "docker.#Build" {
dagger up ./build-simple.cue
dagger up ./build-multi-steps.cue
dagger up ./nested-build-test.cue
# FIXME: this is currently broken
run dagger up ./multi-nested-build-test.cue
assert_failure
}
@test "docker.#Run" {
dagger up ./run-command-test.cue
dagger up ./run-script-test.cue
dagger up ./run-export-file-test.cue
dagger up ./run-export-directory-test.cue
dagger up ./image-config-test.cue
}
@test "docker.#Set" {
dagger up ./set.cue
}

View File

@ -1,84 +0,0 @@
package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/docker"
)
dagger.#Plan & {
actions: {
build: engine.#Dockerfile & {
source: engine.#Scratch
dockerfile: contents: """
FROM alpine:3.15.0
RUN echo -n 'not hello from dagger' > /dagger.txt
RUN echo '#!/bin/sh' > /bin/dagger
ENV HELLO_FROM=dagger
RUN echo 'echo -n "hello from $HELLO_FROM" > /dagger.txt' >> /bin/dagger
RUN chmod +x /bin/dagger
WORKDIR /bin
CMD /bin/dagger
"""
}
myimage: docker.#Image & {
rootfs: build.output
config: build.config
}
run: docker.#Run & {
image: myimage
command: name: "ls"
export: files: {
"/dagger.txt": _ & {
contents: "not hello from dagger"
}
"/bin/dagger": _ & {
contents: """
#!/bin/sh
echo -n "hello from $HELLO_FROM" > /dagger.txt
"""
}
}
}
verify_cmd_is_run: docker.#Run & {
image: myimage
export: files: "/dagger.txt": _ & {
contents: "hello from dagger"
}
}
verify_env_is_overridden: docker.#Run & {
image: myimage
export: files: "/dagger.txt": _ & {
contents: "hello from europa"
}
env: HELLO_FROM: "europa"
}
verify_working_directory: docker.#Run & {
image: myimage
command: {
name: "sh"
flags: "-c": #"""
pwd > dir.txt
"""#
}
export: files: "/bin/dir.txt": _ & {
contents: "/bin\n"
}
}
verify_working_directory_is_overridden: docker.#Run & {
image: myimage
workdir: "/"
command: {
name: "sh"
flags: "-c": #"""
pwd > dir.txt
"""#
}
export: files: "/dir.txt": _ & {
contents: "/\n"
}
}
}
}

View File

@ -0,0 +1,121 @@
package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/docker"
)
dagger.#Plan & {
actions: tests: image: {
// Test: change image config with docker.#Set
set: {
image: output: docker.#Image & {
rootfs: engine.#Scratch
config: {
cmd: ["/bin/sh"]
env: PATH: "/sbin:/bin"
onbuild: ["COPY . /app"]
}
}
set: docker.#Set & {
input: image.output
config: {
env: FOO: "bar"
workdir: "/root"
onbuild: ["RUN /app/build.sh"]
}
}
verify: set.output.config & {
env: {
PATH: "/sbin:/bin"
FOO: "bar"
}
cmd: ["/bin/sh"]
workdir: "/root"
onbuild: [
"COPY . /app",
"RUN /app/build.sh",
]
}
}
// Test: image config behavior is correct
config: {
build: engine.#Dockerfile & {
source: engine.#Scratch
dockerfile: contents: """
FROM alpine:3.15.0
RUN echo -n 'not hello from dagger' > /dagger.txt
RUN echo '#!/bin/sh' > /bin/dagger
ENV HELLO_FROM=dagger
RUN echo 'echo -n "hello from $HELLO_FROM" > /dagger.txt' >> /bin/dagger
RUN chmod +x /bin/dagger
WORKDIR /bin
CMD /bin/dagger
"""
}
myimage: docker.#Image & {
rootfs: build.output
config: build.config
}
run: docker.#Run & {
image: myimage
command: name: "ls"
export: files: {
"/dagger.txt": _ & {
contents: "not hello from dagger"
}
"/bin/dagger": _ & {
contents: """
#!/bin/sh
echo -n "hello from $HELLO_FROM" > /dagger.txt
"""
}
}
}
verify_cmd_is_run: docker.#Run & {
image: myimage
export: files: "/dagger.txt": _ & {
contents: "hello from dagger"
}
}
verify_env_is_overridden: docker.#Run & {
image: myimage
export: files: "/dagger.txt": _ & {
contents: "hello from europa"
}
env: HELLO_FROM: "europa"
}
verify_working_directory: docker.#Run & {
image: myimage
command: {
name: "sh"
flags: "-c": #"""
pwd > dir.txt
"""#
}
export: files: "/bin/dir.txt": _ & {
contents: "/bin\n"
}
}
verify_working_directory_is_overridden: docker.#Run & {
image: myimage
workdir: "/"
command: {
name: "sh"
flags: "-c": #"""
pwd > dir.txt
"""#
}
export: files: "/dir.txt": _ & {
contents: "/\n"
}
}
}
}
}

View File

@ -1,34 +0,0 @@
package docker
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
)
// FIXME: this test is currently broken (see docker.bats)
dagger.#Plan & {
actions: build: docker.#Build & {
steps: [
docker.#Build & {
steps: [
docker.#Build & {
steps: [
docker.#Pull & {
source: "alpine"
},
docker.#Run & {
command: name: "ls"
},
]
},
docker.#Run & {
command: name: "ls"
},
]
},
docker.#Run & {
command: name: "ls"
},
]
}
}

View File

@ -1,26 +0,0 @@
package docker
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
)
dagger.#Plan & {
actions: build: docker.#Build & {
steps: [
docker.#Build & {
steps: [
docker.#Pull & {
source: "alpine"
},
docker.#Run & {
command: name: "ls"
},
]
},
docker.#Run & {
command: name: "ls"
},
]
}
}

View File

@ -1,29 +0,0 @@
package test
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
)
dagger.#Plan & {
actions: {
image: alpine.#Build
run: docker.#Run & {
"image": image.output
command: {
name: "/bin/sh"
args: ["-c", "echo -n hello world >> /output.txt"]
}
}
verify: engine.#ReadFile & {
input: run.output.rootfs
path: "/output.txt"
} & {
contents: "hello world"
}
}
}

View File

@ -1,41 +0,0 @@
package test
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
)
dagger.#Plan & {
actions: {
image: alpine.#Build
run: docker.#Run & {
"image": image.output
command: {
name: "sh"
flags: "-c": #"""
mkdir -p test
echo -n hello world >> /test/output.txt
"""#
}
export: {
directories: "/test": _
files: "/test/output.txt": _ & {
contents: "hello world"
}
}
} & {
completed: true
success: true
}
verify: engine.#ReadFile & {
input: run.export.directories."/test".contents
path: "/output.txt"
} & {
contents: run.export.files."/test/output.txt".contents
}
}
}

View File

@ -1,26 +0,0 @@
package test
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
)
dagger.#Plan & {
actions: {
image: alpine.#Build
run: docker.#Run & {
"image": image.output
command: {
name: "sh"
flags: "-c": #"""
echo -n hello world >> /output.txt
"""#
}
export: files: "/output.txt": _ & {
contents: "hello world"
}
}
}
}

View File

@ -1,32 +0,0 @@
package test
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
)
dagger.#Plan & {
actions: {
image: alpine.#Build
run: docker.#Run & {
"image": image.output
command: {
name: "sh"
flags: "-c": #"""
echo -n $TEST_MESSAGE >> /output.txt
"""#
}
env: TEST_MESSAGE: "hello world"
}
verify: engine.#ReadFile & {
input: run.output.rootfs
path: "/output.txt"
} & {
contents: "hello world"
}
}
}

View File

@ -0,0 +1,71 @@
package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
)
dagger.#Plan & {
actions: tests: run: {
_build: alpine.#Build
_image: _build.output
// Test: run a simple shell command
simpleShell: {
image: alpine.#Build
run: docker.#Run & {
image: _image
command: {
name: "/bin/sh"
args: ["-c", "echo -n hello world >> /output.txt"]
}
}
verify: engine.#ReadFile & {
input: run.output.rootfs
path: "/output.txt"
}
verify: contents: "hello world"
}
// Test: export a file
exportFile: {
image: _image
command: {
name: "sh"
flags: "-c": #"""
echo -n hello world >> /output.txt
"""#
}
export: files: "/output.txt": _ & {
// Assert content
contents: "hello world"
}
}
// Test: export a directory
exportDirectory: {
run: docker.#Run & {
image: _image
command: {
name: "sh"
flags: "-c": #"""
mkdir -p /test
echo -n hello world >> /test/output.txt
"""#
}
export: directories: "/test": _
}
verify: engine.#ReadFile & {
input: run.export.directories."/test".contents
path: "/output.txt"
}
verify: contents: "hello world"
}
}
}

View File

@ -1,40 +0,0 @@
package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/docker"
)
dagger.#Plan & {
actions: {
image: output: docker.#Image & {
rootfs: engine.#Scratch
config: {
cmd: ["/bin/sh"]
env: PATH: "/sbin:/bin"
onbuild: ["COPY . /app"]
}
}
set: docker.#Set & {
input: image.output
config: {
env: FOO: "bar"
workdir: "/root"
onbuild: ["RUN /app/build.sh"]
}
}
verify: set.output.config & {
env: {
PATH: "/sbin:/bin"
FOO: "bar"
}
cmd: ["/bin/sh"]
workdir: "/root"
onbuild: [
"COPY . /app",
"RUN /app/build.sh",
]
}
}
}

View File

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