Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 087c11e

Browse files
committed
Add validation for state value
Fixes #9
1 parent e70eed3 commit 087c11e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

bin/out

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ eval $( jq -r '{
1414
} | to_entries[] | .key + "=" + @sh "\(.value)"' < /tmp/stdin )
1515

1616

17+
#
18+
# validate
19+
#
20+
21+
case "$params_state" in
22+
error) true ;;
23+
failure) true ;;
24+
pending) true ;;
25+
success) true ;;
26+
*) fatal "Invalid parameter: state: $params_state"
27+
esac
28+
29+
1730
#
1831
# commit
1932
#

test/out/validate-state.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
DIR=$( dirname "$0" )/../..
6+
7+
set +e # error expected
8+
9+
BUILD_ID=123 $DIR/bin/out > $TMPDIR/resource-$$ 2> $TMPDIR/resource-$$.out <<EOF
10+
{
11+
"params": {
12+
"description": "test-description",
13+
"commit": "$TMPDIR/commit",
14+
"state": "failed",
15+
"target_url": "https://ci.example.com/\$BUILD_ID/output"
16+
},
17+
"source": {
18+
"access_token": "test-token",
19+
"context": "test-context",
20+
"endpoint": "http://127.0.0.1:9192",
21+
"repository": "dpb587/test-repo"
22+
}
23+
}
24+
EOF
25+
26+
set -e
27+
28+
if ! grep -q '^FATAL: Invalid parameter: state: failed' $TMPDIR/resource-$$.out ; then
29+
echo "FAILURE: Missing error for state validation"
30+
cat $TMPDIR/resource-$$.out
31+
exit 1
32+
fi

0 commit comments

Comments
 (0)