2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 18:39:22 +00:00
|
|
|
|
2021-11-16 18:04:01 +00:00
|
|
|
//go: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
|
|
|
{
|
2023-08-22 14:46:03 +00:00
|
|
|
desc: "segment name not in CE",
|
2017-10-20 09:46:16 +00:00
|
|
|
args: []string{
|
2017-09-25 18:40:42 +00:00
|
|
|
`-data-dir=` + dataDir,
|
|
|
|
},
|
2020-12-22 00:10:01 +00:00
|
|
|
json: []string{`{ "server": true, "segment": "a" }`},
|
|
|
|
hcl: []string{` server = true segment = "a" `},
|
|
|
|
expectedErr: `Network segments are not supported in this version of Consul`,
|
|
|
|
expectedWarnings: []string{
|
2020-04-28 13:45:33 +00:00
|
|
|
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,
|
|
|
|
},
|
2020-12-22 00:10:01 +00:00
|
|
|
json: []string{`{ "segments":[{ "name":"x" }] }`},
|
|
|
|
hcl: []string{`segments = [{ name = "x" }]`},
|
|
|
|
expectedErr: `Port for segment "x" cannot be <= 0`,
|
|
|
|
expectedWarnings: []string{
|
2020-04-28 13:45:33 +00:00
|
|
|
enterpriseConfigKeyError{key: "segments"}.Error(),
|
|
|
|
},
|
2017-10-11 08:15:55 +00:00
|
|
|
},
|
2017-09-25 18:40:42 +00:00
|
|
|
{
|
2023-08-22 14:46:03 +00:00
|
|
|
desc: "segments not in CE",
|
2017-10-20 09:46:16 +00:00
|
|
|
args: []string{
|
2017-09-25 18:40:42 +00:00
|
|
|
`-data-dir=` + dataDir,
|
|
|
|
},
|
2020-12-22 00:10:01 +00:00
|
|
|
json: []string{`{ "segments":[{ "name":"x", "port": 123 }] }`},
|
|
|
|
hcl: []string{`segments = [{ name = "x" port = 123 }]`},
|
|
|
|
expectedErr: `Network segments are not supported in this version of Consul`,
|
|
|
|
expectedWarnings: []string{
|
2020-04-28 13:45:33 +00:00
|
|
|
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
|
|
|
}
|