-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.sh
executable file
·69 lines (49 loc) · 1.44 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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