diff --git a/cmd/integration_config_test.go b/cmd/integration_config_test.go index 1ff2e3552d..b5011a5c2d 100644 --- a/cmd/integration_config_test.go +++ b/cmd/integration_config_test.go @@ -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) diff --git a/cmd/integration_test.go b/cmd/integration_test.go index b941ab3eb9..31ec11ea4b 100644 --- a/cmd/integration_test.go +++ b/cmd/integration_test.go @@ -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!") diff --git a/services/httpd/service.go b/services/httpd/service.go index 2b9647d429..5a55d473ee 100644 --- a/services/httpd/service.go +++ b/services/httpd/service.go @@ -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() }