Merge pull request #1577 from shykes/universe-tests-cleanup

Cleanup universe tests
This commit is contained in:
Solomon Hykes 2022-02-08 19:52:33 -08:00 committed by GitHub
commit 4d345ccdef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 494 additions and 641 deletions

View File

@ -1,10 +0,0 @@
setup() {
load '../../bats_helpers'
common_setup
}
@test "alpine.#Build" {
dagger up ./image-version.cue
dagger up ./package-install.cue
}

View File

@ -1,22 +0,0 @@
package test
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/alpine"
)
dagger.#Plan & {
actions: {
build: alpine.#Build & {
// install an old version on purpose
version: "3.10.9"
}
check: engine.#Readfile & {
input: build.output.rootfs
path: "/etc/alpine-release"
contents: "3.10.9\n"
}
}
}

View File

@ -1,34 +0,0 @@
package test
import (
"dagger.io/dagger"
"universe.dagger.io/alpine"
"universe.dagger.io/docker"
)
dagger.#Plan & {
actions: {
build: alpine.#Build & {
packages: {
jq: {}
curl: {}
}
}
check: docker.#Run & {
image: build.output
command: {
name: "sh"
flags: "-c": """
jq --version > /jq-version.txt
curl --version > /curl-version.txt
"""
}
export: files: {
"/jq-version.txt": contents: =~"^jq"
"/curl-version.txt": contents: =~"^curl"
}
}
}
}

View File

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

View File

@ -0,0 +1,53 @@
package alpine
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/alpine"
"universe.dagger.io/docker"
)
dagger.#Plan & {
actions: tests: {
// Test: customize alpine version
alpineVersion: {
build: alpine.#Build & {
// install an old version on purpose
version: "3.10.9"
}
verify: engine.#Readfile & {
input: build.output.rootfs
path: "/etc/alpine-release"
contents: "3.10.9\n"
}
}
// Test: install packages
packageInstall: {
build: alpine.#Build & {
packages: {
jq: {}
curl: {}
}
}
check: docker.#Run & {
image: build.output
command: {
name: "sh"
flags: "-c": """
jq --version > /jq-version.txt
curl --version > /curl-version.txt
"""
}
export: files: {
"/jq-version.txt": contents: =~"^jq"
"/curl-version.txt": contents: =~"^curl"
}
}
}
}
}

View File

@ -1,87 +0,0 @@
package bash
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
)
dagger.#DAG & {
actions: {
"Run from source directory": {
build: alpine.#Build & {
packages: bash: _
}
run: #Run & {
image: build.output
script: {
directory: loadScripts.output
filename: "hello.sh"
}
export: files: "/out.txt": _
}
output: run.export.files."/out.txt".contents & "Hello, world\n"
}
"Run from source directory with custom image": {
debian: docker.#Pull & {
source: "index.docker.io/debian"
}
run: #Run & {
image: debian.output
export: files: "/out.txt": _
script: {
directory: loadScripts.output
filename: "hello.sh"
}
}
output: run.export.files."/out.txt".contents & "Hello, world\n"
}
"Run from string": {
run: #Run & {
script: contents: "echo 'Hello, inlined world!' > /output.txt"
export: files: "/output.txt": _
}
output: run.export.files."/output.txt".contents & "Hello, inlined world!\n"
}
"Run from string with custom image": {
debian: docker.#Pull & {
source: "index.docker.io/debian"
}
run: #Run & {
image: debian.output
export: files: "/output.txt": _
script: contents: "echo 'Hello, inlined world!' > /output.txt"
}
output: run.export.files."/output.txt".contents & "Hello, inlined world!\n"
}
// Same thing but without bash.#Run
control: {
run: docker.#Run & {
image: base.output
command: {
name: "sh"
args: ["/bash/scripts/hello.sh"]
}
mounts: scripts: {
contents: loadScripts.output
dest: "/bash/scripts"
}
export: files: "/out.txt": _
}
output: run.export.files."/out.txt".contents & "Hello, world\n"
base: docker.#Pull & {
source: "alpine"
}
}
loadScripts: dagger.#Source & {
path: "."
include: ["*.sh"]
}
}
}

View File

@ -4,7 +4,7 @@ setup() {
common_setup common_setup
} }
@test "bash.#Run" { @test "bash" {
dagger up ./run-simple dagger up
} }

View File

@ -0,0 +1,49 @@
package bash
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
"universe.dagger.io/bash"
)
dagger.#Plan & {
actions: tests: {
_pull: docker.#Pull & {
source: "index.docker.io/debian"
}
_image: _pull.output
// Run a script from source directory + filename
runFile: {
dir: _load.output
_load: dagger.#Source & {
path: "./data"
include: ["*.sh"]
}
run: bash.#Run & {
image: _image
export: files: "/out.txt": _
script: {
directory: dir
filename: "hello.sh"
}
}
output: run.export.files."/out.txt".contents & "Hello, world\n"
}
// Run a script from string
runString: {
run: bash.#Run & {
image: _image
export: files: "/output.txt": _
script: contents: "echo 'Hello, inlined world!' > /output.txt"
}
output: run.export.files."/output.txt".contents & "Hello, inlined world!\n"
}
}
}

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

@ -4,6 +4,6 @@ setup() {
common_setup common_setup
} }
@test "netlify.#Deploy" { @test "docker" {
dagger up ./netlify-test.cue dagger up
} }

View File

@ -1,56 +0,0 @@
package yarn
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/netlify"
"universe.dagger.io/alpine"
"universe.dagger.io/bash"
)
dagger.#Plan & {
inputs: secrets: test: command: {
name: "sops"
args: ["-d", "../../test_secrets.yaml"]
}
actions: {
testSecrets: dagger.#DecodeSecret & {
input: inputs.secrets.test.contents
format: "yaml"
}
marker: "hello world"
data: engine.#WriteFile & {
input: engine.#Scratch
path: "index.html"
contents: marker
}
// Deploy to netlify
deploy: netlify.#Deploy & {
team: "blocklayer"
token: testSecrets.output.netlifyToken.contents
site: "dagger-test"
contents: data.output
}
image: alpine.#Build & {
packages: {
bash: {}
curl: {}
}
}
// Check if the website was deployed
verify: bash.#Run & {
input: image.output
script: contents: #"""
test "$(curl \#(deploy.deployUrl))" = "\#(marker)"
"""#
}
}
}

View File

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

View File

@ -0,0 +1,59 @@
package yarn
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/netlify"
"universe.dagger.io/alpine"
"universe.dagger.io/bash"
)
dagger.#Plan & {
inputs: secrets: test: command: {
name: "sops"
args: ["-d", "../../test_secrets.yaml"]
}
actions: tests: {
// Test: netlify.#Deploy correctly receives API token
receiveToken: {
testSecrets: dagger.#DecodeSecret & {
input: inputs.secrets.test.contents
format: "yaml"
}
marker: "hello world"
data: engine.#WriteFile & {
input: engine.#Scratch
path: "index.html"
contents: marker
}
// Deploy to netlify
deploy: netlify.#Deploy & {
team: "blocklayer"
token: testSecrets.output.netlifyToken.contents
site: "dagger-test"
contents: data.output
}
image: alpine.#Build & {
packages: {
bash: {}
curl: {}
}
}
// Check if the website was deployed
verify: bash.#Run & {
input: image.output
script: contents: #"""
test "$(curl \#(deploy.deployUrl))" = "\#(marker)"
"""#
}
}
}
}