wip: automated integration tests
continuous-integration/drone/push Build was killed Details
continuous-integration/drone/pr Build was killed Details

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

View File

@ -2,68 +2,79 @@
kind: pipeline
name: coopcloud.tech/abra
steps:
- name: make check
image: golang:1.20
# - name: run gofmt
# image: golang:1.20
# commands:
# - make check
# - name: build binaries
# image: golang:1.20
# commands:
# - make check
# depends_on:
# - run gofmt
# - name: run unit tests
# image: golang:1.20
# commands:
# - make test
# depends_on:
# - run gofmt
- name: run integration tests
image: debian:12-slim
commands:
- make check
- 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: make build
image: golang:1.20
commands:
- make build
depends_on:
- make check
# - name: fetch all tags
# image: docker:git
# commands:
# - git fetch --tags
# depends_on:
# - run gofmt
# - build binaries
# - run unit tests
# - run integration tests
# when:
# event: tag
- name: make test
image: golang:1.20
commands:
- make test
depends_on:
- make check
# - name: publish release
# image: goreleaser/goreleaser:v1.18.2
# environment:
# GITEA_TOKEN:
# from_secret: goreleaser_gitea_token
# volumes:
# - name: deps
# path: /go
# commands:
# - goreleaser release
# depends_on:
# - fetch all tags
# when:
# event: tag
- name: fetch
image: docker:git
commands:
- git fetch --tags
depends_on:
- make check
- make build
- make test
when:
event: tag
# - name: publish image
# image: plugins/docker
# settings:
# auto_tag: true
# username: 3wordchant
# password:
# from_secret: git_coopcloud_tech_token_3wc
# repo: git.coopcloud.tech/coop-cloud/abra
# tags: dev
# registry: git.coopcloud.tech
# when:
# event:
# exclude:
# - pull_request
# depends_on:
# - run gofmt
# - build binaries
- name: release
image: goreleaser/goreleaser:v1.18.2
environment:
GITEA_TOKEN:
from_secret: goreleaser_gitea_token
volumes:
- name: deps
path: /go
commands:
- goreleaser release
depends_on:
- fetch
when:
event: tag
- name: publish image
image: plugins/docker
settings:
auto_tag: true
username: 3wordchant
password:
from_secret: git_coopcloud_tech_token_3wc
repo: git.coopcloud.tech/coop-cloud/abra
tags: dev
registry: git.coopcloud.tech
when:
event:
exclude:
- pull_request
depends_on:
- make check
volumes:
- name: deps
temp: {}
# volumes:
# - name: deps
# temp: {}

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
}