|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -eu |
| 4 | + |
| 5 | +DIR=$( dirname "$0" )/../.. |
| 6 | + |
| 7 | +echo 'a1b2c3d4e5' > $TMPDIR/commit |
| 8 | +echo 'https://ci.example.com/$BUILD_ID/output-path' > $TMPDIR/target_url |
| 9 | + |
| 10 | +cat <<EOF | nc -l -s 127.0.0.1 -p 9192 > $TMPDIR/http.req-$$ & |
| 11 | +HTTP/1.0 200 OK |
| 12 | +
|
| 13 | +{ |
| 14 | + "created_at": "2012-07-20T01:19:13Z", |
| 15 | + "updated_at": "2012-07-20T02:19:13Z", |
| 16 | + "state": "success", |
| 17 | + "target_url": "https://ci.example.com/1000/output", |
| 18 | + "description": "Build has completed successfully", |
| 19 | + "id": 1, |
| 20 | + "url": "https://api.github.com/repos/octocat/Hello-World/statuses/1", |
| 21 | + "context": "continuous-integration/jenkins", |
| 22 | + "creator": { |
| 23 | + "login": "octocat", |
| 24 | + "id": 1, |
| 25 | + "avatar_url": "https://github.com/images/error/octocat_happy.gif", |
| 26 | + "gravatar_id": "", |
| 27 | + "url": "https://api.github.com/users/octocat", |
| 28 | + "html_url": "https://github.com/octocat", |
| 29 | + "followers_url": "https://api.github.com/users/octocat/followers", |
| 30 | + "following_url": "https://api.github.com/users/octocat/following{/other_user}", |
| 31 | + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", |
| 32 | + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", |
| 33 | + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", |
| 34 | + "organizations_url": "https://api.github.com/users/octocat/orgs", |
| 35 | + "repos_url": "https://api.github.com/users/octocat/repos", |
| 36 | + "events_url": "https://api.github.com/users/octocat/events{/privacy}", |
| 37 | + "received_events_url": "https://api.github.com/users/octocat/received_events", |
| 38 | + "type": "User", |
| 39 | + "site_admin": false |
| 40 | + } |
| 41 | +} |
| 42 | +EOF |
| 43 | + |
| 44 | +BUILD_ID=123 $DIR/bin/out > $TMPDIR/resource-$$ <<EOF |
| 45 | +{ |
| 46 | + "params": { |
| 47 | + "description": "test-description", |
| 48 | + "commit": "$TMPDIR/commit", |
| 49 | + "state": "success", |
| 50 | + "target_url_path": "$TMPDIR/target_url" |
| 51 | + }, |
| 52 | + "source": { |
| 53 | + "access_token": "test-token", |
| 54 | + "context": "test-context", |
| 55 | + "endpoint": "http://127.0.0.1:9192", |
| 56 | + "repository": "dpb587/test-repo" |
| 57 | + } |
| 58 | +} |
| 59 | +EOF |
| 60 | + |
| 61 | +if ! grep -q '^POST /repos/dpb587/test-repo/statuses/a1b2c3d4e5 ' $TMPDIR/http.req-$$ ; then |
| 62 | + echo "FAILURE: Invalid HTTP method or URI" |
| 63 | + cat $TMPDIR/http.req-$$ |
| 64 | + exit 1 |
| 65 | +fi |
| 66 | + |
| 67 | +if ! grep -q '^{"context":"test-context","description":"test-description","state":"success","target_url":"https://ci.example.com/123/output-path"}$' $TMPDIR/http.req-$$ ; then |
| 68 | + echo "FAILURE: Unexpected request body" |
| 69 | + cat $TMPDIR/http.req-$$ |
| 70 | + exit 1 |
| 71 | +fi |
| 72 | + |
| 73 | +if ! grep -q '"version":{"commit":"a1b2c3d4e5","status":"1"}' $TMPDIR/resource-$$ ; then |
| 74 | + echo "FAILURE: Unexpected version output" |
| 75 | + cat $TMPDIR/resource-$$ |
| 76 | + exit 1 |
| 77 | +fi |
| 78 | + |
| 79 | +if ! grep -q '{"name":"created_at","value":"2012-07-20T01:19:13Z"}' $TMPDIR/resource-$$ ; then |
| 80 | + echo "FAILURE: Unexpected created_at output" |
| 81 | + cat $TMPDIR/resource-$$ |
| 82 | + exit 1 |
| 83 | +fi |
| 84 | + |
| 85 | +if ! grep -q '{"name":"created_by","value":"octocat"}' $TMPDIR/resource-$$ ; then |
| 86 | + echo "FAILURE: Unexpected creator output" |
| 87 | + cat $TMPDIR/resource-$$ |
| 88 | + exit 1 |
| 89 | +fi |
0 commit comments