Update MongoDB tests to not fail in Go 1.16 (#11533)

This commit is contained in:
Michael Golowka
2021-05-12 15:22:02 -06:00
committed by GitHub
parent c180ba706c
commit c191081750
12 changed files with 791 additions and 9 deletions

View File

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