From a1927ea6edd333f3198bf3d78d1a703d2b5688ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20de=20Metz?= Date: Fri, 27 May 2016 17:51:53 +0200 Subject: [PATCH] Rename internals struct. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: François de Metz Signed-off-by: Cyril Duez --- plugins/inputs/webhooks/github/github_webhooks.go | 13 ++++++------- .../inputs/webhooks/github/github_webhooks_test.go | 2 +- plugins/inputs/webhooks/rollbar/rollbar_webhooks.go | 13 ++++++------- .../webhooks/rollbar/rollbar_webhooks_test.go | 8 ++++---- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/plugins/inputs/webhooks/github/github_webhooks.go b/plugins/inputs/webhooks/github/github_webhooks.go index b0cf0bec9..6ef795430 100644 --- a/plugins/inputs/webhooks/github/github_webhooks.go +++ b/plugins/inputs/webhooks/github/github_webhooks.go @@ -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) diff --git a/plugins/inputs/webhooks/github/github_webhooks_test.go b/plugins/inputs/webhooks/github/github_webhooks_test.go index 4af51b536..219e94b82 100644 --- a/plugins/inputs/webhooks/github/github_webhooks_test.go +++ b/plugins/inputs/webhooks/github/github_webhooks_test.go @@ -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) diff --git a/plugins/inputs/webhooks/rollbar/rollbar_webhooks.go b/plugins/inputs/webhooks/rollbar/rollbar_webhooks.go index 985d5aa50..c09eb49c1 100644 --- a/plugins/inputs/webhooks/rollbar/rollbar_webhooks.go +++ b/plugins/inputs/webhooks/rollbar/rollbar_webhooks.go @@ -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 { diff --git a/plugins/inputs/webhooks/rollbar/rollbar_webhooks_test.go b/plugins/inputs/webhooks/rollbar/rollbar_webhooks_test.go index eda94ef74..05912f1bb 100644 --- a/plugins/inputs/webhooks/rollbar/rollbar_webhooks_test.go +++ b/plugins/inputs/webhooks/rollbar/rollbar_webhooks_test.go @@ -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)