2023-03-28 19:39:22 +01:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 09:12:13 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 19:39:22 +01:00
|
|
|
|
2021-11-16 12:04:01 -06:00
|
|
|
//go:build !consulent
|
2017-09-25 20:40:42 +02:00
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2020-12-21 19:00:36 -05:00
|
|
|
"fmt"
|
2017-09-25 20:40:42 +02:00
|
|
|
"testing"
|
|
|
|
|
2019-03-27 08:54:56 -04:00
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
2017-09-25 20:40:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSegments(t *testing.T) {
|
|
|
|
dataDir := testutil.TempDir(t, "consul")
|
|
|
|
|
2020-12-21 17:17:16 -05:00
|
|
|
tests := []testCase{
|
2017-09-25 20:40:42 +02:00
|
|
|
{
|
2023-08-22 09:46:03 -05:00
|
|
|
desc: "segment name not in CE",
|
2017-10-20 11:46:16 +02:00
|
|
|
args: []string{
|
2017-09-25 20:40:42 +02:00
|
|
|
`-data-dir=` + dataDir,
|
|
|
|
},
|
2020-12-21 19:10:01 -05: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 09:45:33 -04:00
|
|
|
enterpriseConfigKeyError{key: "segment"}.Error(),
|
|
|
|
},
|
2017-09-25 20:40:42 +02:00
|
|
|
},
|
2017-10-11 10:15:55 +02:00
|
|
|
{
|
|
|
|
desc: "segment port must be set",
|
2017-10-20 11:46:16 +02:00
|
|
|
args: []string{
|
2017-10-11 10:15:55 +02:00
|
|
|
`-data-dir=` + dataDir,
|
|
|
|
},
|
2020-12-21 19:10:01 -05:00
|
|
|
json: []string{`{ "segments":[{ "name":"x" }] }`},
|
|
|
|
hcl: []string{`segments = [{ name = "x" }]`},
|
|
|
|
expectedErr: `Port for segment "x" cannot be <= 0`,
|
|
|
|
expectedWarnings: []string{
|
2020-04-28 09:45:33 -04:00
|
|
|
enterpriseConfigKeyError{key: "segments"}.Error(),
|
|
|
|
},
|
2017-10-11 10:15:55 +02:00
|
|
|
},
|
2017-09-25 20:40:42 +02:00
|
|
|
{
|
2023-08-22 09:46:03 -05:00
|
|
|
desc: "segments not in CE",
|
2017-10-20 11:46:16 +02:00
|
|
|
args: []string{
|
2017-09-25 20:40:42 +02:00
|
|
|
`-data-dir=` + dataDir,
|
|
|
|
},
|
2020-12-21 19:10:01 -05: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 09:45:33 -04:00
|
|
|
enterpriseConfigKeyError{key: "segments"}.Error(),
|
|
|
|
},
|
2017-09-25 20:40:42 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-12-21 19:00:36 -05:00
|
|
|
for _, tc := range tests {
|
2020-12-21 18:38:10 -05:00
|
|
|
for _, format := range []string{"json", "hcl"} {
|
2020-12-21 19:00:36 -05:00
|
|
|
name := fmt.Sprintf("%v_%v", tc.desc, format)
|
|
|
|
t.Run(name, tc.run(format, dataDir))
|
2020-12-21 18:38:10 -05:00
|
|
|
}
|
|
|
|
}
|
2017-09-25 20:40:42 +02:00
|
|
|
}
|