mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-10 12:57:54 +00:00
Merge pull request #1242 from yuce/dont-create-tilde-directory-when-running-tests
Make sure ~ is expanded in NewServer; BroadcastReceiver uses temp path
This commit is contained in:
commit
24c9699432
3 changed files with 28 additions and 13 deletions
|
|
@ -56,9 +56,14 @@ func testMessageMarshal(t *testing.T, m proto.Message) {
|
|||
|
||||
// Ensure that BroadcastReceiver can register a BroadcastHandler.
|
||||
func TestBroadcast_BroadcastReceiver(t *testing.T) {
|
||||
path, err := ioutil.TempDir("", "pilosa-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
com := server.NewCommand(bytes.NewBuffer([]byte{}), ioutil.Discard, ioutil.Discard)
|
||||
com.Config.Bind = "localhost:0"
|
||||
err := com.SetupServer() // this test shouldn't need to import pilosa/server just to set up the Server, but it really shouldn't need to setup the Server at all. The Server should not be the implementation of Broadcast* TODO
|
||||
com.Config.DataDir = path
|
||||
err = com.SetupServer() // this test shouldn't need to import pilosa/server just to set up the Server, but it really shouldn't need to setup the Server at all. The Server should not be the implementation of Broadcast* TODO
|
||||
if err != nil {
|
||||
t.Fatalf("setting up server: %v", err)
|
||||
}
|
||||
|
|
|
|||
24
server.go
24
server.go
|
|
@ -22,6 +22,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -77,6 +78,7 @@ type Server struct {
|
|||
maxWritesPerRequest int
|
||||
|
||||
defaultClient InternalClient
|
||||
dataDir string
|
||||
}
|
||||
|
||||
// ServerOption is a functional option type for pilosa.Server
|
||||
|
|
@ -98,8 +100,7 @@ func OptServerReplicaN(n int) ServerOption {
|
|||
|
||||
func OptServerDataDir(dir string) ServerOption {
|
||||
return func(s *Server) error {
|
||||
s.Cluster.Path = dir
|
||||
s.Holder.Path = dir
|
||||
s.dataDir = dir
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
@ -231,9 +232,16 @@ func NewServer(opts ...ServerOption) (*Server, error) {
|
|||
}
|
||||
}
|
||||
|
||||
path, err := expandDirName(s.dataDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.Holder.Path = path
|
||||
s.Holder.Logger = s.logger
|
||||
s.Holder.Stats.SetLogger(s.logger)
|
||||
|
||||
s.Cluster.Path = path
|
||||
s.Cluster.Logger = s.logger
|
||||
s.Cluster.Holder = s.Holder
|
||||
|
||||
|
|
@ -784,3 +792,15 @@ type StatusHandler interface {
|
|||
ClusterStatus() (proto.Message, error)
|
||||
HandleRemoteStatus(proto.Message) error
|
||||
}
|
||||
|
||||
func expandDirName(path string) (string, error) {
|
||||
prefix := "~" + string(filepath.Separator)
|
||||
if strings.HasPrefix(path, prefix) {
|
||||
HomeDir := os.Getenv("HOME")
|
||||
if HomeDir == "" {
|
||||
return "", errors.New("data directory not specified and no home dir available")
|
||||
}
|
||||
return filepath.Join(HomeDir, strings.TrimPrefix(path, prefix)), nil
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
|
|
@ -93,14 +91,6 @@ func NewCommand(stdin io.Reader, stdout, stderr io.Writer) *Command {
|
|||
// Start starts the pilosa server - it returns once the server is running.
|
||||
func (m *Command) Start() (err error) {
|
||||
defer close(m.Started)
|
||||
prefix := "~" + string(filepath.Separator)
|
||||
if strings.HasPrefix(m.Config.DataDir, prefix) {
|
||||
HomeDir := os.Getenv("HOME")
|
||||
if HomeDir == "" {
|
||||
return errors.New("data directory not specified and no home dir available")
|
||||
}
|
||||
m.Config.DataDir = filepath.Join(HomeDir, strings.TrimPrefix(m.Config.DataDir, prefix))
|
||||
}
|
||||
|
||||
// SetupServer
|
||||
err = m.SetupServer()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue