diff --git a/database/database.go b/database/database.go index 184d0d30..14344844 100644 --- a/database/database.go +++ b/database/database.go @@ -127,30 +127,29 @@ func NewCustomDB(ctx context.Context, dbName string, creds DBCredentials, logger if err != nil { return nil, errors.AddContext(err, "failed to connect to DB") } - database := c.Database(dbName) + db := c.Database(dbName) if logger == nil { logger = &logrus.Logger{} } - err = ensureDBSchema(ctx, database, Schema, logger) + err = ensureDBSchema(ctx, db, Schema, logger) if err != nil { return nil, err } - db := &DB{ - staticDB: database, - staticUsers: database.Collection(collUsers), - staticSkylinks: database.Collection(collSkylinks), - staticUploads: database.Collection(collUploads), - staticDownloads: database.Collection(collDownloads), - staticRegistryReads: database.Collection(collRegistryReads), - staticRegistryWrites: database.Collection(collRegistryWrites), - staticEmails: database.Collection(collEmails), - staticChallenges: database.Collection(collChallenges), - staticUnconfirmedUserUpdates: database.Collection(collUnconfirmedUserUpdates), - staticConfiguration: database.Collection(collConfiguration), - staticAPIKeys: database.Collection(collAPIKeys), + return &DB{ + staticDB: db, + staticUsers: db.Collection(collUsers), + staticSkylinks: db.Collection(collSkylinks), + staticUploads: db.Collection(collUploads), + staticDownloads: db.Collection(collDownloads), + staticRegistryReads: db.Collection(collRegistryReads), + staticRegistryWrites: db.Collection(collRegistryWrites), + staticEmails: db.Collection(collEmails), + staticChallenges: db.Collection(collChallenges), + staticUnconfirmedUserUpdates: db.Collection(collUnconfirmedUserUpdates), + staticConfiguration: db.Collection(collConfiguration), + staticAPIKeys: db.Collection(collAPIKeys), staticLogger: logger, - } - return db, nil + }, nil } // Disconnect closes the connection to the database in an orderly fashion. diff --git a/test/database/apikeys_test.go b/test/database/apikeys_test.go index 5b10151f..1eb0327b 100644 --- a/test/database/apikeys_test.go +++ b/test/database/apikeys_test.go @@ -10,8 +10,6 @@ import ( // TestAPIKeys ensures the DB operations with API keys work as expected. func TestAPIKeys(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) diff --git a/test/database/challenge_test.go b/test/database/challenge_test.go index c6ac508a..b1dd3b70 100644 --- a/test/database/challenge_test.go +++ b/test/database/challenge_test.go @@ -18,8 +18,6 @@ import ( // TestValidateChallengeResponse is a unit test using a database. func TestValidateChallengeResponse(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) @@ -128,8 +126,6 @@ func TestValidateChallengeResponse(t *testing.T) { // TestUnconfirmedUserUpdate ensures the entire flow for unconfirmed user // updates works as expected. func TestUnconfirmedUserUpdate(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) diff --git a/test/database/configuration_test.go b/test/database/configuration_test.go index b9de09bd..14fd3c42 100644 --- a/test/database/configuration_test.go +++ b/test/database/configuration_test.go @@ -13,8 +13,6 @@ import ( // TestConfiguration ensures we can correctly read and write from/to the // configuration DB table. func TestConfiguration(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) diff --git a/test/database/upload_test.go b/test/database/upload_test.go index 8d839846..4a6eb26d 100644 --- a/test/database/upload_test.go +++ b/test/database/upload_test.go @@ -14,8 +14,6 @@ import ( // TestUploadsByUser ensures UploadsByUser returns the correct uploads, // in the correct order, with the correct sized and so on. func TestUploadsByUser(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) diff --git a/test/database/user_test.go b/test/database/user_test.go index b6143894..f8caa4d6 100644 --- a/test/database/user_test.go +++ b/test/database/user_test.go @@ -19,8 +19,6 @@ import ( // TestUserByEmail ensures UserByEmail works as expected. // This method also tests UserCreate. func TestUserByEmail(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) @@ -64,8 +62,6 @@ func TestUserByEmail(t *testing.T) { // TestUserByID ensures UserByID works as expected. func TestUserByID(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) @@ -105,8 +101,6 @@ func TestUserByID(t *testing.T) { // TestUserByPubKey makes sure UserByPubKey functions correctly, both with a // single and multiple pubkeys attached to a user. func TestUserByPubKey(t *testing.T) { - t.Parallel() - ctx := context.Background() name := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, name, test.DBTestCredentials(), nil) @@ -158,8 +152,6 @@ func TestUserByPubKey(t *testing.T) { // TestUserByStripeID ensures UserByStripeID works as expected. // This method also tests UserCreate and UserSetStripeID. func TestUserByStripeID(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) @@ -204,8 +196,6 @@ func TestUserByStripeID(t *testing.T) { // TestUserBySub ensures UserBySub works as expected. // This method also tests UserCreate. func TestUserBySub(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) @@ -248,8 +238,6 @@ func TestUserBySub(t *testing.T) { // TestUserConfirmEmail ensures that email confirmation works as expected, // including resecting the expiration of tokens. func TestUserConfirmEmail(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) @@ -288,8 +276,6 @@ func TestUserConfirmEmail(t *testing.T) { // TestUserCreate ensures UserCreate works as expected. func TestUserCreate(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) @@ -339,8 +325,6 @@ func TestUserCreate(t *testing.T) { // TestUserDelete ensures UserDelete works as expected. func TestUserDelete(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) @@ -379,8 +363,6 @@ func TestUserDelete(t *testing.T) { // TestUserSave ensures that UserSave works as expected. func TestUserSave(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) @@ -427,8 +409,6 @@ func TestUserSave(t *testing.T) { // TestUserSetStripeID ensures that UserSetStripeID works as expected. func TestUserSetStripeID(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) @@ -460,8 +440,6 @@ func TestUserSetStripeID(t *testing.T) { // TestUserSetTier ensures that UserSetTier works as expected. func TestUserSetTier(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil) @@ -491,8 +469,6 @@ func TestUserSetTier(t *testing.T) { // TestUserStats ensures we report accurate statistics for users. func TestUserStats(t *testing.T) { - t.Parallel() - ctx := context.Background() dbName := test.DBNameForTest(t.Name()) db, err := database.NewCustomDB(ctx, dbName, test.DBTestCredentials(), nil)