From 2dc9fc1626507bb54417fc4a1920b847cafb27a2 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 25 Aug 2021 15:34:33 +0200 Subject: Pg to bun (#148) * start moving to bun * changing more stuff * more * and yet more * tests passing * seems stable now * more big changes * small fix * little fixes --- testrig/db.go | 90 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 39 deletions(-) (limited to 'testrig/db.go') diff --git a/testrig/db.go b/testrig/db.go index c670103f1..b0e2afd04 100644 --- a/testrig/db.go +++ b/testrig/db.go @@ -24,7 +24,7 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/db" - "github.com/superseriousbusiness/gotosocial/internal/db/pg" + "github.com/superseriousbusiness/gotosocial/internal/db/bundb" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/oauth" ) @@ -68,9 +68,9 @@ func NewTestDB() db.DB { l := logrus.New() l.SetLevel(logrus.TraceLevel) - testDB, err := pg.NewPostgresService(context.Background(), config, l) + testDB, err := bundb.NewBunDBService(context.Background(), config, l) if err != nil { - panic(err) + logrus.Panic(err) } return testDB } @@ -84,112 +84,124 @@ func NewTestDB() db.DB { // signatures with, otherwise this function will randomly generate new keys for accounts and signature // verification will fail. func StandardDBSetup(db db.DB, accounts map[string]*gtsmodel.Account) { + if db == nil { + logrus.Panic("db setup: db was nil") + } + + ctx := context.Background() + for _, m := range testModels { - if err := db.CreateTable(m); err != nil { - panic(err) + if err := db.CreateTable(ctx, m); err != nil { + logrus.Panicf("error creating table for %+v: %s", m, err) } } for _, v := range NewTestTokens() { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } for _, v := range NewTestClients() { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } for _, v := range NewTestApplications() { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } for _, v := range NewTestUsers() { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } if accounts == nil { for _, v := range NewTestAccounts() { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } } else { for _, v := range accounts { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } } for _, v := range NewTestAttachments() { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } for _, v := range NewTestStatuses() { - if err := db.PutStatus(v); err != nil { - panic(err) + if err := db.PutStatus(ctx, v); err != nil { + logrus.Panic(err) } } for _, v := range NewTestEmojis() { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } for _, v := range NewTestTags() { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } for _, v := range NewTestMentions() { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } for _, v := range NewTestFaves() { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } for _, v := range NewTestFollows() { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } for _, v := range NewTestNotifications() { - if err := db.Put(v); err != nil { - panic(err) + if err := db.Put(ctx, v); err != nil { + logrus.Panic(err) } } - if err := db.CreateInstanceAccount(); err != nil { - panic(err) + if err := db.CreateInstanceAccount(ctx); err != nil { + logrus.Panic(err) } - if err := db.CreateInstanceInstance(); err != nil { - panic(err) + if err := db.CreateInstanceInstance(ctx); err != nil { + logrus.Panic(err) } + + logrus.Debug("testing db setup complete") } // StandardDBTeardown drops all the standard testing tables/models from the database to ensure it's clean for the next test. func StandardDBTeardown(db db.DB) { + ctx := context.Background() + if db == nil { + logrus.Panic("db teardown: db was nil") + } for _, m := range testModels { - if err := db.DropTable(m); err != nil { - panic(err) + if err := db.DropTable(ctx, m); err != nil { + logrus.Panic(err) } } } -- cgit v1.2.3