From c4123791a91917a5d9bf57672b93121040ef53da Mon Sep 17 00:00:00 2001 From: Chris Piraino Date: Mon, 20 Apr 2020 09:02:35 -0500 Subject: [PATCH] Expect default enterprise metadata in gateway tests (#7664) This makes it so that both OSS and enterprise tests pass correctly In the api tests, explicitly set namespace to empty string so that tests can be shared. --- agent/config_endpoint_test.go | 18 ++++++++++++------ agent/structs/config_entry_gateways_test.go | 2 ++ api/config_entry_gateways_test.go | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/agent/config_endpoint_test.go b/agent/config_endpoint_test.go index b322cee90..2b9f3fcd5 100644 --- a/agent/config_endpoint_test.go +++ b/agent/config_endpoint_test.go @@ -227,13 +227,15 @@ func TestConfig_Apply_TerminatingGateway(t *testing.T) { got := out.Entries[0].(*structs.TerminatingGatewayConfigEntry) expect := []structs.LinkedService{ { - Name: "web", - CAFile: "/etc/web/ca.crt", - CertFile: "/etc/web/client.crt", - KeyFile: "/etc/web/tls.key", + Name: "web", + CAFile: "/etc/web/ca.crt", + CertFile: "/etc/web/client.crt", + KeyFile: "/etc/web/tls.key", + EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, { - Name: "api", + Name: "api", + EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, } require.Equal(t, expect, got.Services) @@ -292,10 +294,14 @@ func TestConfig_Apply_IngressGateway(t *testing.T) { Port: 8080, Protocol: "tcp", Services: []structs.IngressService{ - {Name: "web"}, + { + Name: "web", + EnterpriseMeta: *structs.DefaultEnterpriseMeta(), + }, }, }, }, + EnterpriseMeta: *structs.DefaultEnterpriseMeta(), } require.Equal(t, expect, got) } diff --git a/agent/structs/config_entry_gateways_test.go b/agent/structs/config_entry_gateways_test.go index 4b9d29c4b..525a501cc 100644 --- a/agent/structs/config_entry_gateways_test.go +++ b/agent/structs/config_entry_gateways_test.go @@ -37,6 +37,7 @@ func TestIngressConfigEntry_Normalize(t *testing.T) { Services: []IngressService{}, }, }, + EnterpriseMeta: *DefaultEnterpriseMeta(), }, }, { @@ -72,6 +73,7 @@ func TestIngressConfigEntry_Normalize(t *testing.T) { Services: []IngressService{}, }, }, + EnterpriseMeta: *DefaultEnterpriseMeta(), }, }, } diff --git a/api/config_entry_gateways_test.go b/api/config_entry_gateways_test.go index 81b6bff11..824673f08 100644 --- a/api/config_entry_gateways_test.go +++ b/api/config_entry_gateways_test.go @@ -105,12 +105,23 @@ func TestAPI_ConfigEntries_IngressGateway(t *testing.T) { require.True(t, ok) require.Equal(t, ingress1.Kind, readIngress.Kind) require.Equal(t, ingress1.Name, readIngress.Name) + + require.Len(t, readIngress.Listeners, 1) + require.Len(t, readIngress.Listeners[0].Services, 1) + // Set namespace to blank so that OSS and ent can utilize the same tests + readIngress.Listeners[0].Services[0].Namespace = "" + require.Equal(t, ingress1.Listeners, readIngress.Listeners) case "bar": readIngress, ok = entry.(*IngressGatewayConfigEntry) require.True(t, ok) require.Equal(t, ingress2.Kind, readIngress.Kind) require.Equal(t, ingress2.Name, readIngress.Name) + require.Len(t, readIngress.Listeners, 1) + require.Len(t, readIngress.Listeners[0].Services, 1) + // Set namespace to blank so that OSS and ent can utilize the same tests + readIngress.Listeners[0].Services[0].Namespace = "" + require.Equal(t, ingress2.Listeners, readIngress.Listeners) } } @@ -224,12 +235,20 @@ func TestAPI_ConfigEntries_TerminatingGateway(t *testing.T) { require.True(t, ok) require.Equal(t, terminating1.Kind, readTerminating.Kind) require.Equal(t, terminating1.Name, readTerminating.Name) + require.Len(t, readTerminating.Services, 1) + // Set namespace to blank so that OSS and ent can utilize the same tests + readTerminating.Services[0].Namespace = "" + require.Equal(t, terminating1.Services, readTerminating.Services) case "bar": readTerminating, ok = entry.(*TerminatingGatewayConfigEntry) require.True(t, ok) require.Equal(t, terminating2.Kind, readTerminating.Kind) require.Equal(t, terminating2.Name, readTerminating.Name) + require.Len(t, readTerminating.Services, 1) + // Set namespace to blank so that OSS and ent can utilize the same tests + readTerminating.Services[0].Namespace = "" + require.Equal(t, terminating2.Services, readTerminating.Services) } }