diff options
author | 2021-08-25 15:34:33 +0200 | |
---|---|---|
committer | 2021-08-25 15:34:33 +0200 | |
commit | 2dc9fc1626507bb54417fc4a1920b847cafb27a2 (patch) | |
tree | 4ddeac479b923db38090aac8bd9209f3646851c1 /testrig/db.go | |
parent | Manually approves followers (#146) (diff) | |
download | gotosocial-2dc9fc1626507bb54417fc4a1920b847cafb27a2.tar.xz |
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
Diffstat (limited to 'testrig/db.go')
-rw-r--r-- | testrig/db.go | 90 |
1 files changed, 51 insertions, 39 deletions
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) } } } |