fix unit test of influxd in the windows

fix unit test of influxd in the windows
pull/5489/head
runner.mei 2016-01-31 16:33:13 +08:00
parent 9134d43ba6
commit 978305a6dd
5 changed files with 39 additions and 29 deletions

View File

@ -358,7 +358,7 @@ Options:
// retentionAndShardFromPath will take the shard relative path and split it into the
// retention policy name and shard ID. The first part of the path should be the database name.
func retentionAndShardFromPath(path string) (retention, shard string, err error) {
a := strings.Split(path, "/")
a := strings.Split(path, string(filepath.Separator))
if len(a) != 3 {
return "", "", fmt.Errorf("expected database, retention policy, and shard id in path: %s", path)
}

View File

@ -10,6 +10,8 @@ import (
"github.com/influxdb/influxdb/cmd/influxd/backup"
"github.com/influxdb/influxdb/cmd/influxd/restore"
"github.com/influxdb/influxdb/cmd/influxd/run"
"github.com/influxdb/influxdb/services/meta"
)
func TestServer_BackupAndRestore(t *testing.T) {
@ -56,7 +58,8 @@ func TestServer_BackupAndRestore(t *testing.T) {
// now backup
cmd := backup.NewCommand()
if err := cmd.Run("-host", config.Meta.BindAddress, "-database", "mydb", backupDir); err != nil {
hostAddress, _ := meta.DefaultHost(run.DefaultHostname, config.Meta.BindAddress)
if err := cmd.Run("-host", hostAddress, "-database", "mydb", backupDir); err != nil {
t.Fatalf("error backing up: %s", err.Error())
}
}()

View File

@ -30,7 +30,7 @@ import (
"github.com/influxdb/influxdb/services/udp"
"github.com/influxdb/influxdb/tcp"
"github.com/influxdb/influxdb/tsdb"
"github.com/influxdb/usage-client/v1"
client "github.com/influxdb/usage-client/v1"
// Initialize the engine packages
_ "github.com/influxdb/influxdb/tsdb/engine"
)
@ -123,8 +123,13 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) {
}
}
nodeAddr, err := meta.DefaultHost(DefaultHostname, c.Meta.HTTPBindAddress)
if err != nil {
return nil, err
}
// load the node information
metaAddresses := []string{c.Meta.HTTPBindAddress}
metaAddresses := []string{nodeAddr}
if !c.Meta.Enabled {
metaAddresses = c.Meta.JoinPeers
}
@ -149,11 +154,11 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) {
return nil, fmt.Errorf("must run as either meta node or data node or both")
}
httpBindAddress, err := defaultHost(DefaultHostname, c.HTTPD.BindAddress)
httpBindAddress, err := meta.DefaultHost(DefaultHostname, c.HTTPD.BindAddress)
if err != nil {
return nil, err
}
tcpBindAddress, err := defaultHost(DefaultHostname, bind)
tcpBindAddress, err := meta.DefaultHost(DefaultHostname, bind)
if err != nil {
return nil, err
}
@ -748,18 +753,6 @@ func stopProfile() {
}
}
func defaultHost(hostname, addr string) (string, error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {
return "", err
}
if host == "" {
return net.JoinHostPort(hostname, port), nil
}
return addr, nil
}
type tcpaddr struct{ host string }
func (a *tcpaddr) Network() string { return "tcp" }

View File

@ -99,9 +99,15 @@ func (s *Server) Close() {
if err := s.Server.Close(); err != nil {
panic(err.Error())
}
os.RemoveAll(s.Config.Meta.Dir)
os.RemoveAll(s.Config.Data.Dir)
os.RemoveAll(s.Config.HintedHandoff.Dir)
if err := os.RemoveAll(s.Config.Meta.Dir); err != nil {
panic(err.Error())
}
if err := os.RemoveAll(s.Config.Data.Dir); err != nil {
panic(err.Error())
}
if err := os.RemoveAll(s.Config.HintedHandoff.Dir); err != nil {
panic(err.Error())
}
}
// URL returns the base URL for the httpd endpoint.

View File

@ -96,15 +96,11 @@ func (c *Config) Validate() error {
}
func (c *Config) defaultHost(addr string) string {
host, port, err := net.SplitHostPort(addr)
if err != nil {
return addr
address, err := DefaultHost(DefaultHostname, addr)
if nil != err {
panic(err)
}
if host == "" {
return net.JoinHostPort(DefaultHostname, port)
}
return addr
return address
}
// DefaultedBindAddress returns the BindAddress normalized with the
@ -120,3 +116,15 @@ func (c *Config) DefaultedBindAddress() string {
func (c *Config) DefaultedHTTPBindAddress() string {
return c.defaultHost(c.HTTPBindAddress)
}
func DefaultHost(hostname, addr string) (string, error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {
return "", err
}
if host == "" || host == "0.0.0.0" || host == "::" {
return net.JoinHostPort(hostname, port), nil
}
return addr, nil
}