From 48cd700822d25b9c3fcd0851160b81fb5b7458ad Mon Sep 17 00:00:00 2001 From: beorn7 Date: Fri, 28 Jun 2019 15:23:00 +0200 Subject: [PATCH] Use method constants from the http package Signed-off-by: beorn7 --- prometheus/push/push.go | 4 ++-- prometheus/push/push_test.go | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/prometheus/push/push.go b/prometheus/push/push.go index 61f5697..02b11fa 100644 --- a/prometheus/push/push.go +++ b/prometheus/push/push.go @@ -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 diff --git a/prometheus/push/push_test.go b/prometheus/push/push_test.go index c34f948..0fc4110 100644 --- a/prometheus/push/push_test.go +++ b/prometheus/push/push_test.go @@ -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))