wip: automated integration tests

This commit is contained in:
decentral1se 2023-08-02 10:47:44 +02:00
parent 5ae73f700e
commit 77400927a8
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
4 changed files with 98 additions and 18 deletions

View File

@ -2,37 +2,47 @@
kind: pipeline
name: coopcloud.tech/abra
steps:
- name: make check
- name: run gofmt
image: golang:1.20
commands:
- make check
- name: make build
- name: build binaries
image: golang:1.20
commands:
- make build
- make check
depends_on:
- make check
- run gofmt
- name: make test
- name: run unit tests
image: golang:1.20
commands:
- make test
depends_on:
- make check
- run gofmt
- name: fetch
- name: run integration tests
image: 12-slim
commands:
- apt update && apt install -y bats bats-assert bats-support expect git golang make
- curl -fsSL https://get.docker.com | sh
- bats tests/integration/integration.bats
depends_on:
- run gofmt
- name: fetch all tags
image: docker:git
commands:
- git fetch --tags
depends_on:
- make check
- make build
- make test
- run gofmt
- build binaries
- run unit tests
- run integration tests
when:
event: tag
- name: release
- name: publish release
image: goreleaser/goreleaser:v1.18.2
environment:
GITEA_TOKEN:
@ -43,7 +53,7 @@ steps:
commands:
- goreleaser release
depends_on:
- fetch
- fetch all tags
when:
event: tag
@ -62,7 +72,8 @@ steps:
exclude:
- pull_request
depends_on:
- make check
- run gofmt
- build binaries
volumes:
- name: deps

View File

@ -93,14 +93,14 @@ var appNewCommand = cli.Command{
logrus.Fatal(err)
}
cl, err := client.New(internal.NewAppServer)
if err != nil {
logrus.Fatal(err)
}
var secrets AppSecrets
var secretTable *jsontable.JSONTable
if internal.Secrets {
cl, err := client.New(internal.NewAppServer)
if err != nil {
logrus.Fatal(err)
}
secrets, err := createSecrets(cl, sanitisedAppName)
if err != nil {
logrus.Fatal(err)

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
_build_abra() {
if [[ ! -e "$PROJECT_ROOT/abra" ]]; then
cd "$PROJECT_ROOT" && make build-dev
return 0
fi
return 0
}

View File

@ -0,0 +1,60 @@
setup() {
load '/usr/lib/bats/bats-support/load'
load '/usr/lib/bats/bats-assert/load'
# get test binaries on $PATH for testing
TEST_ROOT="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
PROJECT_ROOT="$TEST_ROOT/../.."
PATH="$PROJECT_ROOT/../..:$PATH"
source "$TEST_ROOT/helpers.sh"
_build_abra
}
@test "build test abra" {
run abra -h
assert_output --partial 'The Co-op Cloud command-line utility belt'
}
@test "create new recipe" {
run abra recipe new foobar
assert_output --partial 'Your new foobar recipe has been created'
mkdir -p "$HOME/.abra/servers/example.com"
if ! grep -R -q "example.com" "$HOME/.docker"; then
docker context create --docker host=ssh://foo@example.com:222 example.com
fi
run abra app new foobar \
--no-input \
--server example.com \
--domain foobar.example.com
assert_output --partial 'A new foobar app has been created!'
# TODO: abra app deploy foobar.example.com
# we need an actual server for this to ensure things work maybe we can get
# a donated server from the comrades for this?
rm -r "$HOME/.abra/recipes/foobar"
rm -r "$HOME/.abra/servers/example.com"
}
@test "upgrade and sync a recipe" {
run abra recipe fetch gitea
cd "$HOME/.abra/recipes/gitea" && git checkout "2.3.1+1.20.1-rootless"
run abra recipe upgrade gitea --offline --machine
assert_output --partial '1.20.2-rootless'
# TODO: when passing --patch, there is no output so we can't test against
# anything... we should add info logging when automation flags are passed
# so we can assert
run abra recipe upgrade gitea --offline --patch
run abra recipe sync gitea --offline --patch
assert_output --partial \
'synced label coop-cloud.${STACK_NAME}.version=2.3.2+1.20.2-rootless to service app'
# TODO: assert git output
}