forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinary-smoke-test.sh
executable file
·72 lines (63 loc) · 2.64 KB
/
binary-smoke-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
70
71
72
#!/usr/bin/env bash
set -eo pipefail
OPA_EXEC="$1"
TARGET="$2"
PATH_SEPARATOR="/"
BASE_PATH=$(pwd)
TEST_PATH="${BASE_PATH}/test/cli/smoke/namespace/data.json"
if [[ $OPA_EXEC == *".exe" ]]; then
PATH_SEPARATOR="\\"
BASE_PATH=$(pwd -W)
TEST_PATH="$(echo ${BASE_PATH}/test/cli/smoke/namespace/data.json | sed 's/^\///' | sed 's/\//\\\\/g')"
BASE_PATH=$(echo ${BASE_PATH} | sed 's/^\///' | sed 's/\//\\/g')
fi
github_actions_group() {
local args="$*"
echo "::group::$args"
$args
echo "::endgroup::"
}
opa() {
local args="$*"
github_actions_group $OPA_EXEC $args
}
# assert_contains checks if the actual string contains the expected string.
assert_contains() {
local expected="$1"
local actual="$2"
if [[ "$actual" != *"$expected"* ]]; then
echo "Expected '$expected' but got '$actual'"
exit 1
fi
}
# assert_not_contains checks if the actual string does not contain the expected string.
assert_not_contains() {
local expected="$1"
local actual="$2"
if [[ "$actual" == *"$expected"* ]]; then
echo "Didn't expect '$expected' in '$actual'"
exit 0
fi
}
opa version
opa eval -t $TARGET 'time.now_ns()'
opa eval --format pretty --bundle test/cli/smoke/golden-bundle.tar.gz --input test/cli/smoke/input.json data.test.result --fail
opa exec --bundle test/cli/smoke/golden-bundle.tar.gz --decision test/result test/cli/smoke/input.json
opa build --output o0.tar.gz test/cli/smoke/data.yaml test/cli/smoke/test.rego
echo '{"yay": "bar"}' | opa eval --format pretty --bundle o0.tar.gz -I data.test.result --fail
opa build --optimize 1 --output o1.tar.gz test/cli/smoke/data.yaml test/cli/smoke/test.rego
echo '{"yay": "bar"}' | opa eval --format pretty --bundle o1.tar.gz -I data.test.result --fail
opa build --optimize 2 --output o2.tar.gz test/cli/smoke/data.yaml test/cli/smoke/test.rego
echo '{"yay": "bar"}' | opa eval --format pretty --bundle o2.tar.gz -I data.test.result --fail
# Tar paths
opa build --output o3.tar.gz test/cli/smoke
github_actions_group assert_contains '/test/cli/smoke/test.rego' "$(tar -tf o3.tar.gz /test/cli/smoke/test.rego)"
# Data files - correct namespaces
echo "::group:: Data files - correct namespaces"
assert_contains "data.namespace | test${PATH_SEPARATOR}cli${PATH_SEPARATOR}smoke${PATH_SEPARATOR}namespace${PATH_SEPARATOR}data.json" "$(opa inspect test/cli/smoke)"
echo "::endgroup::"
# Data files - correct root path
echo "::group:: Data files - correct root path"
assert_contains "${TEST_PATH}" "$(opa inspect ${BASE_PATH}/test/cli/smoke -f json)"
assert_not_contains "\\\\${TEST_PATH}" "$(opa inspect ${BASE_PATH}/test/cli/smoke -f json)"
echo "::endgroup::"