From e38b3e799ca3918d3ba01cb7589297d6f3b41efe Mon Sep 17 00:00:00 2001 From: Ross McDonald Date: Thu, 11 Feb 2016 10:05:04 -0600 Subject: [PATCH 1/3] Added test to http handler for checking the version header information. --- services/httpd/handler_test.go | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/services/httpd/handler_test.go b/services/httpd/handler_test.go index 5bdee17c4e..c60cf2b7f8 100644 --- a/services/httpd/handler_test.go +++ b/services/httpd/handler_test.go @@ -318,6 +318,49 @@ func TestHandler_Ping(t *testing.T) { } } +// Ensure the handler returns the version correctly from the different endpoints. +func TestHandler_Version(t *testing.T) { + h := NewHandler(false) + w := httptest.NewRecorder() + tests := []struct { + method string + endpoint string + body *bytes.Reader + }{ + { + method: "GET", + endpoint: "/ping", + body: nil, + }, + { + method: "GET", + endpoint: "/query?db=foo&q=SELECT+*+FROM+bar", + body: nil, + }, + { + method: "POST", + endpoint: "/write", + body: bytes.NewReader(make([]byte, 10)), + }, + } + + for _, test := range tests { + if test.body != nil { + h.ServeHTTP(w, MustNewRequest(test.method, test.endpoint, test.body)) + } else { + h.ServeHTTP(w, MustNewRequest(test.method, test.endpoint, nil)) + } + v, ok := w.HeaderMap["X-Influxdb-Version"] + if ok { + if v[0] != "0.0.0" { + t.Fatalf("unexpected version: %s", v) + } + } else { + t.Fatalf("Header entry 'X-Influxdb-Version' not present") + } + } +} + // Ensure the handler handles status requests correctly. func TestHandler_Status(t *testing.T) { h := NewHandler(false) From f1a5201e67ef2035e275173dbac421036a619aa8 Mon Sep 17 00:00:00 2001 From: Ross McDonald Date: Fri, 12 Feb 2016 14:32:07 -0600 Subject: [PATCH 2/3] Condensed check for version header into one line. --- services/httpd/handler_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/httpd/handler_test.go b/services/httpd/handler_test.go index c60cf2b7f8..f94cbb84ad 100644 --- a/services/httpd/handler_test.go +++ b/services/httpd/handler_test.go @@ -350,8 +350,7 @@ func TestHandler_Version(t *testing.T) { } else { h.ServeHTTP(w, MustNewRequest(test.method, test.endpoint, nil)) } - v, ok := w.HeaderMap["X-Influxdb-Version"] - if ok { + if v, ok := w.HeaderMap["X-Influxdb-Version"]; ok { if v[0] != "0.0.0" { t.Fatalf("unexpected version: %s", v) } From a724c90477adaebfb3034f48865368657062bd26 Mon Sep 17 00:00:00 2001 From: Ross McDonald Date: Tue, 16 Feb 2016 09:01:09 -0600 Subject: [PATCH 3/3] Changed body to io.Reader. --- services/httpd/handler_test.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/services/httpd/handler_test.go b/services/httpd/handler_test.go index f94cbb84ad..12813be5ae 100644 --- a/services/httpd/handler_test.go +++ b/services/httpd/handler_test.go @@ -325,7 +325,7 @@ func TestHandler_Version(t *testing.T) { tests := []struct { method string endpoint string - body *bytes.Reader + body io.Reader }{ { method: "GET", @@ -345,11 +345,7 @@ func TestHandler_Version(t *testing.T) { } for _, test := range tests { - if test.body != nil { - h.ServeHTTP(w, MustNewRequest(test.method, test.endpoint, test.body)) - } else { - h.ServeHTTP(w, MustNewRequest(test.method, test.endpoint, nil)) - } + h.ServeHTTP(w, MustNewRequest(test.method, test.endpoint, test.body)) if v, ok := w.HeaderMap["X-Influxdb-Version"]; ok { if v[0] != "0.0.0" { t.Fatalf("unexpected version: %s", v)