tests: Basic test infrastructure for Europa Universe

- Each package can include its own bats file (e.g. `universe.dagger.io/yarn/test/yarn.bats`)
- universe.dagger.io includes a common bash helper file
- bats is installed/launched through yarn with minimal setup
- shellcheck is done across the entire repo
- Integrated into our CI

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2022-01-18 19:13:07 -08:00
parent 44335b5818
commit 568cd194a4
12 changed files with 96 additions and 44 deletions

View File

@ -168,6 +168,29 @@ jobs:
run: | run: |
make universe-test make universe-test
europa:
name: Universe (Europa)
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Check out
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.16
- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v1
- name: Universe Test
env:
DAGGER_CACHE_TO: "type=gha,mode=max,scope=test-universe"
DAGGER_CACHE_FROM: "type=gha,mode=max,scope=test-universe"
run: |
make europa-universe-test
doc: doc:
name: Documentation name: Documentation
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -24,7 +24,7 @@ golint:
.PHONY: cuefmt .PHONY: cuefmt
cuefmt: cuefmt:
@(find . -name '*.cue' -exec cue fmt -s {} \;) find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -n 1 -P 8 cue fmt -s
.PHONY: cuelint .PHONY: cuelint
cuelint: cuefmt cuelint: cuefmt
@ -32,8 +32,7 @@ cuelint: cuefmt
.PHONY: shellcheck .PHONY: shellcheck
shellcheck: shellcheck:
shellcheck ./tests/*.bats ./tests/*.bash shellcheck $$(find . -type f \( -iname \*.bats -o -iname \*.bash -o -iname \*.sh \) -not -path "*/node_modules/*" -not -path "*/bats-*/*")
shellcheck ./universe/*.bats ./universe/*.bash
.PHONY: lint .PHONY: lint
lint: shellcheck cuelint golint docslint lint: shellcheck cuelint golint docslint
@ -51,6 +50,11 @@ universe-test: dagger-debug
yarn --cwd "./universe" install yarn --cwd "./universe" install
DAGGER_BINARY="$(shell pwd)/cmd/dagger/dagger-debug" yarn --cwd "./universe" test DAGGER_BINARY="$(shell pwd)/cmd/dagger/dagger-debug" yarn --cwd "./universe" test
.PHONY: europa-universe-test
europa-universe-test: dagger-debug
yarn --cwd "./pkg/universe.dagger.io" install
DAGGER_BINARY="$(shell pwd)/cmd/dagger/dagger-debug" yarn --cwd "./pkg/universe.dagger.io" test
.PHONY: doc-test .PHONY: doc-test
doc-test: dagger-debug doc-test: dagger-debug
yarn --cwd "./docs/learn/tests" install yarn --cwd "./docs/learn/tests" install

2
pkg/universe.dagger.io/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
report.xml

View File

@ -0,0 +1,25 @@
common_setup() {
load "$(dirname "${BASH_SOURCE[0]}")/node_modules/bats-support/load.bash"
load "$(dirname "${BASH_SOURCE[0]}")/node_modules/bats-assert/load.bash"
# Dagger Binary
# FIXME: `command -v` must be wrapped in a sub-bash,
# otherwise infinite recursion when DAGGER_BINARY is not set.
export DAGGER="${DAGGER_BINARY:-$(bash -c 'command -v dagger')}"
# Force Europa mode
DAGGER_EUROPA="1"
export DAGGER_EUROPA
# Force plain printing for error reporting
DAGGER_LOG_FORMAT="plain"
export DAGGER_LOG_FORMAT
# cd into the directory containing the bats file
cd "$BATS_TEST_DIRNAME" || exit 1
}
# dagger helper to execute the right binary
dagger() {
"${DAGGER}" "$@"
}

View File

@ -1 +0,0 @@
../../../dagger.io

View File

@ -1,3 +0,0 @@
#!/bin/bash
find . -name '*.cue' -exec cue fmt -s {} \;

View File

@ -0,0 +1,11 @@
{
"license": "Apache-2.0",
"scripts": {
"test": "bats --report-formatter junit --jobs 4 $(find . -type f -name '*.bats' -not -path '*/node_modules/*')"
},
"devDependencies": {
"bats": "^1.5.0",
"bats-assert": "^2.0.0",
"bats-support": "^0.3.0"
}
}

View File

@ -1,3 +0,0 @@
#!/bin/bash
find . -name '*.cue' -exec grep -H "$1" {} \;

View File

@ -1,33 +0,0 @@
#!/bin/bash
set -e
targets=(
dagger.io/dagger
dagger.io/dagger/engine
./docker
./docker/test/build
./alpine
./alpine/tests/simple
./yarn
./yarn/tests/simple
./bash
./python
./git
./nginx
./netlify
./netlify/test/simple
./examples/todoapp
./examples/todoapp/dev
./examples/todoapp/staging
)
for t in "${targets[@]}"; do
echo "-- $t"
cue eval "$t" >/dev/null
done

View File

@ -0,0 +1,18 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
bats-assert@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/bats-assert/-/bats-assert-2.0.0.tgz#ba1b4eeee2c7848f1a25948b623790dd41a2b94b"
integrity sha512-qO3kNilWxW8iCONu9NDUfvsCiC6JzL6DPOc/DGq9z3bZ9/A7wURJ+FnFMxGbofOmWbCoy7pVhofn0o47A95qkQ==
bats-support@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/bats-support/-/bats-support-0.3.0.tgz#a1f6b8878d2a51837911fdffa0750036f60701ef"
integrity sha512-z+2WzXbI4OZgLnynydqH8GpI3+DcOtepO66PlK47SfEzTkiuV9hxn9eIQX+uLVFbt2Oqoc7Ky3TJ/N83lqD+cg==
bats@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/bats/-/bats-1.5.0.tgz#683f522e89df7d8fc99bf3631d35501f35445166"
integrity sha512-83YgQw24Yi2c1ctB0Vd7WCsACUMSWuEtOboxQZyFQYfiv9hDMW7nk7bdloqGLg3vK5pOODCBGBQjhvRmHKsJuA==

View File

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

View File

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
echo -n hello world > /test.txt printf "hello world" > /test.txt