Skip to content

Commit

Permalink
build: run integration tests and dry-run build
Browse files Browse the repository at this point in the history
  • Loading branch information
ericnorris committed Aug 31, 2021
1 parent 77ca7f7 commit fb9e488
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on: [push, pull_request]

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15

- name: Test
run: |
./test.sh
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
args: build --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# ignore built binaries
/terraform-demux

# ignore test output
test-log
69 changes: 69 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

set -e

GIT_ROOT="$(git rev-parse --show-toplevel)"
TMP_DIR="$(mktemp -d)"

if ! [[ $TMP_DIR ]]; then
panic "could not create temporary directory"
else
# shellcheck disable=SC2064
trap "rm -r $TMP_DIR" EXIT

export XDG_CACHE_HOME="$TMP_DIR"
fi

function terraform_demux_version() {
go run "$GIT_ROOT/cmd/..." -- -version >test-log 2>&1
}

function expect_log() {
(grep -q "$1" test-log && pass "Found '$1' in test-log") || fail "Expected to find '$1' in test-log"
}

function pass() {
echo "PASS:" "$@" >&2
}

function fail() {
echo "FAIL:" "$@" >&2
exit 1
}

function panic() {
echo "PANIC:" "$@" >&2
exit 1
}

function terraform_demux_version_test() {
local dir="$1"
local expected_version="$2"

pushd "$dir" >/dev/null

terraform_demux_version

(grep -q "$expected_version" test-log && pass "Found '$expected_version' in $dir/test-log") \
|| fail "Expected to find '$expected_version' in $dir/test-log"

popd >/dev/null
}

function test_pre_0.12_exact() {
terraform_demux_version_test "testdata/terraform-pre-0.12-exact" "Terraform v0.11.15"
}

function test_post_0.12_exact() {
terraform_demux_version_test "testdata/terraform-post-0.12-exact" "Terraform v1.0.3"
}

function test_pessimistic_constraint() {
terraform_demux_version_test "testdata/terraform-pessimistic" "Terraform v0.14."
}

test_pre_0.12_exact

test_post_0.12_exact

test_pessimistic_constraint
3 changes: 3 additions & 0 deletions testdata/terraform-pessimistic/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = "~> 0.14.0"
}
3 changes: 3 additions & 0 deletions testdata/terraform-post-0.12-exact/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = "1.0.3"
}
3 changes: 3 additions & 0 deletions testdata/terraform-pre-0.12-exact/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = "0.11.15"
}

0 comments on commit fb9e488

Please sign in to comment.