config: fix check for segment.port <= 0 and add test
This commit is contained in:
parent
a16dbc0212
commit
8cda75454a
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue