Merge pull request #7 from koenrh/koenrh/add-tests

Add first test
This commit is contained in:
Koen Rouwhorst 2019-01-06 12:09:45 +01:00 committed by GitHub
commit 4dd97cb875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 0 deletions

19
.github/main.workflow vendored Normal file
View file

@ -0,0 +1,19 @@
workflow "Run tests" {
on = "push"
resolves = ["Shellcheck", "Bats", "Dockerfilelint"]
}
action "Shellcheck" {
uses = "actions/bin/shellcheck@master"
args = "entrypoint.sh"
}
action "Bats" {
uses = "actions/bin/bats@master"
args = "test/*.bats"
}
action "Dockerfilelint" {
uses = "docker://replicated/dockerfilelint"
args = ["Dockerfile"]
}

3
test/bin/dnscontrol Normal file
View file

@ -0,0 +1,3 @@
#!/bin/sh
echo "foo"

5
test/bootstrap.bash Normal file
View file

@ -0,0 +1,5 @@
#!/bin/sh
set -e
apt update && apt install --no-install-recommends -y jq >&2

48
test/entrypoint.bats Normal file
View file

@ -0,0 +1,48 @@
#!/usr/bin/env bats
load bootstrap
PATH="$PATH:$BATS_TEST_DIRNAME/bin"
function setup() {
export WORKSPACE="${WORKSPACE-"${BATS_TEST_DIRNAME}/.."}"
}
function teardown() {
rm creds.json
}
function assert_jq_eq {
MATCH=$2
RESULT=$(jq -r "$1" < creds.json)
if [[ "$RESULT" != "$MATCH" ]]
then
echo "Expected match "'"'"$MATCH"'"'" was not found in "'"'"$RES"'"'
return 1
fi
}
@test "cloudflare default" {
export CLOUDFLARE_API_USER="info@example.com"
export CLOUDFLARE_API_KEY="foo"
run $WORKSPACE/entrypoint.sh
assert_jq_eq ".cloudflare.apiuser" "\$CLOUDFLARE_API_USER"
assert_jq_eq ".cloudflare.apikey" "\$CLOUDFLARE_API_KEY"
}
@test "Cloudflare account ID and name only set when both are specified" {
export CLOUDFLARE_API_USER="info@example.com"
export CLOUDFLARE_API_KEY="foo"
export CLOUDFLARE_ACCOUNT_ID="1"
export CLOUDFLARE_ACCOUNT_NAME="Contoso"
run $WORKSPACE/entrypoint.sh
assert_jq_eq ".cloudflare.apiuser" "\$CLOUDFLARE_API_USER"
assert_jq_eq ".cloudflare.apikey" "\$CLOUDFLARE_API_KEY"
assert_jq_eq ".cloudflare.accountid" "\$CLOUDFLARE_ACCOUNT_ID"
assert_jq_eq ".cloudflare.accountname" "\$CLOUDFLARE_ACCOUNT_NAME"
}