From 2281d883b9397502481f49e7a31b76e0cf8cc97c Mon Sep 17 00:00:00 2001 From: Paul Banks Date: Fri, 27 Aug 2021 16:00:07 +0100 Subject: [PATCH] Fix some more Enterprise Normalization issues affecting tests --- agent/structs/config_entry_gateways_test.go | 9 ++++++--- agent/structs/config_entry_test.go | 14 +++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/agent/structs/config_entry_gateways_test.go b/agent/structs/config_entry_gateways_test.go index 2a6c7c5b59..3afc7cb03e 100644 --- a/agent/structs/config_entry_gateways_test.go +++ b/agent/structs/config_entry_gateways_test.go @@ -539,7 +539,6 @@ func TestIngressGatewayConfigEntry(t *testing.T) { }, }, }, - expectUnchanged: true, }, "TLS.SDS gateway-level": { entry: &IngressGatewayConfigEntry{ @@ -845,7 +844,9 @@ func TestIngressGatewayConfigEntry(t *testing.T) { }, }, }, - validateErr: "A service specifying TLS.SDS.CertResource must have at least one item in Hosts (service \"*\" on listener on port 1111)", + // Note we don't assert the last part `(service \"*\" on listener on port 1111)` + // since the service name is normalized differently on OSS and Ent + validateErr: "A service specifying TLS.SDS.CertResource must have at least one item in Hosts", }, "TLS.SDS at service level needs a cluster from somewhere": { entry: &IngressGatewayConfigEntry{ @@ -870,7 +871,9 @@ func TestIngressGatewayConfigEntry(t *testing.T) { }, }, }, - validateErr: "TLS.SDS.ClusterName is required if CertResource is set (service \"foo\" on listener on port 1111)", + // Note we don't assert the last part `(service \"foo\" on listener on port 1111)` + // since the service name is normalized differently on OSS and Ent + validateErr: "TLS.SDS.ClusterName is required if CertResource is set", }, } diff --git a/agent/structs/config_entry_test.go b/agent/structs/config_entry_test.go index 31a29d2ac7..7b82c2dd10 100644 --- a/agent/structs/config_entry_test.go +++ b/agent/structs/config_entry_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" "github.com/hashicorp/go-msgpack/codec" "github.com/hashicorp/hcl" "github.com/mitchellh/copystructure" @@ -2563,7 +2564,18 @@ func testConfigEntryNormalizeAndValidate(t *testing.T, cases map[string]configEn } if tc.expectUnchanged { - require.Equal(t, beforeNormalize, tc.entry, "Expected Normalize not to change anything") + // EnterpriseMeta.Normalize behaves differently in Ent and OSS which + // causes an exact comparison to fail. It's still useful to assert that + // nothing else changes though during Normalize. So we ignore + // EnterpriseMeta Defaults. + opts := cmp.Options{ + cmp.Comparer(func(a, b EnterpriseMeta) bool { + return a.IsSame(&b) + }), + } + if diff := cmp.Diff(beforeNormalize, tc.entry, opts); diff != "" { + t.Fatalf("expect unchanged after Normalize, got diff:\n%s", diff) + } } if tc.check != nil {