testutil: test server uses offset ports

This commit is contained in:
Ryan Uber 2015-09-10 18:57:53 -07:00
parent 35580ef9ec
commit 02564caa70
1 changed files with 44 additions and 10 deletions

View File

@ -29,13 +29,33 @@ var offset uint64
// TestServerConfig is the main server configuration struct.
type TestServerConfig struct {
HTTPAddr string `json:"http_addr,omitempty"`
Bootstrap bool `json:"bootstrap,omitempty"`
DataDir string `json:"data_dir,omitempty"`
Region string `json:"region,omitempty"`
DisableCheckpoint bool `json:"disable_update_check"`
LogLevel string `json:"log_level,omitempty"`
Stdout, Stderr io.Writer `json:"-"`
Bootstrap bool `json:"bootstrap,omitempty"`
DataDir string `json:"data_dir,omitempty"`
Region string `json:"region,omitempty"`
DisableCheckpoint bool `json:"disable_update_check"`
LogLevel string `json:"log_level,omitempty"`
Ports *PortsConfig `json:"ports,omitempty"`
Server *ServerConfig `json:"server,omitempty"`
Client *ClientConfig `json:"client,omitempty"`
Stdout, Stderr io.Writer `json:"-"`
}
// Ports is used to configure the network ports we use.
type PortsConfig struct {
HTTP int `json:"http,omitempty"`
RPC int `json:"rpc,omitempty"`
Serf int `json:"serf,omitempty"`
}
// ServerConfig is used to configure the nomad server.
type ServerConfig struct {
Enabled bool `json:"enabled"`
Bootstrap bool `json:"bootstrap"`
}
// ClientConfig is used to configure the client
type ClientConfig struct {
Enabled bool `json:"enabled"`
}
// ServerConfigCallback is a function interface which can be
@ -51,7 +71,18 @@ func defaultServerConfig() *TestServerConfig {
DisableCheckpoint: true,
Bootstrap: true,
LogLevel: "DEBUG",
HTTPAddr: fmt.Sprintf("127.0.0.1:%d", 20000+idx),
Ports: &PortsConfig{
HTTP: 20000 + idx,
RPC: 21000 + idx,
Serf: 22000 + idx,
},
Server: &ServerConfig{
Enabled: true,
Bootstrap: true,
},
Client: &ClientConfig{
Enabled: false,
},
}
}
@ -62,6 +93,7 @@ type TestServer struct {
t *testing.T
HTTPAddr string
SerfAddr string
HttpClient *http.Client
}
@ -91,6 +123,7 @@ func NewTestServer(t *testing.T, cb ServerConfigCallback) *TestServer {
}
configContent, err := json.Marshal(nomadConfig)
println(string(configContent))
if err != nil {
t.Fatalf("err: %s", err)
}
@ -111,7 +144,7 @@ func NewTestServer(t *testing.T, cb ServerConfigCallback) *TestServer {
}
// Start the server
cmd := exec.Command("nomad", "agent", "-dev", "-config", configFile.Name())
cmd := exec.Command("nomad", "agent", "-config", configFile.Name())
cmd.Stdout = stdout
cmd.Stderr = stderr
if err := cmd.Start(); err != nil {
@ -126,7 +159,8 @@ func NewTestServer(t *testing.T, cb ServerConfigCallback) *TestServer {
PID: cmd.Process.Pid,
t: t,
HTTPAddr: nomadConfig.HTTPAddr,
HTTPAddr: fmt.Sprintf("127.0.0.1:%d", nomadConfig.Ports.HTTP),
SerfAddr: fmt.Sprintf("127.0.0.1:%d", nomadConfig.Ports.Serf),
HttpClient: client,
}