Rename internals struct.

Signed-off-by: François de Metz <francois@stormz.me>
Signed-off-by: Cyril Duez <cyril@stormz.me>
This commit is contained in:
François de Metz 2016-05-27 17:51:53 +02:00
parent 6775719975
commit a1927ea6ed
4 changed files with 17 additions and 19 deletions

View File

@ -12,26 +12,25 @@ import (
)
func init() {
webhooks_models.Add("github", func(path string) webhooks_models.Webhook { return NewGithubWebhooks(path) })
webhooks_models.Add("github", func(path string) webhooks_models.Webhook { return NewGithubWebhook(path) })
}
type GithubWebhooks struct {
type GithubWebhook struct {
Path string
acc telegraf.Accumulator
}
func NewGithubWebhooks(path string) *GithubWebhooks {
return &GithubWebhooks{Path: path}
func NewGithubWebhook(path string) *GithubWebhook {
return &GithubWebhook{Path: path}
}
func (gh *GithubWebhooks) Register(router *mux.Router, acc telegraf.Accumulator) {
func (gh *GithubWebhook) Register(router *mux.Router, acc telegraf.Accumulator) {
router.HandleFunc(gh.Path, gh.eventHandler).Methods("POST")
log.Printf("Started the webhooks_github on %s\n", gh.Path)
gh.acc = acc
}
// Handles the / route
func (gh *GithubWebhooks) eventHandler(w http.ResponseWriter, r *http.Request) {
func (gh *GithubWebhook) eventHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
eventType := r.Header["X-Github-Event"][0]
data, err := ioutil.ReadAll(r.Body)

View File

@ -11,7 +11,7 @@ import (
func GithubWebhookRequest(event string, jsonString string, t *testing.T) {
var acc testutil.Accumulator
gh := NewGithubWebhooks("/github")
gh := NewGithubWebhook("/github")
gh.acc = &acc
req, _ := http.NewRequest("POST", "/github", strings.NewReader(jsonString))
req.Header.Add("X-Github-Event", event)

View File

@ -14,26 +14,25 @@ import (
)
func init() {
webhooks_models.Add("rollbar", func(path string) webhooks_models.Webhook { return NewRollbarWebhooks(path) })
webhooks_models.Add("rollbar", func(path string) webhooks_models.Webhook { return NewRollbarWebhook(path) })
}
// FIXME: rename
type RollbarWebhooks struct {
type RollbarWebhook struct {
Path string
acc telegraf.Accumulator
}
func NewRollbarWebhooks(path string) *RollbarWebhooks {
return &RollbarWebhooks{Path: path}
func NewRollbarWebhook(path string) *RollbarWebhook {
return &RollbarWebhook{Path: path}
}
func (rb *RollbarWebhooks) Register(router *mux.Router, acc telegraf.Accumulator) {
func (rb *RollbarWebhook) Register(router *mux.Router, acc telegraf.Accumulator) {
router.HandleFunc(rb.Path, rb.eventHandler).Methods("POST")
log.Printf("Started the webhooks_rollbar on %s\n", rb.Path)
rb.acc = acc
}
func (rb *RollbarWebhooks) eventHandler(w http.ResponseWriter, r *http.Request) {
func (rb *RollbarWebhook) eventHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
data, err := ioutil.ReadAll(r.Body)
if err != nil {

View File

@ -9,7 +9,7 @@ import (
"github.com/influxdata/telegraf/testutil"
)
func postWebhooks(rb *RollbarWebhooks, eventBody string) *httptest.ResponseRecorder {
func postWebhooks(rb *RollbarWebhook, eventBody string) *httptest.ResponseRecorder {
req, _ := http.NewRequest("POST", "/", strings.NewReader(eventBody))
w := httptest.NewRecorder()
w.Code = 500
@ -21,7 +21,7 @@ func postWebhooks(rb *RollbarWebhooks, eventBody string) *httptest.ResponseRecor
func TestNewItem(t *testing.T) {
var acc testutil.Accumulator
rb := NewRollbarWebhooks("/rollbar")
rb := NewRollbarWebhook("/rollbar")
rb.acc = &acc
resp := postWebhooks(rb, NewItemJSON())
if resp.Code != http.StatusOK {
@ -45,7 +45,7 @@ func TestNewItem(t *testing.T) {
func TestDeploy(t *testing.T) {
var acc testutil.Accumulator
rb := NewRollbarWebhooks("/rollbar")
rb := NewRollbarWebhook("/rollbar")
rb.acc = &acc
resp := postWebhooks(rb, DeployJSON())
if resp.Code != http.StatusOK {
@ -66,7 +66,7 @@ func TestDeploy(t *testing.T) {
}
func TestUnknowItem(t *testing.T) {
rb := NewRollbarWebhooks("/rollbar")
rb := NewRollbarWebhook("/rollbar")
resp := postWebhooks(rb, UnknowJSON())
if resp.Code != http.StatusOK {
t.Errorf("POST unknow returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK)