Unit test version in HTTP response

pull/2969/head
Philip O'Toole 2015-06-12 12:23:49 -07:00
parent d5fda01c2a
commit 85bb693119
2 changed files with 48 additions and 15 deletions

View File

@ -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)
}
}
}
}

View File

@ -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()