config: fix check for segment.port <= 0 and add test

This commit is contained in:
Frank Schroeder 2017-10-11 10:15:55 +02:00
parent a16dbc0212
commit 8cda75454a
No known key found for this signature in database
GPG Key ID: 4D65C6EAEC87DECD
2 changed files with 13 additions and 4 deletions

View File

@ -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(

View File

@ -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