open-consul/agent/structs/config_entry_exports_test.go
Derek Menteer ee59a81dc9
Add sameness-group to exported-services config entries (#16836)
This PR adds the sameness-group field to exported-service
config entries, which allows for services to be exported
to multiple destination partitions / peers easily.
2023-03-31 12:36:44 -05:00

98 lines
2 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package structs
import (
"testing"
)
func TestExportedServicesConfigEntry(t *testing.T) {
cases := map[string]configEntryTestcase{
"validate: empty service name": {
entry: &ExportedServicesConfigEntry{
Name: "default",
Services: []ExportedService{
{
Name: "",
},
},
},
validateErr: `service name cannot be empty`,
},
"validate: empty consumer list": {
entry: &ExportedServicesConfigEntry{
Name: "default",
Services: []ExportedService{
{
Name: "web",
},
},
},
validateErr: `must have at least one consumer`,
},
"validate: no wildcard in consumer partition": {
entry: &ExportedServicesConfigEntry{
Name: "default",
Services: []ExportedService{
{
Name: "api",
Consumers: []ServiceConsumer{
{
Partition: "foo",
},
},
},
{
Name: "web",
Consumers: []ServiceConsumer{
{
Partition: "*",
},
},
},
},
},
validateErr: `Services[1].Consumers[0]: exporting to all partitions (wildcard) is not supported`,
},
"validate: no wildcard in consumer peername": {
entry: &ExportedServicesConfigEntry{
Name: "default",
Services: []ExportedService{
{
Name: "web",
Consumers: []ServiceConsumer{
{
Peer: "foo",
},
{
Peer: "*",
},
},
},
},
},
validateErr: `Services[0].Consumers[1]: exporting to all peers (wildcard) is not supported`,
},
"validate: cannot specify consumer with partition and peername": {
entry: &ExportedServicesConfigEntry{
Name: "default",
Services: []ExportedService{
{
Name: "web",
Consumers: []ServiceConsumer{
{
Partition: "foo",
Peer: "bar",
},
},
},
},
},
validateErr: `Services[0].Consumers[0]: must define at most one of Peer, Partition, or SamenessGroup`,
},
}
testConfigEntryNormalizeAndValidate(t, cases)
}