2019-05-01 15:11:27 +00:00
|
|
|
// +build !consulent
|
2017-09-25 18:40:42 +00:00
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2020-12-22 00:00:36 +00:00
|
|
|
"fmt"
|
2017-09-25 18:40:42 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-03-27 12:54:56 +00:00
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
2017-09-25 18:40:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSegments(t *testing.T) {
|
|
|
|
dataDir := testutil.TempDir(t, "consul")
|
|
|
|
|
2020-12-21 22:17:16 +00:00
|
|
|
tests := []testCase{
|
2017-09-25 18:40:42 +00:00
|
|
|
{
|
|
|
|
desc: "segment name not in OSS",
|
2017-10-20 09:46:16 +00:00
|
|
|
args: []string{
|
2017-09-25 18:40:42 +00:00
|
|
|
`-data-dir=` + dataDir,
|
|
|
|
},
|
|
|
|
json: []string{`{ "server": true, "segment": "a" }`},
|
|
|
|
hcl: []string{` server = true segment = "a" `},
|
|
|
|
err: `Network segments are not supported in this version of Consul`,
|
2020-04-28 13:45:33 +00:00
|
|
|
warns: []string{
|
|
|
|
enterpriseConfigKeyError{key: "segment"}.Error(),
|
|
|
|
},
|
2017-09-25 18:40:42 +00:00
|
|
|
},
|
2017-10-11 08:15:55 +00:00
|
|
|
{
|
|
|
|
desc: "segment port must be set",
|
2017-10-20 09:46:16 +00:00
|
|
|
args: []string{
|
2017-10-11 08:15:55 +00:00
|
|
|
`-data-dir=` + dataDir,
|
|
|
|
},
|
|
|
|
json: []string{`{ "segments":[{ "name":"x" }] }`},
|
|
|
|
hcl: []string{`segments = [{ name = "x" }]`},
|
|
|
|
err: `Port for segment "x" cannot be <= 0`,
|
2020-04-28 13:45:33 +00:00
|
|
|
warns: []string{
|
|
|
|
enterpriseConfigKeyError{key: "segments"}.Error(),
|
|
|
|
},
|
2017-10-11 08:15:55 +00:00
|
|
|
},
|
2017-09-25 18:40:42 +00:00
|
|
|
{
|
|
|
|
desc: "segments not in OSS",
|
2017-10-20 09:46:16 +00:00
|
|
|
args: []string{
|
2017-09-25 18:40:42 +00:00
|
|
|
`-data-dir=` + dataDir,
|
|
|
|
},
|
2017-10-11 08:15:55 +00:00
|
|
|
json: []string{`{ "segments":[{ "name":"x", "port": 123 }] }`},
|
|
|
|
hcl: []string{`segments = [{ name = "x" port = 123 }]`},
|
2017-09-25 18:40:42 +00:00
|
|
|
err: `Network segments are not supported in this version of Consul`,
|
2020-04-28 13:45:33 +00:00
|
|
|
warns: []string{
|
|
|
|
enterpriseConfigKeyError{key: "segments"}.Error(),
|
|
|
|
},
|
2017-09-25 18:40:42 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-12-22 00:00:36 +00:00
|
|
|
for _, tc := range tests {
|
2020-12-21 23:38:10 +00:00
|
|
|
for _, format := range []string{"json", "hcl"} {
|
2020-12-22 00:00:36 +00:00
|
|
|
name := fmt.Sprintf("%v_%v", tc.desc, format)
|
|
|
|
t.Run(name, tc.run(format, dataDir))
|
2020-12-21 23:38:10 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-25 18:40:42 +00:00
|
|
|
}
|