diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 58dba43..f8f34fc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,10 +13,5 @@ jobs: with: args: Dockerfile - - name: Bats - uses: koenrh/actions/bats@master - with: - args: test/*.bats - - name: ShellCheck run: shellcheck entrypoint.sh diff --git a/test/bin/dnscontrol b/test/bin/dnscontrol deleted file mode 100644 index e65e27d..0000000 --- a/test/bin/dnscontrol +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -echo "foo" diff --git a/test/bootstrap.bash b/test/bootstrap.bash deleted file mode 100644 index 9e461aa..0000000 --- a/test/bootstrap.bash +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -set -e - -apt update && apt install --no-install-recommends -y jq >&2 diff --git a/test/entrypoint.bats b/test/entrypoint.bats deleted file mode 100644 index c3368ec..0000000 --- a/test/entrypoint.bats +++ /dev/null @@ -1,115 +0,0 @@ -#!/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 - - unset "${!CLOUDFLARE@}" - unset "${!AWS@}" - unset "${!DIGITALOCEAN@}" -} - -function assert_key_equals { - key="$1" - got=$(jq -r "$key" < creds.json) - expected=$2 - - if [[ "$got" != "$expected" ]] - then - echo "Expected \"$got\" to equal \"$expected\"" - return 1 - fi -} - -function assert_key_not_exists { - key="$1" - path=${key%.*} - last=${key##*.} - got=$(jq "$path | has(\"$last\")" < creds.json) - - if [[ "$got" == "true" ]] - then - echo "Expected key \"$key\" to not exist." - return 1 - fi -} - -# Cloudflare -@test "Cloudflare API token is set in credentials file" { - export CLOUDFLARE_API_TOKEN="foo-bar-baz" - - run "$WORKSPACE/entrypoint.sh" - - assert_key_equals ".cloudflare.apitoken" "\$CLOUDFLARE_API_TOKEN" - - assert_key_not_exists ".cloudflare.accountid" - assert_key_not_exists ".cloudflare.accountname" -} - -@test "Cloudflare API user and key are set in credentials file" { - export CLOUDFLARE_API_USER="info@example.com" - export CLOUDFLARE_API_KEY="foo" - - run "$WORKSPACE/entrypoint.sh" - - assert_key_equals ".cloudflare.apiuser" "\$CLOUDFLARE_API_USER" - assert_key_equals ".cloudflare.apikey" "\$CLOUDFLARE_API_KEY" - - assert_key_not_exists ".cloudflare.accountid" - assert_key_not_exists ".cloudflare.accountname" -} - -@test "Cloudflare API user and key, and optional account ID and name are set" { - 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_key_equals ".cloudflare.apiuser" "\$CLOUDFLARE_API_USER" - assert_key_equals ".cloudflare.apikey" "\$CLOUDFLARE_API_KEY" - assert_key_equals ".cloudflare.accountid" "\$CLOUDFLARE_ACCOUNT_ID" - assert_key_equals ".cloudflare.accountname" "\$CLOUDFLARE_ACCOUNT_NAME" -} - -# DigitalOcean -@test "DigitalOcean token is set in credentials file" { - export DIGITALOCEAN_OAUTH_TOKEN="secret" - - run "$WORKSPACE/entrypoint.sh" - - assert_key_equals ".digitalocean.token" "\$DIGITALOCEAN_OAUTH_TOKEN" -} - -# Route 53 -@test "AWS access key ID and secret access key are set in credentials file" { - export AWS_ACCESS_KEY_ID="access_key_foo" - export AWS_SECRET_ACCESS_KEY="very_secret" - - run "$WORKSPACE/entrypoint.sh" - - assert_key_equals ".r53.KeyId" "\$AWS_ACCESS_KEY_ID" - assert_key_equals ".r53.SecretKey" "\$AWS_SECRET_ACCESS_KEY" - - assert_key_not_exists ".r53.Token" -} - -@test "AWS access keys, and optional session token are set in credentials file" { - export AWS_ACCESS_KEY_ID="access_key_foo" - export AWS_SECRET_ACCESS_KEY="very_secret" - export AWS_SESSION_TOKEN="session_token" - - run "$WORKSPACE/entrypoint.sh" - - assert_key_equals ".r53.KeyId" "\$AWS_ACCESS_KEY_ID" - assert_key_equals ".r53.SecretKey" "\$AWS_SECRET_ACCESS_KEY" - assert_key_equals ".r53.Token" "\$AWS_SESSION_TOKEN" -}