Store commandOptions on test.Main for use in Reopen(); unexport serverOptions

This commit is contained in:
Cody Soyland 2018-06-26 08:46:56 -05:00
parent ff7c3cb512
commit e448d47004
2 changed files with 7 additions and 5 deletions

View file

@ -77,14 +77,14 @@ type Command struct {
Handler pilosa.Handler
ln net.Listener
ServerOptions []pilosa.ServerOption
serverOptions []pilosa.ServerOption
}
type CommandOption func(c *Command) error
func OptCommandServerOptions(opts ...pilosa.ServerOption) CommandOption {
return func(c *Command) error {
c.ServerOptions = append(c.ServerOptions, opts...)
c.serverOptions = append(c.serverOptions, opts...)
return nil
}
}
@ -266,7 +266,7 @@ func (m *Command) SetupServer() error {
pilosa.OptServerClusterDisabled(m.Config.Cluster.Disabled, m.Config.Cluster.Hosts),
}
serverOptions = append(serverOptions, m.ServerOptions...)
serverOptions = append(serverOptions, m.serverOptions...)
m.Server, err = pilosa.NewServer(serverOptions...)

View file

@ -38,6 +38,8 @@ import (
type Main struct {
*server.Command
commandOptions []server.CommandOption
Stdin bytes.Buffer
Stdout bytes.Buffer
Stderr bytes.Buffer
@ -64,7 +66,7 @@ func NewMain(opts ...server.CommandOption) *Main {
panic(err)
}
m := &Main{Command: server.NewCommand(os.Stdin, os.Stdout, os.Stderr, opts...)}
m := &Main{Command: server.NewCommand(os.Stdin, os.Stdout, os.Stderr, opts...), commandOptions: opts}
m.Config.DataDir = path
m.Config.Bind = "http://localhost:0"
m.Config.Cluster.Disabled = true
@ -156,7 +158,7 @@ func (m *Main) Reopen() error {
// Create new main with the same config.
config := m.Command.Config
m.Command = server.NewCommand(os.Stdin, os.Stdout, os.Stderr, server.OptCommandServerOptions(m.ServerOptions...))
m.Command = server.NewCommand(os.Stdin, os.Stdout, os.Stderr, m.commandOptions...)
m.Command.Config = config
err := m.SetupServer()
if err != nil {