diff options
Diffstat (limited to 'testrig')
-rw-r--r-- | testrig/db.go | 52 | ||||
-rw-r--r-- | testrig/log.go | 16 | ||||
-rw-r--r-- | testrig/transportcontroller.go | 12 |
3 files changed, 47 insertions, 33 deletions
diff --git a/testrig/db.go b/testrig/db.go index b4c05d727..ae3132835 100644 --- a/testrig/db.go +++ b/testrig/db.go @@ -23,11 +23,11 @@ import ( "os" "strconv" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/bundb" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/log" ) var testModels = []interface{}{ @@ -91,7 +91,7 @@ func NewTestDB() db.DB { testDB, err := bundb.NewBunDBService(context.Background()) if err != nil { - logrus.Panic(err) + log.Panic(err) } return testDB } @@ -101,7 +101,7 @@ func CreateTestTables(db db.DB) { ctx := context.Background() for _, m := range testModels { if err := db.CreateTable(ctx, m); err != nil { - logrus.Panicf("error creating table for %+v: %s", m, err) + log.Panicf("error creating table for %+v: %s", m, err) } } } @@ -116,7 +116,7 @@ func CreateTestTables(db db.DB) { // verification will fail. func StandardDBSetup(db db.DB, accounts map[string]*gtsmodel.Account) { if db == nil { - logrus.Panic("db setup: db was nil") + log.Panic("db setup: db was nil") } CreateTestTables(db) @@ -125,128 +125,128 @@ func StandardDBSetup(db db.DB, accounts map[string]*gtsmodel.Account) { for _, v := range NewTestTokens() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestClients() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestApplications() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestBlocks() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestDomainBlocks() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestInstances() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestUsers() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } if accounts == nil { for _, v := range NewTestAccounts() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } } else { for _, v := range accounts { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } } for _, v := range NewTestAttachments() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestStatuses() { if err := db.PutStatus(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestEmojis() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestTags() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestMentions() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestFaves() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestFollows() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } for _, v := range NewTestNotifications() { if err := db.Put(ctx, v); err != nil { - logrus.Panic(err) + log.Panic(err) } } if err := db.CreateInstanceAccount(ctx); err != nil { - logrus.Panic(err) + log.Panic(err) } if err := db.CreateInstanceInstance(ctx); err != nil { - logrus.Panic(err) + log.Panic(err) } - logrus.Debug("testing db setup complete") + log.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") + log.Panic("db teardown: db was nil") } for _, m := range testModels { if err := db.DropTable(ctx, m); err != nil { - logrus.Panic(err) + log.Panic(err) } } } diff --git a/testrig/log.go b/testrig/log.go index 1dbba83b5..48e335297 100644 --- a/testrig/log.go +++ b/testrig/log.go @@ -19,6 +19,7 @@ package testrig import ( + "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/log" "gopkg.in/mcuadros/go-syslog.v2" "gopkg.in/mcuadros/go-syslog.v2/format" @@ -26,8 +27,19 @@ import ( // InitTestLog sets the global logger to trace level for logging func InitTestLog() { - if err := log.Initialize(); err != nil { - panic(err) + // Set the global log level from configuration + if err := log.ParseLevel(config.GetLogLevel()); err != nil { + log.Panicf("error parsing log level: %v", err) + } + + if config.GetSyslogEnabled() { + // Enable logging to syslog + if err := log.EnableSyslog( + config.GetSyslogProtocol(), + config.GetSyslogAddress(), + ); err != nil { + log.Panicf("error enabling syslogging: %v", err) + } } } diff --git a/testrig/transportcontroller.go b/testrig/transportcontroller.go index 48463c1df..6edf2b52e 100644 --- a/testrig/transportcontroller.go +++ b/testrig/transportcontroller.go @@ -25,7 +25,6 @@ import ( "net/http" "strings" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/activity/pub" "github.com/superseriousbusiness/activity/streams" "github.com/superseriousbusiness/activity/streams/vocab" @@ -33,12 +32,15 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/concurrency" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/federation" + "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/messages" "github.com/superseriousbusiness/gotosocial/internal/transport" ) -const applicationJSON = "application/json" -const applicationActivityJSON = "application/activity+json" +const ( + applicationJSON = "application/json" + applicationActivityJSON = "application/activity+json" +) // NewTestTransportController returns a test transport controller with the given http client. // @@ -171,7 +173,7 @@ func NewMockHTTPClient(do func(req *http.Request) (*http.Response, error), relat responseContentLength = len(attachment.Data) } - logrus.Debugf("returning response %s", string(responseBytes)) + log.Debugf("returning response %s", string(responseBytes)) reader := bytes.NewReader(responseBytes) readCloser := io.NopCloser(reader) return &http.Response{ @@ -264,7 +266,7 @@ func WebfingerResponse(req *http.Request) (responseCode int, responseBytes []byt } if wfr == nil { - logrus.Debugf("webfinger response not available for %s", req.URL) + log.Debugf("webfinger response not available for %s", req.URL) responseCode = http.StatusNotFound responseBytes = []byte(`{"error":"not found"}`) responseContentType = applicationJSON |