Skip to content

Commit

Permalink
Update MongoDB tests to not fail in Go 1.16 (#11533)
Browse files Browse the repository at this point in the history
# Conflicts:
#	.circleci/config.yml
#	.circleci/config/commands/go_test.yml
  • Loading branch information
pcman312 authored and ncabatoff committed Dec 14, 2021
1 parent 83ce6e1 commit a7e7ffd
Show file tree
Hide file tree
Showing 10 changed files with 785 additions and 3 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -51,6 +51,7 @@ require (
github.com/go-test/deep v1.0.7
github.com/gocql/gocql v0.0.0-20210401103645-80ab1e13e309
github.com/golang/protobuf v1.4.2
github.com/google/go-cmp v0.5.5
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-metrics-stackdriver v0.2.0
github.com/hashicorp/consul-template v0.25.2
Expand Down
29 changes: 26 additions & 3 deletions plugins/database/mongodb/mongodb_test.go
Expand Up @@ -7,9 +7,13 @@ import (
"fmt"
"reflect"
"strings"
"sync"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"

"github.com/hashicorp/vault/helper/testhelpers/certhelpers"
"github.com/hashicorp/vault/helper/testhelpers/mongodb"
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
Expand Down Expand Up @@ -346,9 +350,7 @@ func TestGetTLSAuth(t *testing.T) {
if !test.expectErr && err != nil {
t.Fatalf("no error expected, got: %s", err)
}
if !reflect.DeepEqual(actual, test.expectOpts) {
t.Fatalf("Actual:\n%#v\nExpected:\n%#v", actual, test.expectOpts)
}
assertDeepEqual(t, test.expectOpts, actual)
})
}
}
Expand All @@ -363,6 +365,27 @@ func appendToCertPool(t *testing.T, pool *x509.CertPool, caPem []byte) *x509.Cer
return pool
}

var cmpClientOptionsOpts = cmp.Options{
cmp.AllowUnexported(options.ClientOptions{}),

cmp.AllowUnexported(tls.Config{}),
cmpopts.IgnoreTypes(sync.Mutex{}, sync.RWMutex{}),

// 'lazyCerts' has a func field which can't be compared.
cmpopts.IgnoreFields(x509.CertPool{}, "lazyCerts"),
cmp.AllowUnexported(x509.CertPool{}),
}

// Need a special comparison for ClientOptions because reflect.DeepEquals won't work in Go 1.16.
// See: https://github.com/golang/go/issues/45891
func assertDeepEqual(t *testing.T, a, b *options.ClientOptions) {
t.Helper()

if diff := cmp.Diff(a, b, cmpClientOptionsOpts); diff != "" {
t.Fatalf("assertion failed: values are not equal\n--- expected\n+++ actual\n%v", diff)
}
}

func createDBUser(t testing.TB, connURL, db, username, password string) {
t.Helper()

Expand Down
148 changes: 148 additions & 0 deletions vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/github.com/google/go-cmp/cmp/cmpopts/errors_go113.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions vendor/github.com/google/go-cmp/cmp/cmpopts/errors_xerrors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a7e7ffd

Please sign in to comment.