From 8cda75454acc523bca028bc51b3465913e80fe01 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Wed, 11 Oct 2017 10:15:55 +0200 Subject: [PATCH] config: fix check for segment.port <= 0 and add test --- agent/config/builder.go | 4 ++-- agent/config/segments_oss_test.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/agent/config/builder.go b/agent/config/builder.go index 9698d0a6e..812b513e3 100644 --- a/agent/config/builder.go +++ b/agent/config/builder.go @@ -399,8 +399,8 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) { for _, s := range c.Segments { name := b.stringVal(s.Name) port := b.portVal(fmt.Sprintf("segments[%s].port", name), s.Port) - if port == 0 { - return RuntimeConfig{}, fmt.Errorf("Port must be specified for segment %q", s.Name) + if port <= 0 { + return RuntimeConfig{}, fmt.Errorf("Port for segment %q cannot be <= 0", name) } bind := b.makeTCPAddr( diff --git a/agent/config/segments_oss_test.go b/agent/config/segments_oss_test.go index 35b6db008..432107f27 100644 --- a/agent/config/segments_oss_test.go +++ b/agent/config/segments_oss_test.go @@ -27,13 +27,22 @@ func TestSegments(t *testing.T) { return []*net.IPAddr{ipAddr("10.0.0.1")}, nil }, }, + { + desc: "segment port must be set", + flags: []string{ + `-data-dir=` + dataDir, + }, + json: []string{`{ "segments":[{ "name":"x" }] }`}, + hcl: []string{`segments = [{ name = "x" }]`}, + err: `Port for segment "x" cannot be <= 0`, + }, { desc: "segments not in OSS", flags: []string{ `-data-dir=` + dataDir, }, - json: []string{`{ "segments":[{ "name":"x", "advertise": "unix:///foo" }] }`}, - hcl: []string{`segments = [{ name = "x" advertise = "unix:///foo" }]`}, + json: []string{`{ "segments":[{ "name":"x", "port": 123 }] }`}, + hcl: []string{`segments = [{ name = "x" port = 123 }]`}, err: `Network segments are not supported in this version of Consul`, privatev4: func() ([]*net.IPAddr, error) { return []*net.IPAddr{ipAddr("10.0.0.1")}, nil