-
Notifications
You must be signed in to change notification settings - Fork 12
/
check-muse-api.sh
executable file
·92 lines (85 loc) · 2.83 KB
/
check-muse-api.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
function checkVersion() {
local result
result=$($script "$test_repo" "$test_commit" version | jq .)
if [[ "$result" = "1" ]] ; then
echo "$script version GOOD"
else
echo "$script version BAD (returned $result)"
echo " should emit '1' to indicate API version 1."
fi
}
function checkApplicable() {
local aresult
aresult=$($script "$test_repo" "$test_commit" applicable | jq .)
if [[ ( "$aresult" = "true" ) || ( "$aresult" = "false" ) ]] ; then
echo "$script applicable GOOD"
else
echo "$script applicable BAD (returned '$aresult')"
echo " should emit a boolean (true or false)"
fi
}
function checkRun() {
if [[ -d "$test_repo" ]] ; then
local result
result=$($script "$test_repo" "$test_commit" run)
toptype=$(echo "$result" | jq 'type')
if [[ ! ( "$toptype" = '"array"' ) ]] ; then
echo "$script run BAD - results should be an array"
exit 1
fi
correctLength=$(echo "$result" | jq 'length')
withFile=$(echo "$result" | jq 'map(.file) | map(strings) | length')
withType=$(echo "$result" | jq 'map(.type) | map(strings) | length')
withMessage=$(echo "$result" | jq 'map(.message) | map(strings) | length')
withLine=$(echo "$result" | jq 'map(.line) | map(numbers) | length')
if [[ ! ( "$correctLength" = "$withFile" ) ]] ; then
echo "$script run BAD - bad or missing 'file' field(s)."
exit 1
fi
if [[ ! ( "$correctLength" = "$withType" ) ]] ; then
echo "$script run BAD - bad or missing 'type' field(s)."
exit 1
fi
if [[ ! ( "$correctLength" = "$withMessage" ) ]] ; then
echo "$script run BAD- bad or missing 'message' field(s)."
exit 1
fi
if [[ ! ( "$correctLength" = "$withLine" ) ]] ; then
echo "$script run BAD - bad or missing 'line' field(s)."
exit 1
fi
echo "$script run GOOD"
else
echo "No repository specified on the command line."
echo "Not checking the 'run' functionallity due to missing test repository."
fi
}
function checkDeps() {
if [[ ! ( -f "$(command -v jq)" ) ]] ; then
echo "Missing jq"
exit 1
fi
if [[ ! ( -f "$(command -v git)" ) ]] ; then
echo "Missing git"
exit 1
fi
}
function main() {
checkDeps
script="$(pwd)/$1"
test_repo=$2
test_commit=""
echo "Checking script '$script'"
if [[ ! ( -z "$test_repo" ) ]] ; then
pushd "$test_repo" || exit 1
test_commit=$(git rev-parse HEAD 2>/dev/null)
else
test_repo="some_repo_directory"
test_commit="some_commit"
fi
checkVersion
checkApplicable
checkRun
}
main "$@"