Use method constants from the http package

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2019-06-28 15:23:00 +02:00
parent 9a1440d469
commit 48cd700822
2 changed files with 12 additions and 12 deletions

View File

@ -117,14 +117,14 @@ func New(url, job string) *Pusher {
// Push returns the first error encountered by any method call (including this
// one) in the lifetime of the Pusher.
func (p *Pusher) Push() error {
return p.push("PUT")
return p.push(http.MethodPut)
}
// Add works like push, but only previously pushed metrics with the same name
// (and the same job and other grouping labels) will be replaced. (It uses HTTP
// method “POST” to push to the Pushgateway.)
func (p *Pusher) Add() error {
return p.push("POST")
return p.push(http.MethodPost)
}
// Gatherer adds a Gatherer to the Pusher, from which metrics will be gathered

View File

@ -93,8 +93,8 @@ func TestPush(t *testing.T) {
Push(); err != nil {
t.Fatal(err)
}
if lastMethod != "PUT" {
t.Error("want method PUT for Push, got", lastMethod)
if lastMethod != http.MethodPut {
t.Errorf("got method %q for Push, want %q", lastMethod, http.MethodPut)
}
if !bytes.Equal(lastBody, wantBody) {
t.Errorf("got body %v, want %v", lastBody, wantBody)
@ -110,8 +110,8 @@ func TestPush(t *testing.T) {
Add(); err != nil {
t.Fatal(err)
}
if lastMethod != "POST" {
t.Error("want method POST for Add, got", lastMethod)
if lastMethod != http.MethodPost {
t.Errorf("got method %q for Add, want %q", lastMethod, http.MethodPost)
}
if !bytes.Equal(lastBody, wantBody) {
t.Errorf("got body %v, want %v", lastBody, wantBody)
@ -167,8 +167,8 @@ func TestPush(t *testing.T) {
Push(); err != nil {
t.Fatal(err)
}
if lastMethod != "PUT" {
t.Error("want method PUT for Push, got", lastMethod)
if lastMethod != http.MethodPut {
t.Errorf("got method %q for Push, want %q", lastMethod, http.MethodPut)
}
if !bytes.Equal(lastBody, wantBody) {
t.Errorf("got body %v, want %v", lastBody, wantBody)
@ -182,8 +182,8 @@ func TestPush(t *testing.T) {
Add(); err != nil {
t.Fatal(err)
}
if lastMethod != "POST" {
t.Error("want method POST for Add, got", lastMethod)
if lastMethod != http.MethodPost {
t.Errorf("got method %q for Add, want %q", lastMethod, http.MethodPost)
}
if !bytes.Equal(lastBody, wantBody) {
t.Errorf("got body %v, want %v", lastBody, wantBody)
@ -199,8 +199,8 @@ func TestPush(t *testing.T) {
Delete(); err != nil {
t.Fatal(err)
}
if lastMethod != "DELETE" {
t.Error("want method DELETE for delete, got", lastMethod)
if lastMethod != http.MethodDelete {
t.Errorf("got method %q for Delete, want %q", lastMethod, http.MethodDelete)
}
if len(lastBody) != 0 {
t.Errorf("got body of length %d, want empty body", len(lastBody))