2016-01-25 17:56:57 +00:00
|
|
|
package github_webhooks
|
2016-01-23 00:43:33 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-05-23 10:21:34 +00:00
|
|
|
func GithubWebhookRequest(event string, jsonString string, t *testing.T) {
|
2016-01-25 17:56:57 +00:00
|
|
|
gh := NewGithubWebhooks()
|
2016-01-23 00:43:33 +00:00
|
|
|
req, _ := http.NewRequest("POST", "/", strings.NewReader(jsonString))
|
2016-05-23 10:21:34 +00:00
|
|
|
req.Header.Add("X-Github-Event", event)
|
2016-01-23 00:43:33 +00:00
|
|
|
w := httptest.NewRecorder()
|
|
|
|
gh.eventHandler(w, req)
|
|
|
|
if w.Code != http.StatusOK {
|
2016-05-23 10:21:34 +00:00
|
|
|
t.Errorf("POST "+event+" returned HTTP status code %v.\nExpected %v", w.Code, http.StatusOK)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-23 10:21:34 +00:00
|
|
|
func TestCommitCommentEvent(t *testing.T) {
|
|
|
|
GithubWebhookRequest("commit_comment", CommitCommentEventJSON(), t)
|
|
|
|
}
|
|
|
|
|
2016-01-23 00:43:33 +00:00
|
|
|
func TestDeleteEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("delete", DeleteEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeploymentEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("deployment", DeploymentEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeploymentStatusEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("deployment_status", DeploymentStatusEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestForkEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("fork", ForkEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGollumEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("gollum", GollumEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIssueCommentEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("issue_comment", IssueCommentEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIssuesEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("issues", IssuesEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMemberEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("member", MemberEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMembershipEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("membership", MembershipEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPageBuildEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("page_build", PageBuildEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublicEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("public", PublicEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPullRequestReviewCommentEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("pull_request_review_comment", PullRequestReviewCommentEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPushEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("push", PushEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReleaseEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("release", ReleaseEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRepositoryEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("repository", RepositoryEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStatusEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("status", StatusEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTeamAddEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("team_add", TeamAddEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestWatchEvent(t *testing.T) {
|
2016-05-23 10:21:34 +00:00
|
|
|
GithubWebhookRequest("watch", WatchEventJSON(), t)
|
2016-01-23 00:43:33 +00:00
|
|
|
}
|