telegraf/plugins/inputs/github_webhooks/github_webhooks_test.go

96 lines
2.4 KiB
Go
Raw Normal View History

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