Merge pull request #10165 from hashicorp/dnephin/improve-cert-pool-cmp

testing: slightly better comparison for x509.CertPool
This commit is contained in:
Daniel Nephin 2021-05-06 14:04:55 -04:00 committed by GitHub
commit 5efced79c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 6 deletions

View File

@ -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()