Skip to content

Commit

Permalink
Merge pull request nats-io#333 from wallyqs/custom-monitoring-server-…
Browse files Browse the repository at this point in the history
…listen

Enables using the same listen from server for monitoring endpoint via `-a`
  • Loading branch information
derekcollison authored Aug 18, 2016
2 parents 1b8cde6 + e46b187 commit 21e5836
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions server/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ func processOptions(opts *Options) {
if opts.Host == "" {
opts.Host = DEFAULT_HOST
}
if opts.HTTPHost == "" {
// Default to same bind from server if left undefined
opts.HTTPHost = opts.Host
}
if opts.Port == 0 {
opts.Port = DEFAULT_PORT
} else if opts.Port == RANDOM_PORT {
Expand Down
30 changes: 29 additions & 1 deletion server/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestDefaultOptions(t *testing.T) {
Host: DEFAULT_HOST,
Port: DEFAULT_PORT,
MaxConn: DEFAULT_MAX_CONNECTIONS,
HTTPHost: DEFAULT_HOST,
PingInterval: DEFAULT_PING_INTERVAL,
MaxPingsOut: DEFAULT_PING_MAX_OUT,
TLSTimeout: float64(TLS_TIMEOUT) / float64(time.Second),
Expand Down Expand Up @@ -360,10 +361,13 @@ func TestListenConfig(t *testing.T) {
// Normal clients
host := "10.0.1.22"
port := 4422

monHost := "127.0.0.1"
if opts.Host != host {
t.Fatalf("Received incorrect host %q, expected %q\n", opts.Host, host)
}
if opts.HTTPHost != monHost {
t.Fatalf("Received incorrect host %q, expected %q\n", opts.HTTPHost, monHost)
}
if opts.Port != port {
t.Fatalf("Received incorrect port %v, expected %v\n", opts.Port, port)
}
Expand Down Expand Up @@ -409,6 +413,9 @@ func TestListenPortOnlyConfig(t *testing.T) {
if opts.Host != DEFAULT_HOST {
t.Fatalf("Received incorrect host %q, expected %q\n", opts.Host, DEFAULT_HOST)
}
if opts.HTTPHost != DEFAULT_HOST {
t.Fatalf("Received incorrect host %q, expected %q\n", opts.Host, DEFAULT_HOST)
}
if opts.Port != port {
t.Fatalf("Received incorrect port %v, expected %v\n", opts.Port, port)
}
Expand All @@ -426,11 +433,32 @@ func TestListenPortWithColonConfig(t *testing.T) {
if opts.Host != DEFAULT_HOST {
t.Fatalf("Received incorrect host %q, expected %q\n", opts.Host, DEFAULT_HOST)
}
if opts.HTTPHost != DEFAULT_HOST {
t.Fatalf("Received incorrect host %q, expected %q\n", opts.Host, DEFAULT_HOST)
}
if opts.Port != port {
t.Fatalf("Received incorrect port %v, expected %v\n", opts.Port, port)
}
}

func TestListenMonitoringDefault(t *testing.T) {
opts := &Options{
Host: "10.0.1.22",
}
processOptions(opts)

host := "10.0.1.22"
if opts.Host != host {
t.Fatalf("Received incorrect host %q, expected %q\n", opts.Host, host)
}
if opts.HTTPHost != host {
t.Fatalf("Received incorrect host %q, expected %q\n", opts.Host, host)
}
if opts.Port != DEFAULT_PORT {
t.Fatalf("Received incorrect port %v, expected %v\n", opts.Port, DEFAULT_PORT)
}
}

func TestMultipleUsersConfig(t *testing.T) {
opts, err := ProcessConfigFile("./configs/multiple_users.conf")
if err != nil {
Expand Down

0 comments on commit 21e5836

Please sign in to comment.