Skip to content

Commit

Permalink
testing: slightly better comparison for x509.CertPool
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed May 6, 2021
1 parent f5afed8 commit 0624c75
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions connect/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0624c75

Please sign in to comment.