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