mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Fix tests - Update MongoDB driver (#17662)
* Fix tests - Update MongoDB driver * increase timeout and disconnect client after ping * increase timeout * disconnect client after the ping
This commit is contained in:
committed by
GitHub
parent
28f091abe4
commit
2a1753a469
@@ -14,13 +14,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/vault/helper/testhelpers/certhelpers"
|
||||
"github.com/hashicorp/vault/helper/testhelpers/mongodb"
|
||||
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
|
||||
"github.com/ory/dockertest"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||
"gopkg.in/mgo.v2"
|
||||
)
|
||||
|
||||
func TestInit_clientTLS(t *testing.T) {
|
||||
@@ -215,19 +213,12 @@ func startMongoWithTLS(t *testing.T, version string, confDir string) (retURL str
|
||||
// exponential backoff-retry
|
||||
err = pool.Retry(func() error {
|
||||
var err error
|
||||
dialInfo, err := mongodb.ParseMongoURL(retURL)
|
||||
if err != nil {
|
||||
return err
|
||||
ctx, _ := context.WithTimeout(context.Background(), 1*time.Minute)
|
||||
client, err := mongo.Connect(ctx, options.Client().ApplyURI(retURL))
|
||||
if err = client.Disconnect(ctx); err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
session, err := mgo.DialWithInfo(dialInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer session.Close()
|
||||
session.SetSyncTimeout(1 * time.Minute)
|
||||
session.SetSocketTimeout(1 * time.Minute)
|
||||
return session.Ping()
|
||||
return client.Ping(ctx, readpref.Primary())
|
||||
})
|
||||
if err != nil {
|
||||
cleanup()
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
|
||||
"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"
|
||||
@@ -27,7 +26,7 @@ import (
|
||||
const mongoAdminRole = `{ "db": "admin", "roles": [ { "role": "readWrite" } ] }`
|
||||
|
||||
func TestMongoDB_Initialize(t *testing.T) {
|
||||
cleanup, connURL := mongodb.PrepareTestContainer(t, "5.0.10")
|
||||
cleanup, connURL := mongodb.PrepareTestContainer(t, "latest")
|
||||
defer cleanup()
|
||||
|
||||
db := new()
|
||||
@@ -120,7 +119,7 @@ func TestNewUser_usernameTemplate(t *testing.T) {
|
||||
|
||||
for name, test := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
cleanup, connURL := mongodb.PrepareTestContainer(t, "5.0.10")
|
||||
cleanup, connURL := mongodb.PrepareTestContainer(t, "latest")
|
||||
defer cleanup()
|
||||
|
||||
db := new()
|
||||
@@ -146,7 +145,7 @@ func TestNewUser_usernameTemplate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMongoDB_CreateUser(t *testing.T) {
|
||||
cleanup, connURL := mongodb.PrepareTestContainer(t, "5.0.10")
|
||||
cleanup, connURL := mongodb.PrepareTestContainer(t, "latest")
|
||||
defer cleanup()
|
||||
|
||||
db := new()
|
||||
@@ -178,7 +177,7 @@ func TestMongoDB_CreateUser(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMongoDB_CreateUser_writeConcern(t *testing.T) {
|
||||
cleanup, connURL := mongodb.PrepareTestContainer(t, "5.0.10")
|
||||
cleanup, connURL := mongodb.PrepareTestContainer(t, "latest")
|
||||
defer cleanup()
|
||||
|
||||
initReq := dbplugin.InitializeRequest{
|
||||
@@ -212,7 +211,7 @@ func TestMongoDB_CreateUser_writeConcern(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMongoDB_DeleteUser(t *testing.T) {
|
||||
cleanup, connURL := mongodb.PrepareTestContainer(t, "5.0.10")
|
||||
cleanup, connURL := mongodb.PrepareTestContainer(t, "latest")
|
||||
defer cleanup()
|
||||
|
||||
db := new()
|
||||
@@ -252,7 +251,7 @@ func TestMongoDB_DeleteUser(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMongoDB_UpdateUser_Password(t *testing.T) {
|
||||
cleanup, connURL := mongodb.PrepareTestContainer(t, "5.0.10")
|
||||
cleanup, connURL := mongodb.PrepareTestContainer(t, "latest")
|
||||
defer cleanup()
|
||||
|
||||
// The docker test method PrepareTestContainer defaults to a database "test"
|
||||
|
||||
Reference in New Issue
Block a user