Update api module and decoding tests

This commit is contained in:
freddygv 2021-12-06 11:58:33 -07:00
parent 60fe5f75bb
commit 9b44861ce4
2 changed files with 54 additions and 24 deletions

View File

@ -65,8 +65,8 @@ type ServiceRouteHTTPMatchQueryParam struct {
type ServiceRouteDestination struct {
Service string `json:",omitempty"`
ServiceSubset string `json:",omitempty" alias:"service_subset"`
// Referencing other partitions is not supported.
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"`
@ -137,8 +137,8 @@ type ServiceSplit struct {
Weight float32
Service string `json:",omitempty"`
ServiceSubset string `json:",omitempty" alias:"service_subset"`
// Referencing other partitions is not supported.
Namespace string `json:",omitempty"`
Partition string `json:",omitempty"`
RequestHeaders *HTTPHeaderModifiers `json:",omitempty" alias:"request_headers"`
ResponseHeaders *HTTPHeaderModifiers `json:",omitempty" alias:"response_headers"`
}
@ -216,8 +216,8 @@ 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"`
Partition string `json:",omitempty"`
Datacenter string `json:",omitempty"`
}

View File

@ -791,6 +791,7 @@ func TestParseConfigEntry(t *testing.T) {
snake: `
kind = "service-router"
name = "main"
partition = "pepper"
meta {
"foo" = "bar"
"gir" = "zim"
@ -833,6 +834,7 @@ func TestParseConfigEntry(t *testing.T) {
service = "carrot"
service_subset = "kale"
namespace = "leek"
partition = "chard"
prefix_rewrite = "/alternate"
request_timeout = "99s"
num_retries = 12345
@ -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,
@ -1139,6 +1147,7 @@ func TestParseConfigEntry(t *testing.T) {
expect: &api.ServiceRouterConfigEntry{
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,7 +1330,8 @@ func TestParseConfigEntry(t *testing.T) {
{
"Weight": 0.9,
"Service": "other",
"Namespace": "alt"
"Namespace": "alt",
"Partition": "west"
}
]
}
@ -1321,6 +1339,7 @@ func TestParseConfigEntry(t *testing.T) {
expect: &api.ServiceSplitterConfigEntry{
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,10 +1571,12 @@ func TestParseConfigEntry(t *testing.T) {
{
"Kind": "service-resolver",
"Name": "main",
"Partition": "east",
"Redirect": {
"Service": "other",
"ServiceSubset": "backup",
"Namespace": "alt",
"Partition": "west",
"Datacenter": "dc9"
}
}
@ -1556,10 +1584,12 @@ func TestParseConfigEntry(t *testing.T) {
expect: &api.ServiceResolverConfigEntry{
Kind: "service-resolver",
Name: "main",
Partition: "east",
Redirect: &api.ServiceResolverRedirect{
Service: "other",
ServiceSubset: "backup",
Namespace: "alt",
Partition: "west",
Datacenter: "dc9",
},
},