Minor cleanup

pull/8954/head
Mark Rushakoff 2017-10-13 17:28:24 -07:00
parent f3f1cc1064
commit 4ed2e6f21e
3 changed files with 11 additions and 13 deletions

View File

@ -25,7 +25,7 @@ func TestRetentionAutocreate(t *testing.T) {
cmd.MustRun()
c, err := client.NewHTTPClient(client.HTTPConfig{
Addr: "http://" + cmd.HTTPAddr(),
Addr: "http://" + cmd.BoundHTTPAddr(),
})
if err != nil {
t.Fatal(err)

View File

@ -26,12 +26,10 @@ func NewTestRunCommand(env map[string]string) *TestRunCommand {
cmd := run.NewCommand()
cmd.Getenv = func(k string) string {
// Return value in env map, if set.
var v string
if env != nil {
v = env[k]
}
if v != "" {
return v
if v, ok := env[k]; ok {
return v
}
}
// If the key wasn't explicitly set in env, use some reasonable defaults for test.
@ -61,7 +59,7 @@ func NewTestRunCommand(env map[string]string) *TestRunCommand {
// MustRun calls Command.Run and panics if there is an error.
func (c *TestRunCommand) MustRun() {
if err := c.Command.Run(); err != nil {
if err := c.Command.Run("-config", os.DevNull); err != nil {
panic(err)
}
}
@ -69,7 +67,7 @@ func (c *TestRunCommand) MustRun() {
// HTTPClient returns a new v2 HTTP client.
func (c *TestRunCommand) HTTPClient() client.Client {
cl, err := client.NewHTTPClient(client.HTTPConfig{
Addr: "http://" + c.HTTPAddr(),
Addr: "http://" + c.BoundHTTPAddr(),
})
if err != nil {
panic(err)
@ -77,11 +75,11 @@ func (c *TestRunCommand) HTTPClient() client.Client {
return cl
}
// HTTPAddr returns the bind address of the HTTP service, in form "localhost:65432".
func (c *TestRunCommand) HTTPAddr() string {
// BoundHTTPAddr returns the bind address of the HTTP service, in form "localhost:65432".
func (c *TestRunCommand) BoundHTTPAddr() string {
for _, s := range c.Command.Server.Services {
if s, ok := s.(*httpd.Service); ok {
return s.HTTPAddr()
return s.BoundHTTPAddr()
}
}
panic("Did not find HTTPD service!")

View File

@ -198,9 +198,9 @@ func (s *Service) Statistics(tags map[string]string) []models.Statistic {
return s.Handler.Statistics(models.NewTags(map[string]string{"bind": s.addr}).Merge(tags).Map())
}
// HTTPAddr returns the string version of the address that the HTTP server is listening on.
// BoundHTTPAddr returns the string version of the address that the HTTP server is listening on.
// This is useful if you start an ephemeral server in test with bind address localhost:0.
func (s *Service) HTTPAddr() string {
func (s *Service) BoundHTTPAddr() string {
return s.ln.Addr().String()
}