mirror of
https://github.com/koenrh/dnscontrol-action.git
synced 2025-02-23 14:34:19 +08:00
Added entrypoint test.
This commit is contained in:
parent
6e93a1ca95
commit
3e410f3f26
4 changed files with 75 additions and 0 deletions
19
.github/main.workflow
vendored
Normal file
19
.github/main.workflow
vendored
Normal 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
3
test/bin/dnscontrol
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "foo"
|
5
test/bootstrap.bash
Normal file
5
test/bootstrap.bash
Normal 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
48
test/entrypoint.bats
Normal 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"
|
||||||
|
}
|
Loading…
Reference in a new issue