structs: ensure exported-services PeerName field can be addressed as peer_name (#12862)

This commit is contained in:
R.B. Boyer 2022-04-27 10:27:21 -05:00 committed by GitHub
parent 238de66109
commit c949de9f50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 8 deletions

View File

@ -14,7 +14,7 @@ type ExportedServicesConfigEntry struct {
// Services is a list of services to be exported and the list of partitions // Services is a list of services to be exported and the list of partitions
// to expose them to. // to expose them to.
Services []ExportedService Services []ExportedService `json:",omitempty"`
Meta map[string]string `json:",omitempty"` Meta map[string]string `json:",omitempty"`
acl.EnterpriseMeta `hcl:",squash" mapstructure:",squash"` acl.EnterpriseMeta `hcl:",squash" mapstructure:",squash"`
@ -31,7 +31,7 @@ type ExportedService struct {
Namespace string `json:",omitempty"` Namespace string `json:",omitempty"`
// Consumers is a list of downstream consumers of the service to be exported. // Consumers is a list of downstream consumers of the service to be exported.
Consumers []ServiceConsumer Consumers []ServiceConsumer `json:",omitempty"`
} }
// ServiceConsumer represents a downstream consumer of the service to be exported. // ServiceConsumer represents a downstream consumer of the service to be exported.
@ -39,10 +39,10 @@ type ExportedService struct {
type ServiceConsumer struct { type ServiceConsumer struct {
// Partition is the admin partition to export the service to. // Partition is the admin partition to export the service to.
// Deprecated: PeerName should be used for both remote peers and local partitions. // Deprecated: PeerName should be used for both remote peers and local partitions.
Partition string Partition string `json:",omitempty"`
// PeerName is the name of the peer to export the service to. // PeerName is the name of the peer to export the service to.
PeerName string PeerName string `json:",omitempty" alias:"peer_name"`
} }
func (e *ExportedServicesConfigEntry) ToMap() map[string]map[string][]string { func (e *ExportedServicesConfigEntry) ToMap() map[string]map[string][]string {

View File

@ -1770,6 +1770,9 @@ func TestDecodeConfigEntry(t *testing.T) {
}, },
{ {
partition = "baz" partition = "baz"
},
{
peer_name = "flarm"
} }
] ]
}, },
@ -1801,6 +1804,9 @@ func TestDecodeConfigEntry(t *testing.T) {
}, },
{ {
Partition = "baz" Partition = "baz"
},
{
PeerName = "flarm"
} }
] ]
}, },
@ -1832,6 +1838,9 @@ func TestDecodeConfigEntry(t *testing.T) {
{ {
Partition: "baz", Partition: "baz",
}, },
{
PeerName: "flarm",
},
}, },
}, },
{ {

View File

@ -16,7 +16,7 @@ type ExportedServicesConfigEntry struct {
// Services is a list of services to be exported and the list of partitions // Services is a list of services to be exported and the list of partitions
// to expose them to. // to expose them to.
Services []ExportedService Services []ExportedService `json:",omitempty"`
Meta map[string]string `json:",omitempty"` Meta map[string]string `json:",omitempty"`
@ -40,7 +40,7 @@ type ExportedService struct {
Namespace string `json:",omitempty"` Namespace string `json:",omitempty"`
// Consumers is a list of downstream consumers of the service to be exported. // Consumers is a list of downstream consumers of the service to be exported.
Consumers []ServiceConsumer Consumers []ServiceConsumer `json:",omitempty"`
} }
// ServiceConsumer represents a downstream consumer of the service to be exported. // ServiceConsumer represents a downstream consumer of the service to be exported.
@ -48,10 +48,10 @@ type ExportedService struct {
type ServiceConsumer struct { type ServiceConsumer struct {
// Partition is the admin partition to export the service to. // Partition is the admin partition to export the service to.
// Deprecated: PeerName should be used for both remote peers and local partitions. // Deprecated: PeerName should be used for both remote peers and local partitions.
Partition string Partition string `json:",omitempty"`
// PeerName is the name of the peer to export the service to. // PeerName is the name of the peer to export the service to.
PeerName string PeerName string `json:",omitempty" alias:"peer_name"`
} }
func (e *ExportedServicesConfigEntry) GetKind() string { return ExportedServices } func (e *ExportedServicesConfigEntry) GetKind() string { return ExportedServices }

View File

@ -2891,6 +2891,9 @@ func TestParseConfigEntry(t *testing.T) {
}, },
{ {
partition = "baz" partition = "baz"
},
{
peer_name = "flarm"
} }
] ]
}, },
@ -2922,6 +2925,9 @@ func TestParseConfigEntry(t *testing.T) {
}, },
{ {
Partition = "baz" Partition = "baz"
},
{
PeerName = "flarm"
} }
] ]
}, },
@ -2954,6 +2960,9 @@ func TestParseConfigEntry(t *testing.T) {
}, },
{ {
"partition": "baz" "partition": "baz"
},
{
"peer_name": "flarm"
} }
] ]
}, },
@ -2987,6 +2996,9 @@ func TestParseConfigEntry(t *testing.T) {
}, },
{ {
"Partition": "baz" "Partition": "baz"
},
{
"PeerName": "flarm"
} }
] ]
}, },
@ -3019,6 +3031,9 @@ func TestParseConfigEntry(t *testing.T) {
{ {
Partition: "baz", Partition: "baz",
}, },
{
PeerName: "flarm",
},
}, },
}, },
{ {