Skip to content

Commit a7e7ffd

Browse files
pcman312ncabatoff
authored andcommitted
Update MongoDB tests to not fail in Go 1.16 (#11533)
# Conflicts: # .circleci/config.yml # .circleci/config/commands/go_test.yml
1 parent 83ce6e1 commit a7e7ffd

File tree

10 files changed

+785
-3
lines changed

10 files changed

+785
-3
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ require (
5151
github.com/go-test/deep v1.0.7
5252
github.com/gocql/gocql v0.0.0-20210401103645-80ab1e13e309
5353
github.com/golang/protobuf v1.4.2
54+
github.com/google/go-cmp v0.5.5
5455
github.com/google/go-github v17.0.0+incompatible
5556
github.com/google/go-metrics-stackdriver v0.2.0
5657
github.com/hashicorp/consul-template v0.25.2

plugins/database/mongodb/mongodb_test.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ import (
77
"fmt"
88
"reflect"
99
"strings"
10+
"sync"
1011
"testing"
1112
"time"
1213

14+
"github.com/google/go-cmp/cmp"
15+
"github.com/google/go-cmp/cmp/cmpopts"
16+
1317
"github.com/hashicorp/vault/helper/testhelpers/certhelpers"
1418
"github.com/hashicorp/vault/helper/testhelpers/mongodb"
1519
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
@@ -346,9 +350,7 @@ func TestGetTLSAuth(t *testing.T) {
346350
if !test.expectErr && err != nil {
347351
t.Fatalf("no error expected, got: %s", err)
348352
}
349-
if !reflect.DeepEqual(actual, test.expectOpts) {
350-
t.Fatalf("Actual:\n%#v\nExpected:\n%#v", actual, test.expectOpts)
351-
}
353+
assertDeepEqual(t, test.expectOpts, actual)
352354
})
353355
}
354356
}
@@ -363,6 +365,27 @@ func appendToCertPool(t *testing.T, pool *x509.CertPool, caPem []byte) *x509.Cer
363365
return pool
364366
}
365367

368+
var cmpClientOptionsOpts = cmp.Options{
369+
cmp.AllowUnexported(options.ClientOptions{}),
370+
371+
cmp.AllowUnexported(tls.Config{}),
372+
cmpopts.IgnoreTypes(sync.Mutex{}, sync.RWMutex{}),
373+
374+
// 'lazyCerts' has a func field which can't be compared.
375+
cmpopts.IgnoreFields(x509.CertPool{}, "lazyCerts"),
376+
cmp.AllowUnexported(x509.CertPool{}),
377+
}
378+
379+
// Need a special comparison for ClientOptions because reflect.DeepEquals won't work in Go 1.16.
380+
// See: https://github.com/golang/go/issues/45891
381+
func assertDeepEqual(t *testing.T, a, b *options.ClientOptions) {
382+
t.Helper()
383+
384+
if diff := cmp.Diff(a, b, cmpClientOptionsOpts); diff != "" {
385+
t.Fatalf("assertion failed: values are not equal\n--- expected\n+++ actual\n%v", diff)
386+
}
387+
}
388+
366389
func createDBUser(t testing.TB, connURL, db, username, password string) {
367390
t.Helper()
368391

vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go

Lines changed: 148 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/google/go-cmp/cmp/cmpopts/errors_go113.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/google/go-cmp/cmp/cmpopts/errors_xerrors.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)