From 090ecfb9f2529c668ae4d9a1090b61fcb86badb6 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 8 Feb 2022 23:47:28 +0000 Subject: [PATCH] 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" + } + + } +}