From 9b44861ce4bc2fabc6bb24dc4b790650cb27e922 Mon Sep 17 00:00:00 2001 From: freddygv Date: Mon, 6 Dec 2021 11:58:33 -0700 Subject: [PATCH] Update api module and decoding tests --- api/config_entry_discoverychain.go | 20 ++++---- command/config/write/config_write_test.go | 58 +++++++++++++++++------ 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/api/config_entry_discoverychain.go b/api/config_entry_discoverychain.go index b9c5994851..dfb2bcc101 100644 --- a/api/config_entry_discoverychain.go +++ b/api/config_entry_discoverychain.go @@ -63,10 +63,10 @@ type ServiceRouteHTTPMatchQueryParam struct { } type ServiceRouteDestination struct { - Service string `json:",omitempty"` - ServiceSubset string `json:",omitempty" alias:"service_subset"` - // Referencing other partitions is not supported. + Service string `json:",omitempty"` + ServiceSubset string `json:",omitempty" alias:"service_subset"` Namespace string `json:",omitempty"` + Partition string `json:",omitempty"` PrefixRewrite string `json:",omitempty" alias:"prefix_rewrite"` RequestTimeout time.Duration `json:",omitempty" alias:"request_timeout"` NumRetries uint32 `json:",omitempty" alias:"num_retries"` @@ -134,11 +134,11 @@ func (e *ServiceSplitterConfigEntry) GetCreateIndex() uint64 { return e.Crea func (e *ServiceSplitterConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex } type ServiceSplit struct { - Weight float32 - Service string `json:",omitempty"` - ServiceSubset string `json:",omitempty" alias:"service_subset"` - // Referencing other partitions is not supported. + Weight float32 + Service string `json:",omitempty"` + ServiceSubset string `json:",omitempty" alias:"service_subset"` Namespace string `json:",omitempty"` + Partition string `json:",omitempty"` RequestHeaders *HTTPHeaderModifiers `json:",omitempty" alias:"request_headers"` ResponseHeaders *HTTPHeaderModifiers `json:",omitempty" alias:"response_headers"` } @@ -216,9 +216,9 @@ type ServiceResolverSubset struct { type ServiceResolverRedirect struct { Service string `json:",omitempty"` ServiceSubset string `json:",omitempty" alias:"service_subset"` - // Referencing other partitions is not supported. - Namespace string `json:",omitempty"` - Datacenter string `json:",omitempty"` + Namespace string `json:",omitempty"` + Partition string `json:",omitempty"` + Datacenter string `json:",omitempty"` } type ServiceResolverFailover struct { diff --git a/command/config/write/config_write_test.go b/command/config/write/config_write_test.go index fc80e3b984..0ff5152c90 100644 --- a/command/config/write/config_write_test.go +++ b/command/config/write/config_write_test.go @@ -791,6 +791,7 @@ func TestParseConfigEntry(t *testing.T) { snake: ` kind = "service-router" name = "main" + partition = "pepper" meta { "foo" = "bar" "gir" = "zim" @@ -830,12 +831,13 @@ func TestParseConfigEntry(t *testing.T) { } } destination { - service = "carrot" - service_subset = "kale" - namespace = "leek" - prefix_rewrite = "/alternate" - request_timeout = "99s" - num_retries = 12345 + service = "carrot" + service_subset = "kale" + namespace = "leek" + partition = "chard" + prefix_rewrite = "/alternate" + request_timeout = "99s" + num_retries = 12345 retry_on_connect_failure = true retry_on_status_codes = [401, 209] } @@ -874,6 +876,7 @@ func TestParseConfigEntry(t *testing.T) { camel: ` Kind = "service-router" Name = "main" + Partition = "pepper" Meta { "foo" = "bar" "gir" = "zim" @@ -916,6 +919,7 @@ func TestParseConfigEntry(t *testing.T) { Service = "carrot" ServiceSubset = "kale" Namespace = "leek" + Partition = "chard" PrefixRewrite = "/alternate" RequestTimeout = "99s" NumRetries = 12345 @@ -958,6 +962,7 @@ func TestParseConfigEntry(t *testing.T) { { "kind": "service-router", "name": "main", + "partition": "pepper", "meta" : { "foo": "bar", "gir": "zim" @@ -1000,6 +1005,7 @@ func TestParseConfigEntry(t *testing.T) { "service": "carrot", "service_subset": "kale", "namespace": "leek", + "partition": "chard", "prefix_rewrite": "/alternate", "request_timeout": "99s", "num_retries": 12345, @@ -1049,6 +1055,7 @@ func TestParseConfigEntry(t *testing.T) { { "Kind": "service-router", "Name": "main", + "Partition": "pepper", "Meta" : { "foo": "bar", "gir": "zim" @@ -1091,6 +1098,7 @@ func TestParseConfigEntry(t *testing.T) { "Service": "carrot", "ServiceSubset": "kale", "Namespace": "leek", + "Partition": "chard", "PrefixRewrite": "/alternate", "RequestTimeout": "99s", "NumRetries": 12345, @@ -1137,8 +1145,9 @@ func TestParseConfigEntry(t *testing.T) { } `, expect: &api.ServiceRouterConfigEntry{ - Kind: "service-router", - Name: "main", + Kind: "service-router", + Name: "main", + Partition: "pepper", Meta: map[string]string{ "foo": "bar", "gir": "zim", @@ -1181,6 +1190,7 @@ func TestParseConfigEntry(t *testing.T) { Service: "carrot", ServiceSubset: "kale", Namespace: "leek", + Partition: "chard", PrefixRewrite: "/alternate", RequestTimeout: 99 * time.Second, NumRetries: 12345, @@ -1225,6 +1235,7 @@ func TestParseConfigEntry(t *testing.T) { snake: ` kind = "service-splitter" name = "main" + partition = "east" meta { "foo" = "bar" "gir" = "zim" @@ -1242,12 +1253,14 @@ func TestParseConfigEntry(t *testing.T) { weight = 0.9 service = "other" namespace = "alt" + partition = "west" }, ] `, camel: ` Kind = "service-splitter" Name = "main" + Partition = "east" Meta { "foo" = "bar" "gir" = "zim" @@ -1265,6 +1278,7 @@ func TestParseConfigEntry(t *testing.T) { Weight = 0.9 Service = "other" Namespace = "alt" + Partition = "west" }, ] `, @@ -1272,6 +1286,7 @@ func TestParseConfigEntry(t *testing.T) { { "kind": "service-splitter", "name": "main", + "partition": "east", "meta" : { "foo": "bar", "gir": "zim" @@ -1288,7 +1303,8 @@ func TestParseConfigEntry(t *testing.T) { { "weight": 0.9, "service": "other", - "namespace": "alt" + "namespace": "alt", + "partition": "west" } ] } @@ -1297,6 +1313,7 @@ func TestParseConfigEntry(t *testing.T) { { "Kind": "service-splitter", "Name": "main", + "Partition": "east", "Meta" : { "foo": "bar", "gir": "zim" @@ -1313,14 +1330,16 @@ func TestParseConfigEntry(t *testing.T) { { "Weight": 0.9, "Service": "other", - "Namespace": "alt" + "Namespace": "alt", + "Partition": "west" } ] } `, expect: &api.ServiceSplitterConfigEntry{ - Kind: api.ServiceSplitter, - Name: "main", + Kind: api.ServiceSplitter, + Name: "main", + Partition: "east", Meta: map[string]string{ "foo": "bar", "gir": "zim", @@ -1338,6 +1357,7 @@ func TestParseConfigEntry(t *testing.T) { Weight: 0.9, Service: "other", Namespace: "alt", + Partition: "west", }, }, }, @@ -1512,20 +1532,24 @@ func TestParseConfigEntry(t *testing.T) { snake: ` kind = "service-resolver" name = "main" + partition = "east" redirect { service = "other" service_subset = "backup" namespace = "alt" + partition = "west" datacenter = "dc9" } `, camel: ` Kind = "service-resolver" Name = "main" + Partition = "east" Redirect { Service = "other" ServiceSubset = "backup" Namespace = "alt" + Partition = "west" Datacenter = "dc9" } `, @@ -1533,10 +1557,12 @@ func TestParseConfigEntry(t *testing.T) { { "kind": "service-resolver", "name": "main", + "partition": "east", "redirect": { "service": "other", "service_subset": "backup", "namespace": "alt", + "partition": "west", "datacenter": "dc9" } } @@ -1545,21 +1571,25 @@ func TestParseConfigEntry(t *testing.T) { { "Kind": "service-resolver", "Name": "main", + "Partition": "east", "Redirect": { "Service": "other", "ServiceSubset": "backup", "Namespace": "alt", + "Partition": "west", "Datacenter": "dc9" } } `, expect: &api.ServiceResolverConfigEntry{ - Kind: "service-resolver", - Name: "main", + Kind: "service-resolver", + Name: "main", + Partition: "east", Redirect: &api.ServiceResolverRedirect{ Service: "other", ServiceSubset: "backup", Namespace: "alt", + Partition: "west", Datacenter: "dc9", }, },