From 0624c75c56902d49265e8fe823f16cfeb7d9b815 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 3 May 2021 12:12:12 -0400 Subject: [PATCH] testing: slightly better comparison for x509.CertPool --- connect/tls_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/connect/tls_test.go b/connect/tls_test.go index 9da69b3e1f..fe35229d89 100644 --- a/connect/tls_test.go +++ b/connect/tls_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" "github.com/stretchr/testify/require" "github.com/hashicorp/consul/agent" @@ -295,11 +294,11 @@ func requireEqualTLSConfig(t *testing.T, expect, got *tls.Config) { require.Equal(expectLeaf, gotLeaf) } -// lazyCerts has a func field which can't be compared. -var cmpCertPool = cmp.Options{ - cmpopts.IgnoreFields(x509.CertPool{}, "lazyCerts"), - cmp.AllowUnexported(x509.CertPool{}), -} +// cmpCertPool is a custom comparison for x509.CertPool, because CertPool.lazyCerts +// has a func field which can't be compared. +var cmpCertPool = cmp.Comparer(func(x, y *x509.CertPool) bool { + return cmp.Equal(x.Subjects(), y.Subjects()) +}) func assertDeepEqual(t *testing.T, x, y interface{}, opts ...cmp.Option) { t.Helper()