From cf6fadbedabf0fa82e087c5d0f06dae29ceb3c66 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 8 Feb 2022 23:29:00 +0000 Subject: [PATCH 1/4] alpine: cleanup tests Signed-off-by: Solomon Hykes --- .../alpine/test/alpine.bats | 10 ---- .../alpine/test/image-version.cue | 22 -------- .../alpine/test/package-install.cue | 34 ------------ pkg/universe.dagger.io/alpine/test/test.bats | 8 +++ pkg/universe.dagger.io/alpine/test/test.cue | 53 +++++++++++++++++++ 5 files changed, 61 insertions(+), 66 deletions(-) delete mode 100644 pkg/universe.dagger.io/alpine/test/alpine.bats delete mode 100644 pkg/universe.dagger.io/alpine/test/image-version.cue delete mode 100644 pkg/universe.dagger.io/alpine/test/package-install.cue create mode 100644 pkg/universe.dagger.io/alpine/test/test.bats create mode 100644 pkg/universe.dagger.io/alpine/test/test.cue diff --git a/pkg/universe.dagger.io/alpine/test/alpine.bats b/pkg/universe.dagger.io/alpine/test/alpine.bats deleted file mode 100644 index 05854ffa..00000000 --- a/pkg/universe.dagger.io/alpine/test/alpine.bats +++ /dev/null @@ -1,10 +0,0 @@ -setup() { - load '../../bats_helpers' - - common_setup -} - -@test "alpine.#Build" { - dagger up ./image-version.cue - dagger up ./package-install.cue -} \ No newline at end of file diff --git a/pkg/universe.dagger.io/alpine/test/image-version.cue b/pkg/universe.dagger.io/alpine/test/image-version.cue deleted file mode 100644 index 2a912ff6..00000000 --- a/pkg/universe.dagger.io/alpine/test/image-version.cue +++ /dev/null @@ -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" - } - } -} diff --git a/pkg/universe.dagger.io/alpine/test/package-install.cue b/pkg/universe.dagger.io/alpine/test/package-install.cue deleted file mode 100644 index 7a5a4689..00000000 --- a/pkg/universe.dagger.io/alpine/test/package-install.cue +++ /dev/null @@ -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" - } - } - } -} diff --git a/pkg/universe.dagger.io/alpine/test/test.bats b/pkg/universe.dagger.io/alpine/test/test.bats new file mode 100644 index 00000000..4c4c4c7b --- /dev/null +++ b/pkg/universe.dagger.io/alpine/test/test.bats @@ -0,0 +1,8 @@ +setup() { + load '../../bats_helpers' + + common_setup +} +@test "alpine" { + dagger up +} diff --git a/pkg/universe.dagger.io/alpine/test/test.cue b/pkg/universe.dagger.io/alpine/test/test.cue new file mode 100644 index 00000000..d3691d8d --- /dev/null +++ b/pkg/universe.dagger.io/alpine/test/test.cue @@ -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" + } + } + } + } +} From 090ecfb9f2529c668ae4d9a1090b61fcb86badb6 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 8 Feb 2022 23:47:28 +0000 Subject: [PATCH 2/4] bash: cleanup tests Signed-off-by: Solomon Hykes --- .../bash/test/{run-simple => data}/hello.sh | 0 .../bash/test/run-simple/simple.cue | 87 ------------------- .../bash/test/{bash.bats => test.bats} | 4 +- pkg/universe.dagger.io/bash/test/test.cue | 49 +++++++++++ 4 files changed, 51 insertions(+), 89 deletions(-) rename pkg/universe.dagger.io/bash/test/{run-simple => data}/hello.sh (100%) delete mode 100644 pkg/universe.dagger.io/bash/test/run-simple/simple.cue rename pkg/universe.dagger.io/bash/test/{bash.bats => test.bats} (57%) create mode 100644 pkg/universe.dagger.io/bash/test/test.cue diff --git a/pkg/universe.dagger.io/bash/test/run-simple/hello.sh b/pkg/universe.dagger.io/bash/test/data/hello.sh similarity index 100% rename from pkg/universe.dagger.io/bash/test/run-simple/hello.sh rename to pkg/universe.dagger.io/bash/test/data/hello.sh diff --git a/pkg/universe.dagger.io/bash/test/run-simple/simple.cue b/pkg/universe.dagger.io/bash/test/run-simple/simple.cue deleted file mode 100644 index 3227b9b0..00000000 --- a/pkg/universe.dagger.io/bash/test/run-simple/simple.cue +++ /dev/null @@ -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"] - } - } -} diff --git a/pkg/universe.dagger.io/bash/test/bash.bats b/pkg/universe.dagger.io/bash/test/test.bats similarity index 57% rename from pkg/universe.dagger.io/bash/test/bash.bats rename to pkg/universe.dagger.io/bash/test/test.bats index 42186abf..52dc4dc7 100644 --- a/pkg/universe.dagger.io/bash/test/bash.bats +++ b/pkg/universe.dagger.io/bash/test/test.bats @@ -4,7 +4,7 @@ setup() { common_setup } -@test "bash.#Run" { - dagger up ./run-simple +@test "bash" { + dagger up } diff --git a/pkg/universe.dagger.io/bash/test/test.cue b/pkg/universe.dagger.io/bash/test/test.cue new file mode 100644 index 00000000..bde6af9f --- /dev/null +++ b/pkg/universe.dagger.io/bash/test/test.cue @@ -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" + } + + } +} From 20e1ac9d7fc94a3bf94275e301fe9714eda2bab8 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 9 Feb 2022 00:20:11 +0000 Subject: [PATCH 3/4] docker: cleanup tests Signed-off-by: Solomon Hykes --- .../docker/test/build-multi-steps.cue | 52 -------- .../docker/test/build-simple.cue | 36 ------ pkg/universe.dagger.io/docker/test/build.cue | 120 +++++++++++++++++ .../docker/test/docker.bats | 28 ---- .../docker/test/image-config-test.cue | 84 ------------ pkg/universe.dagger.io/docker/test/image.cue | 121 ++++++++++++++++++ .../docker/test/multi-nested-build-test.cue | 34 ----- .../docker/test/nested-build-test.cue | 26 ---- .../docker/test/run-command-test.cue | 29 ----- .../docker/test/run-export-directory-test.cue | 41 ------ .../docker/test/run-export-file-test.cue | 26 ---- .../docker/test/run-script-test.cue | 32 ----- pkg/universe.dagger.io/docker/test/run.cue | 71 ++++++++++ pkg/universe.dagger.io/docker/test/set.cue | 40 ------ pkg/universe.dagger.io/docker/test/test.bats | 9 ++ 15 files changed, 321 insertions(+), 428 deletions(-) delete mode 100644 pkg/universe.dagger.io/docker/test/build-multi-steps.cue delete mode 100644 pkg/universe.dagger.io/docker/test/build-simple.cue create mode 100644 pkg/universe.dagger.io/docker/test/build.cue delete mode 100644 pkg/universe.dagger.io/docker/test/docker.bats delete mode 100644 pkg/universe.dagger.io/docker/test/image-config-test.cue create mode 100644 pkg/universe.dagger.io/docker/test/image.cue delete mode 100644 pkg/universe.dagger.io/docker/test/multi-nested-build-test.cue delete mode 100644 pkg/universe.dagger.io/docker/test/nested-build-test.cue delete mode 100644 pkg/universe.dagger.io/docker/test/run-command-test.cue delete mode 100644 pkg/universe.dagger.io/docker/test/run-export-directory-test.cue delete mode 100644 pkg/universe.dagger.io/docker/test/run-export-file-test.cue delete mode 100644 pkg/universe.dagger.io/docker/test/run-script-test.cue create mode 100644 pkg/universe.dagger.io/docker/test/run.cue delete mode 100644 pkg/universe.dagger.io/docker/test/set.cue create mode 100644 pkg/universe.dagger.io/docker/test/test.bats diff --git a/pkg/universe.dagger.io/docker/test/build-multi-steps.cue b/pkg/universe.dagger.io/docker/test/build-multi-steps.cue deleted file mode 100644 index f4fc6ce1..00000000 --- a/pkg/universe.dagger.io/docker/test/build-multi-steps.cue +++ /dev/null @@ -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" - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/build-simple.cue b/pkg/universe.dagger.io/docker/test/build-simple.cue deleted file mode 100644 index 35290671..00000000 --- a/pkg/universe.dagger.io/docker/test/build-simple.cue +++ /dev/null @@ -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 - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/build.cue b/pkg/universe.dagger.io/docker/test/build.cue new file mode 100644 index 00000000..061c605c --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/build.cue @@ -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" + // }, + // ] + // } + } + } +} diff --git a/pkg/universe.dagger.io/docker/test/docker.bats b/pkg/universe.dagger.io/docker/test/docker.bats deleted file mode 100644 index 8198c44d..00000000 --- a/pkg/universe.dagger.io/docker/test/docker.bats +++ /dev/null @@ -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 -} diff --git a/pkg/universe.dagger.io/docker/test/image-config-test.cue b/pkg/universe.dagger.io/docker/test/image-config-test.cue deleted file mode 100644 index f1d5d2e1..00000000 --- a/pkg/universe.dagger.io/docker/test/image-config-test.cue +++ /dev/null @@ -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" - } - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/image.cue b/pkg/universe.dagger.io/docker/test/image.cue new file mode 100644 index 00000000..98ba4576 --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/image.cue @@ -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" + } + } + } + } +} diff --git a/pkg/universe.dagger.io/docker/test/multi-nested-build-test.cue b/pkg/universe.dagger.io/docker/test/multi-nested-build-test.cue deleted file mode 100644 index 40c95e2e..00000000 --- a/pkg/universe.dagger.io/docker/test/multi-nested-build-test.cue +++ /dev/null @@ -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" - }, - ] - } -} diff --git a/pkg/universe.dagger.io/docker/test/nested-build-test.cue b/pkg/universe.dagger.io/docker/test/nested-build-test.cue deleted file mode 100644 index e1adb995..00000000 --- a/pkg/universe.dagger.io/docker/test/nested-build-test.cue +++ /dev/null @@ -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" - }, - ] - } -} diff --git a/pkg/universe.dagger.io/docker/test/run-command-test.cue b/pkg/universe.dagger.io/docker/test/run-command-test.cue deleted file mode 100644 index b7e03070..00000000 --- a/pkg/universe.dagger.io/docker/test/run-command-test.cue +++ /dev/null @@ -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" - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/run-export-directory-test.cue b/pkg/universe.dagger.io/docker/test/run-export-directory-test.cue deleted file mode 100644 index e167169a..00000000 --- a/pkg/universe.dagger.io/docker/test/run-export-directory-test.cue +++ /dev/null @@ -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 - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/run-export-file-test.cue b/pkg/universe.dagger.io/docker/test/run-export-file-test.cue deleted file mode 100644 index 664a5b59..00000000 --- a/pkg/universe.dagger.io/docker/test/run-export-file-test.cue +++ /dev/null @@ -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" - } - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/run-script-test.cue b/pkg/universe.dagger.io/docker/test/run-script-test.cue deleted file mode 100644 index 08832b3e..00000000 --- a/pkg/universe.dagger.io/docker/test/run-script-test.cue +++ /dev/null @@ -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" - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/run.cue b/pkg/universe.dagger.io/docker/test/run.cue new file mode 100644 index 00000000..d0ce07af --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/run.cue @@ -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" + } + } +} diff --git a/pkg/universe.dagger.io/docker/test/set.cue b/pkg/universe.dagger.io/docker/test/set.cue deleted file mode 100644 index b19ff93d..00000000 --- a/pkg/universe.dagger.io/docker/test/set.cue +++ /dev/null @@ -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", - ] - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/test.bats b/pkg/universe.dagger.io/docker/test/test.bats new file mode 100644 index 00000000..f8fbedda --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/test.bats @@ -0,0 +1,9 @@ +setup() { + load '../../bats_helpers' + + common_setup +} + +@test "docker" { + dagger up +} From 7502bc876bccac08356d6010f44564c00f6bbbc6 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 9 Feb 2022 00:26:12 +0000 Subject: [PATCH 4/4] netlify: cleanup tests Signed-off-by: Solomon Hykes --- .../netlify/test/netlify-test.cue | 56 ------------------ .../netlify/test/{netlify.bats => test.bats} | 4 +- pkg/universe.dagger.io/netlify/test/test.cue | 59 +++++++++++++++++++ 3 files changed, 61 insertions(+), 58 deletions(-) delete mode 100644 pkg/universe.dagger.io/netlify/test/netlify-test.cue rename pkg/universe.dagger.io/netlify/test/{netlify.bats => test.bats} (51%) create mode 100644 pkg/universe.dagger.io/netlify/test/test.cue diff --git a/pkg/universe.dagger.io/netlify/test/netlify-test.cue b/pkg/universe.dagger.io/netlify/test/netlify-test.cue deleted file mode 100644 index 4de4864d..00000000 --- a/pkg/universe.dagger.io/netlify/test/netlify-test.cue +++ /dev/null @@ -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)" - """# - } - } -} diff --git a/pkg/universe.dagger.io/netlify/test/netlify.bats b/pkg/universe.dagger.io/netlify/test/test.bats similarity index 51% rename from pkg/universe.dagger.io/netlify/test/netlify.bats rename to pkg/universe.dagger.io/netlify/test/test.bats index 9f665e9e..29f6d1d1 100644 --- a/pkg/universe.dagger.io/netlify/test/netlify.bats +++ b/pkg/universe.dagger.io/netlify/test/test.bats @@ -4,6 +4,6 @@ setup() { common_setup } -@test "netlify.#Deploy" { - dagger up ./netlify-test.cue +@test "netlify" { + dagger up } diff --git a/pkg/universe.dagger.io/netlify/test/test.cue b/pkg/universe.dagger.io/netlify/test/test.cue new file mode 100644 index 00000000..3a486b1d --- /dev/null +++ b/pkg/universe.dagger.io/netlify/test/test.cue @@ -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)" + """# + } + } + } +}