From 85bb6931199b895618cef790bae381d901f26716 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Fri, 12 Jun 2015 12:23:49 -0700 Subject: [PATCH] Unit test version in HTTP response --- cmd/influxd/run/server_helpers_test.go | 49 ++++++++++++++++++-------- cmd/influxd/run/server_test.go | 14 ++++++++ 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/cmd/influxd/run/server_helpers_test.go b/cmd/influxd/run/server_helpers_test.go index 344156b61c..aa51ac924c 100644 --- a/cmd/influxd/run/server_helpers_test.go +++ b/cmd/influxd/run/server_helpers_test.go @@ -35,27 +35,14 @@ func NewServer(c *run.Config) *Server { Server: srv, Config: c, } - // Set the logger to discard unless verbose is on - if !testing.Verbose() { - type logSetter interface { - SetLogger(*log.Logger) - } - nullLogger := log.New(ioutil.Discard, "", 0) - s.MetaStore.Logger = nullLogger - s.TSDBStore.Logger = nullLogger - for _, service := range s.Services { - if service, ok := service.(logSetter); ok { - service.SetLogger(nullLogger) - } - } - } - + configureLogging(&s) return &s } // OpenServer opens a test server. func OpenServer(c *run.Config, joinURLs string) *Server { s := NewServer(c) + configureLogging(s) if err := s.Open(); err != nil { panic(err.Error()) } @@ -63,6 +50,21 @@ func OpenServer(c *run.Config, joinURLs string) *Server { return s } +// OpenServerWithVersion opens a test server with a specific version. +func OpenServerWithVersion(c *run.Config, version string) *Server { + srv, _ := run.NewServer(c, version) + s := Server{ + Server: srv, + Config: c, + } + configureLogging(&s) + if err := s.Open(); err != nil { + panic(err.Error()) + } + + return &s +} + // Close shuts down the server and removes all temporary paths. func (s *Server) Close() { os.RemoveAll(s.Config.Meta.Dir) @@ -287,3 +289,20 @@ func (t *Test) init(s *Server) error { } return nil } + +func configureLogging(s *Server) { + // Set the logger to discard unless verbose is on + if !testing.Verbose() { + type logSetter interface { + SetLogger(*log.Logger) + } + nullLogger := log.New(ioutil.Discard, "", 0) + s.MetaStore.Logger = nullLogger + s.TSDBStore.Logger = nullLogger + for _, service := range s.Services { + if service, ok := service.(logSetter); ok { + service.SetLogger(nullLogger) + } + } + } +} diff --git a/cmd/influxd/run/server_test.go b/cmd/influxd/run/server_test.go index d145038e23..0e5be6a874 100644 --- a/cmd/influxd/run/server_test.go +++ b/cmd/influxd/run/server_test.go @@ -3,6 +3,7 @@ package run_test import ( "fmt" "log" + "net/http" "net/url" "strconv" "strings" @@ -10,6 +11,19 @@ import ( "time" ) +// Ensure that HTTP responses include the InfluxDB version. +func TestServer_HTTPResponseVersion(t *testing.T) { + version := "v1234" + s := OpenServerWithVersion(NewConfig(), version) + defer s.Close() + + resp, _ := http.Get(s.URL() + "/query") + got := resp.Header.Get("X-Influxdb-Version") + if version != version { + t.Errorf("Server responded with incorrect version, exp %s, got %s", version, got) + } +} + // Ensure the database commands work. func TestServer_DatabaseCommands(t *testing.T) { t.Parallel()