From 098b9af9010b398529e59779e0e1ce4267eb34fa Mon Sep 17 00:00:00 2001 From: freddygv Date: Wed, 17 Mar 2021 23:05:00 -0600 Subject: [PATCH] Fixup enterprise tests from tproxy changes --- agent/consul/config_endpoint_test.go | 60 +++++++++++++--------------- agent/proxycfg/state_test.go | 6 +-- agent/service_manager_test.go | 28 ++++++++----- agent/structs/config_entry_test.go | 14 ++++--- 4 files changed, 57 insertions(+), 51 deletions(-) diff --git a/agent/consul/config_endpoint_test.go b/agent/consul/config_endpoint_test.go index 35f26ce3f5..188aab44f9 100644 --- a/agent/consul/config_endpoint_test.go +++ b/agent/consul/config_endpoint_test.go @@ -998,6 +998,9 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) { } t.Parallel() + mysql := structs.NewServiceID("mysql", structs.DefaultEnterpriseMeta()) + cache := structs.NewServiceID("cache", structs.DefaultEnterpriseMeta()) + tt := []struct { name string entries []structs.ConfigEntry @@ -1017,10 +1020,10 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) { }, &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, - Name: "foo", + Name: "api", Connect: &structs.ConnectConfiguration{ UpstreamConfigs: map[string]*structs.UpstreamConfig{ - "zip": { + mysql.String(): { Protocol: "http", }, }, @@ -1028,19 +1031,19 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) { }, }, request: structs.ServiceConfigRequest{ - Name: "foo", + Name: "api", Datacenter: "dc1", - Upstreams: []string{"zap"}, + Upstreams: []string{"cache"}, }, expect: structs.ServiceConfigResponse{ ProxyConfig: map[string]interface{}{ "protocol": "grpc", }, UpstreamConfigs: map[string]map[string]interface{}{ - "zip": { + "mysql": { "protocol": "http", }, - "zap": { + "cache": { "protocol": "grpc", }, }, @@ -1058,10 +1061,10 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) { }, &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, - Name: "foo", + Name: "api", Connect: &structs.ConnectConfiguration{ UpstreamConfigs: map[string]*structs.UpstreamConfig{ - "zip": { + mysql.String(): { Protocol: "http", }, }, @@ -1069,9 +1072,11 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) { }, }, request: structs.ServiceConfigRequest{ - Name: "foo", - Datacenter: "dc1", - UpstreamIDs: []structs.ServiceID{{ID: "zap"}}, + Name: "api", + Datacenter: "dc1", + UpstreamIDs: []structs.ServiceID{ + cache, + }, }, expect: structs.ServiceConfigResponse{ ProxyConfig: map[string]interface{}{ @@ -1079,17 +1084,14 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) { }, UpstreamIDConfigs: structs.OpaqueUpstreamConfigs{ { - Upstream: structs.ServiceID{ - ID: "zap", - EnterpriseMeta: *structs.DefaultEnterpriseMeta(), - }, + Upstream: cache, Config: map[string]interface{}{ "protocol": "grpc", }, }, { Upstream: structs.ServiceID{ - ID: "zip", + ID: "mysql", EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, Config: map[string]interface{}{ @@ -1104,7 +1106,7 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) { entries: []structs.ConfigEntry{ &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, - Name: "foo", + Name: "api", Connect: &structs.ConnectConfiguration{ UpstreamDefaults: &structs.UpstreamConfig{ MeshGateway: structs.MeshGatewayConfig{Mode: structs.MeshGatewayModeRemote}, @@ -1113,22 +1115,19 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) { }, }, request: structs.ServiceConfigRequest{ - Name: "foo", + Name: "api", Datacenter: "dc1", MeshGateway: structs.MeshGatewayConfig{ Mode: structs.MeshGatewayModeNone, }, UpstreamIDs: []structs.ServiceID{ - {ID: "zap"}, + mysql, }, }, expect: structs.ServiceConfigResponse{ UpstreamIDConfigs: structs.OpaqueUpstreamConfigs{ { - Upstream: structs.ServiceID{ - ID: "zap", - EnterpriseMeta: *structs.DefaultEnterpriseMeta(), - }, + Upstream: mysql, Config: map[string]interface{}{ "mesh_gateway": map[string]interface{}{ "Mode": "none", @@ -1150,12 +1149,12 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) { }, &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, - Name: "foo", + Name: "api", Protocol: "tcp", }, &structs.ServiceConfigEntry{ Kind: structs.ServiceDefaults, - Name: "foo", + Name: "api", Connect: &structs.ConnectConfiguration{ UpstreamDefaults: &structs.UpstreamConfig{ Protocol: "http", @@ -1166,7 +1165,7 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) { }, }, UpstreamConfigs: map[string]*structs.UpstreamConfig{ - "zap": { + mysql.String(): { Protocol: "grpc", MeshGateway: structs.MeshGatewayConfig{Mode: structs.MeshGatewayModeLocal}, }, @@ -1175,13 +1174,13 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) { }, }, request: structs.ServiceConfigRequest{ - Name: "foo", + Name: "api", Datacenter: "dc1", MeshGateway: structs.MeshGatewayConfig{ Mode: structs.MeshGatewayModeNone, }, UpstreamIDs: []structs.ServiceID{ - {ID: "zap"}, + mysql, }, }, expect: structs.ServiceConfigResponse{ @@ -1190,10 +1189,7 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) { }, UpstreamIDConfigs: structs.OpaqueUpstreamConfigs{ { - Upstream: structs.ServiceID{ - ID: "zap", - EnterpriseMeta: *structs.DefaultEnterpriseMeta(), - }, + Upstream: mysql, Config: map[string]interface{}{ "passive_health_check": map[string]interface{}{ "Interval": int64(10), diff --git a/agent/proxycfg/state_test.go b/agent/proxycfg/state_test.go index a93e6adb26..0c98e6c0a5 100644 --- a/agent/proxycfg/state_test.go +++ b/agent/proxycfg/state_test.go @@ -1664,7 +1664,7 @@ func TestState_WatchesAndUpdates(t *testing.T) { { requiredWatches: map[string]verifyWatchRequest{ "discovery-chain:" + dbStr: genVerifyDiscoveryChainWatch(&structs.DiscoveryChainRequest{ - Name: dbStr, + Name: "db", EvaluateInDatacenter: "dc1", EvaluateInNamespace: "default", Datacenter: "dc1", @@ -1686,11 +1686,11 @@ func TestState_WatchesAndUpdates(t *testing.T) { }, { requiredWatches: map[string]verifyWatchRequest{ - "upstream-target:db.default.dc1:db": genVerifyServiceWatch("db", "", "dc1", true), + "upstream-target:db.default.dc1:" + dbStr: genVerifyServiceWatch("db", "", "dc1", true), }, events: []cache.UpdateEvent{ { - CorrelationID: "upstream-target:db.default.dc1:db", + CorrelationID: "upstream-target:db.default.dc1:" + dbStr, Result: &structs.IndexedCheckServiceNodes{ Nodes: structs.CheckServiceNodes{ { diff --git a/agent/service_manager_test.go b/agent/service_manager_test.go index de3b4e3cc3..7a4ef3eec4 100644 --- a/agent/service_manager_test.go +++ b/agent/service_manager_test.go @@ -112,8 +112,9 @@ func TestServiceManager_RegisterSidecar(t *testing.T) { LocalServicePort: 8000, Upstreams: structs.Upstreams{ { - DestinationName: "redis", - LocalBindPort: 5000, + DestinationName: "redis", + DestinationNamespace: "default", + LocalBindPort: 5000, }, }, }, @@ -141,8 +142,9 @@ func TestServiceManager_RegisterSidecar(t *testing.T) { }, Upstreams: structs.Upstreams{ { - DestinationName: "redis", - LocalBindPort: 5000, + DestinationName: "redis", + DestinationNamespace: "default", + LocalBindPort: 5000, Config: map[string]interface{}{ "protocol": "tcp", }, @@ -341,8 +343,9 @@ func TestServiceManager_PersistService_API(t *testing.T) { LocalServicePort: 8000, Upstreams: structs.Upstreams{ { - DestinationName: "redis", - LocalBindPort: 5000, + DestinationName: "redis", + DestinationNamespace: "default", + LocalBindPort: 5000, }, }, }, @@ -366,8 +369,9 @@ func TestServiceManager_PersistService_API(t *testing.T) { }, Upstreams: structs.Upstreams{ { - DestinationName: "redis", - LocalBindPort: 5000, + DestinationName: "redis", + DestinationNamespace: "default", + LocalBindPort: 5000, Config: map[string]interface{}{ "protocol": "tcp", }, @@ -550,6 +554,7 @@ func TestServiceManager_PersistService_ConfigFiles(t *testing.T) { local_service_port = 8000 upstreams = [{ destination_name = "redis" + destination_namespace = "default" local_bind_port = 5000 }] } @@ -592,9 +597,10 @@ func TestServiceManager_PersistService_ConfigFiles(t *testing.T) { }, Upstreams: structs.Upstreams{ { - DestinationType: "service", - DestinationName: "redis", - LocalBindPort: 5000, + DestinationType: "service", + DestinationName: "redis", + DestinationNamespace: "default", + LocalBindPort: 5000, Config: map[string]interface{}{ "protocol": "tcp", }, diff --git a/agent/structs/config_entry_test.go b/agent/structs/config_entry_test.go index 523cab0025..bff3315c50 100644 --- a/agent/structs/config_entry_test.go +++ b/agent/structs/config_entry_test.go @@ -1531,8 +1531,9 @@ func TestServiceConfigEntry_Normalize(t *testing.T) { Name: "web", }, expect: ServiceConfigEntry{ - Kind: ServiceDefaults, - Name: "web", + Kind: ServiceDefaults, + Name: "web", + EnterpriseMeta: *DefaultEnterpriseMeta(), }, }, { @@ -1543,9 +1544,10 @@ func TestServiceConfigEntry_Normalize(t *testing.T) { Protocol: "PrOtoCoL", }, expect: ServiceConfigEntry{ - Kind: ServiceDefaults, - Name: "web", - Protocol: "protocol", + Kind: ServiceDefaults, + Name: "web", + Protocol: "protocol", + EnterpriseMeta: *DefaultEnterpriseMeta(), }, }, { @@ -1564,6 +1566,7 @@ func TestServiceConfigEntry_Normalize(t *testing.T) { }, UpstreamDefaults: &UpstreamConfig{ConnectTimeoutMs: -20}, }, + EnterpriseMeta: *DefaultEnterpriseMeta(), }, expect: ServiceConfigEntry{ Kind: ServiceDefaults, @@ -1582,6 +1585,7 @@ func TestServiceConfigEntry_Normalize(t *testing.T) { ConnectTimeoutMs: 0, }, }, + EnterpriseMeta: *DefaultEnterpriseMeta(), }, }, }