From 81cdccf54130a449f1d6924eb00cb307feb5ce4c Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Wed, 24 Feb 2021 19:18:24 -0800 Subject: [PATCH] basic tests for alpine go and yarn Signed-off-by: Andrea Luzzardi --- tests/stdlib/alpine/alpine.cue | 43 +++++++++++++++++++++++++ tests/stdlib/go/go.cue | 33 +++++++++++++++++++ tests/stdlib/go/testdata/go.mod | 3 ++ tests/stdlib/go/testdata/main.go | 7 ++++ tests/stdlib/yarn/testdata/package.json | 11 +++++++ tests/stdlib/yarn/yarn.cue | 35 ++++++++++++++++++++ tests/test.sh | 14 +++++++- 7 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 tests/stdlib/alpine/alpine.cue create mode 100644 tests/stdlib/go/go.cue create mode 100644 tests/stdlib/go/testdata/go.mod create mode 100644 tests/stdlib/go/testdata/main.go create mode 100644 tests/stdlib/yarn/testdata/package.json create mode 100644 tests/stdlib/yarn/yarn.cue diff --git a/tests/stdlib/alpine/alpine.cue b/tests/stdlib/alpine/alpine.cue new file mode 100644 index 00000000..b9e7186a --- /dev/null +++ b/tests/stdlib/alpine/alpine.cue @@ -0,0 +1,43 @@ +package alpine + +import ( + "dagger.io/dagger" + "dagger.io/alpine" +) + +TestImageVersion: { + image: alpine.#Image & { + // install an old version on purpose + version: "3.10.6" + } + + test: #dagger: compute: [ + dagger.#Load & {from: image}, + dagger.#Exec & { + args: [ + "sh", + "-ec", + """ + test "$(cat /etc/alpine-release)" = 3.10.6 + """, + ] + }, + ] +} + +TestPackageInstall: { + image: alpine.#Image & { + package: jq: true + package: curl: "=~7.74.0" + } + + test: #dagger: compute: [ + dagger.#Load & {from: image}, + dagger.#Exec & { + args: ["jq", "--version"] + }, + dagger.#Exec & { + args: ["sh", "-ec", "curl --version | grep -q 7.74.0"] + }, + ] +} diff --git a/tests/stdlib/go/go.cue b/tests/stdlib/go/go.cue new file mode 100644 index 00000000..0b98f584 --- /dev/null +++ b/tests/stdlib/go/go.cue @@ -0,0 +1,33 @@ +package go + +import ( + "dagger.io/dagger" + "dagger.io/go" + "dagger.io/alpine" +) + +TestData: dagger.#Dir + +TestGoBuild: { + build: go.#Build & { + source: TestData + output: "/bin/testbin" + } + + test: #dagger: compute: [ + dagger.#Load & {from: alpine.#Image}, + dagger.#Exec & { + args: [ + "sh", + "-ec", + """ + test "$(/bin/testbin)" = "hello world" + """, + ] + mount: "/bin/testbin": { + from: build + path: "/bin/testbin" + } + }, + ] +} diff --git a/tests/stdlib/go/testdata/go.mod b/tests/stdlib/go/testdata/go.mod new file mode 100644 index 00000000..c4133132 --- /dev/null +++ b/tests/stdlib/go/testdata/go.mod @@ -0,0 +1,3 @@ +module main + +go 1.14 diff --git a/tests/stdlib/go/testdata/main.go b/tests/stdlib/go/testdata/main.go new file mode 100644 index 00000000..c0481191 --- /dev/null +++ b/tests/stdlib/go/testdata/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("hello world") +} diff --git a/tests/stdlib/yarn/testdata/package.json b/tests/stdlib/yarn/testdata/package.json new file mode 100644 index 00000000..60c2e43d --- /dev/null +++ b/tests/stdlib/yarn/testdata/package.json @@ -0,0 +1,11 @@ +{ + "name": "test", + "main": "index.js", + "license": { + "type": "Apache-2.0", + "url": "https://opensource.org/licenses/apache2.0.php" + }, + "scripts": { + "build": "mkdir -p ./build && echo output > ./build/test && touch .env && cp .env ./build/" + } +} diff --git a/tests/stdlib/yarn/yarn.cue b/tests/stdlib/yarn/yarn.cue new file mode 100644 index 00000000..a707eefa --- /dev/null +++ b/tests/stdlib/yarn/yarn.cue @@ -0,0 +1,35 @@ +package yarn + +import ( + "dagger.io/dagger" + "dagger.io/yarn" + "dagger.io/alpine" +) + +TestData: dagger.#Dir + +TestYarn: { + run: yarn.#Script & { + source: TestData + } + + test: #dagger: compute: [ + dagger.#Load & {from: alpine.#Image & { + package: bash: "=5.1.0-r0" + }}, + dagger.#Exec & { + mount: "/build": from: run + args: [ + "/bin/bash", + "--noprofile", + "--norc", + "-eo", + "pipefail", + "-c", + """ + test "$(cat /build/test)" = "output" + """, + ] + }, + ] +} diff --git a/tests/test.sh b/tests/test.sh index fb166a30..8961a16b 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -20,6 +20,17 @@ test::examples() { "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute --input-dir www.source="$d"/../examples/simple "$d"/../examples/simple } +test::stdlib() { + local dagger="$1" + + test::one "stdlib: alpine" \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/stdlib/alpine + disable test::one "stdlib: yarn (FIXME: performance)" \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/stdlib/yarn --input-dir TestData="$d"/stdlib/yarn/testdata + disable test::one "stdlib: go (FIXME: performance)" \ + "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/stdlib/go --input-dir TestData="$d"/stdlib/go/testdata +} + test::compute(){ local dagger="$1" @@ -32,7 +43,7 @@ test::compute(){ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/int test::one "Compute: invalid struct should fail" --exit=1 --stdout= \ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/struct - disable test::one "Compute: overloading #ComponentScript with new prop should fail (FIXME: unauthorized fields are not checked)" --exit=1 \ + disable test::one "Compute: overloading #ComponentScript with new prop should fail (FIXME: unauthorized fields are not checked)" --exit=1 \ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/overload/new_prop test::one "Compute: overloading #ComponentScript with new def should succeed" --exit=0 \ "$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/compute/invalid/overload/new_def @@ -251,6 +262,7 @@ test::all(){ test::subdir "$dagger" test::dockerbuild "$dagger" + test::stdlib "$dagger" test::examples "$dagger" }