Skip to content

Commit 6d0eb69

Browse files
committed
test: GitHubPing
1 parent 36b32ae commit 6d0eb69

File tree

2 files changed

+177
-3
lines changed

2 files changed

+177
-3
lines changed

src/app/app_github_test.go

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
package app
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
6+
"bytes"
7+
"encoding/json"
8+
"net/http"
9+
"net/http/httptest"
10+
"testing"
11+
)
12+
13+
func TestGitHubPing(t *testing.T) {
14+
15+
server := httptest.NewServer(CreateApp())
16+
17+
req, _ := http.NewRequest("POST", server.URL+"/webhooks/github/", bytes.NewReader([]byte(PingJson)))
18+
req.Header.Set("X-GitHub-Event", "ping")
19+
req.Header.Set("Content-Type", "application/json")
20+
req.Header.Set("X-Hub-Signature", PingSha)
21+
22+
if response, err := (&http.Client{}).Do(req); assert.NoError(t, err) {
23+
24+
if assert.Equal(t, http.StatusOK, response.StatusCode) {
25+
26+
var resp string
27+
28+
if err := json.NewDecoder(response.Body).Decode(&resp); assert.NoError(t, err) {
29+
30+
assert.Equal(t, "pong", resp)
31+
}
32+
}
33+
}
34+
}
35+
36+
const (
37+
PingSha = "27577ef3f3d983a7c34c4863cd3a36ad8a3ee128"
38+
PingJson = `
39+
{
40+
"zen": "Non-blocking is better than blocking.",
41+
"hook_id": 8566024,
42+
"hook": {
43+
"type": "Repository",
44+
"id": 8566024,
45+
"name": "web",
46+
"active": true,
47+
"events": [
48+
"push"
49+
],
50+
"config": {
51+
"content_type": "json",
52+
"insecure_ssl": "0",
53+
"secret": "********",
54+
"url": "http://185.143.172.56/webhooks/github/"
55+
},
56+
"updated_at": "2016-05-30T06:52:10Z",
57+
"created_at": "2016-05-30T06:52:10Z",
58+
"url": "https://api.github.com/repos/postgres-ci/http200ok/hooks/8566024",
59+
"test_url": "https://api.github.com/repos/postgres-ci/http200ok/hooks/8566024/test",
60+
"ping_url": "https://api.github.com/repos/postgres-ci/http200ok/hooks/8566024/pings",
61+
"last_response": {
62+
"code": null,
63+
"status": "unused",
64+
"message": null
65+
}
66+
},
67+
"repository": {
68+
"id": 56714132,
69+
"name": "http200ok",
70+
"full_name": "postgres-ci/http200ok",
71+
"owner": {
72+
"login": "postgres-ci",
73+
"id": 16963162,
74+
"avatar_url": "https://avatars.githubusercontent.com/u/16963162?v=3",
75+
"gravatar_id": "",
76+
"url": "https://api.github.com/users/postgres-ci",
77+
"html_url": "https://github.com/postgres-ci",
78+
"followers_url": "https://api.github.com/users/postgres-ci/followers",
79+
"following_url": "https://api.github.com/users/postgres-ci/following{/other_user}",
80+
"gists_url": "https://api.github.com/users/postgres-ci/gists{/gist_id}",
81+
"starred_url": "https://api.github.com/users/postgres-ci/starred{/owner}{/repo}",
82+
"subscriptions_url": "https://api.github.com/users/postgres-ci/subscriptions",
83+
"organizations_url": "https://api.github.com/users/postgres-ci/orgs",
84+
"repos_url": "https://api.github.com/users/postgres-ci/repos",
85+
"events_url": "https://api.github.com/users/postgres-ci/events{/privacy}",
86+
"received_events_url": "https://api.github.com/users/postgres-ci/received_events",
87+
"type": "Organization",
88+
"site_admin": false
89+
},
90+
"private": false,
91+
"html_url": "https://github.com/postgres-ci/http200ok",
92+
"description": "",
93+
"fork": false,
94+
"url": "https://api.github.com/repos/postgres-ci/http200ok",
95+
"forks_url": "https://api.github.com/repos/postgres-ci/http200ok/forks",
96+
"keys_url": "https://api.github.com/repos/postgres-ci/http200ok/keys{/key_id}",
97+
"collaborators_url": "https://api.github.com/repos/postgres-ci/http200ok/collaborators{/collaborator}",
98+
"teams_url": "https://api.github.com/repos/postgres-ci/http200ok/teams",
99+
"hooks_url": "https://api.github.com/repos/postgres-ci/http200ok/hooks",
100+
"issue_events_url": "https://api.github.com/repos/postgres-ci/http200ok/issues/events{/number}",
101+
"events_url": "https://api.github.com/repos/postgres-ci/http200ok/events",
102+
"assignees_url": "https://api.github.com/repos/postgres-ci/http200ok/assignees{/user}",
103+
"branches_url": "https://api.github.com/repos/postgres-ci/http200ok/branches{/branch}",
104+
"tags_url": "https://api.github.com/repos/postgres-ci/http200ok/tags",
105+
"blobs_url": "https://api.github.com/repos/postgres-ci/http200ok/git/blobs{/sha}",
106+
"git_tags_url": "https://api.github.com/repos/postgres-ci/http200ok/git/tags{/sha}",
107+
"git_refs_url": "https://api.github.com/repos/postgres-ci/http200ok/git/refs{/sha}",
108+
"trees_url": "https://api.github.com/repos/postgres-ci/http200ok/git/trees{/sha}",
109+
"statuses_url": "https://api.github.com/repos/postgres-ci/http200ok/statuses/{sha}",
110+
"languages_url": "https://api.github.com/repos/postgres-ci/http200ok/languages",
111+
"stargazers_url": "https://api.github.com/repos/postgres-ci/http200ok/stargazers",
112+
"contributors_url": "https://api.github.com/repos/postgres-ci/http200ok/contributors",
113+
"subscribers_url": "https://api.github.com/repos/postgres-ci/http200ok/subscribers",
114+
"subscription_url": "https://api.github.com/repos/postgres-ci/http200ok/subscription",
115+
"commits_url": "https://api.github.com/repos/postgres-ci/http200ok/commits{/sha}",
116+
"git_commits_url": "https://api.github.com/repos/postgres-ci/http200ok/git/commits{/sha}",
117+
"comments_url": "https://api.github.com/repos/postgres-ci/http200ok/comments{/number}",
118+
"issue_comment_url": "https://api.github.com/repos/postgres-ci/http200ok/issues/comments{/number}",
119+
"contents_url": "https://api.github.com/repos/postgres-ci/http200ok/contents/{+path}",
120+
"compare_url": "https://api.github.com/repos/postgres-ci/http200ok/compare/{base}...{head}",
121+
"merges_url": "https://api.github.com/repos/postgres-ci/http200ok/merges",
122+
"archive_url": "https://api.github.com/repos/postgres-ci/http200ok/{archive_format}{/ref}",
123+
"downloads_url": "https://api.github.com/repos/postgres-ci/http200ok/downloads",
124+
"issues_url": "https://api.github.com/repos/postgres-ci/http200ok/issues{/number}",
125+
"pulls_url": "https://api.github.com/repos/postgres-ci/http200ok/pulls{/number}",
126+
"milestones_url": "https://api.github.com/repos/postgres-ci/http200ok/milestones{/number}",
127+
"notifications_url": "https://api.github.com/repos/postgres-ci/http200ok/notifications{?since,all,participating}",
128+
"labels_url": "https://api.github.com/repos/postgres-ci/http200ok/labels{/name}",
129+
"releases_url": "https://api.github.com/repos/postgres-ci/http200ok/releases{/id}",
130+
"deployments_url": "https://api.github.com/repos/postgres-ci/http200ok/deployments",
131+
"created_at": "2016-04-20T19:10:09Z",
132+
"updated_at": "2016-05-17T21:32:50Z",
133+
"pushed_at": "2016-04-20T20:05:15Z",
134+
"git_url": "git://github.com/postgres-ci/http200ok.git",
135+
"ssh_url": "git@github.com:postgres-ci/http200ok.git",
136+
"clone_url": "https://github.com/postgres-ci/http200ok.git",
137+
"svn_url": "https://github.com/postgres-ci/http200ok",
138+
"homepage": null,
139+
"size": 131,
140+
"stargazers_count": 0,
141+
"watchers_count": 0,
142+
"language": "Go",
143+
"has_issues": false,
144+
"has_downloads": true,
145+
"has_wiki": false,
146+
"has_pages": false,
147+
"forks_count": 0,
148+
"mirror_url": null,
149+
"open_issues_count": 0,
150+
"forks": 0,
151+
"open_issues": 0,
152+
"watchers": 0,
153+
"default_branch": "master"
154+
},
155+
"sender": {
156+
"login": "kshvakov",
157+
"id": 978534,
158+
"avatar_url": "https://avatars.githubusercontent.com/u/978534?v=3",
159+
"gravatar_id": "",
160+
"url": "https://api.github.com/users/kshvakov",
161+
"html_url": "https://github.com/kshvakov",
162+
"followers_url": "https://api.github.com/users/kshvakov/followers",
163+
"following_url": "https://api.github.com/users/kshvakov/following{/other_user}",
164+
"gists_url": "https://api.github.com/users/kshvakov/gists{/gist_id}",
165+
"starred_url": "https://api.github.com/users/kshvakov/starred{/owner}{/repo}",
166+
"subscriptions_url": "https://api.github.com/users/kshvakov/subscriptions",
167+
"organizations_url": "https://api.github.com/users/kshvakov/orgs",
168+
"repos_url": "https://api.github.com/users/kshvakov/repos",
169+
"events_url": "https://api.github.com/users/kshvakov/events{/privacy}",
170+
"received_events_url": "https://api.github.com/users/kshvakov/received_events",
171+
"type": "User",
172+
"site_admin": false
173+
}
174+
}
175+
`
176+
)

src/tools/render/render.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@ func JSON(c *http200ok.Context, v interface{}) error {
100100
func JSONok(c *http200ok.Context) {
101101

102102
JSON(c, struct {
103-
Success bool `json:"success"`
104-
Message string `json:"message"`
103+
Success bool `json:"success"`
105104
}{
106105
Success: true,
107-
Message: "OK",
108106
})
109107
}
110108
func JSONError(c *http200ok.Context, code int, format string, a ...interface{}) error {

0 commit comments

Comments
 (0)