test suites should also directly use the global logrus logger

This commit is contained in:
R. Aidan Campbell 2021-10-10 14:55:24 -07:00
commit 9ab16632de
No known key found for this signature in database
GPG key ID: 0985399E9CD6A99B
31 changed files with 39 additions and 72 deletions

View file

@ -42,7 +42,7 @@ func runAction(c *cli.Context, a cliactions.GTSAction) error {
}
// create a logger with the log level, formatting, and output splitter already set
err = log.New(conf.LogLevel)
err = log.Initialize(conf.LogLevel)
if err != nil {
return fmt.Errorf("error creating logger: %s", err)
}

View file

@ -8,7 +8,6 @@ import (
"git.iim.gay/grufwub/go-store/kv"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/account"
"github.com/superseriousbusiness/gotosocial/internal/config"
@ -26,7 +25,6 @@ type AccountStandardTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
tc typeutils.TypeConverter
storage *kv.KVStore
federator federation.Federator
@ -59,7 +57,7 @@ func (suite *AccountStandardTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)
suite.accountModule = account.New(suite.config, suite.processor).(*account.Module)

View file

@ -48,7 +48,6 @@ type ServeFileTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
storage *kv.KVStore
federator federation.Federator
tc typeutils.TypeConverter
@ -76,7 +75,7 @@ func (suite *ServeFileTestSuite) SetupSuite() {
// setup standard items
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.storage = testrig.NewTestStorage()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)

View file

@ -51,7 +51,6 @@ type MediaCreateTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
storage *kv.KVStore
federator federation.Federator
tc typeutils.TypeConverter
@ -79,7 +78,7 @@ func (suite *MediaCreateTestSuite) SetupSuite() {
// setup standard items
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.storage = testrig.NewTestStorage()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage)

View file

@ -20,7 +20,6 @@ package status_test
import (
"git.iim.gay/grufwub/go-store/kv"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/status"
"github.com/superseriousbusiness/gotosocial/internal/config"
@ -37,7 +36,6 @@ type StatusStandardTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
tc typeutils.TypeConverter
federator federation.Federator
processor processing.Processor

View file

@ -51,7 +51,7 @@ func (suite *StatusBoostTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)
suite.statusModule = status.New(suite.config, suite.processor).(*status.Module)

View file

@ -57,7 +57,7 @@ func (suite *StatusCreateTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)

View file

@ -54,7 +54,7 @@ func (suite *StatusFaveTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)
suite.statusModule = status.New(suite.config, suite.processor).(*status.Module)

View file

@ -54,7 +54,7 @@ func (suite *StatusFavedByTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)
suite.statusModule = status.New(suite.config, suite.processor).(*status.Module)

View file

@ -44,7 +44,7 @@ func (suite *StatusGetTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)
suite.statusModule = status.New(suite.config, suite.processor).(*status.Module)

View file

@ -54,7 +54,7 @@ func (suite *StatusUnfaveTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)
suite.statusModule = status.New(suite.config, suite.processor).(*status.Module)

View file

@ -20,7 +20,6 @@ package user_test
import (
"git.iim.gay/grufwub/go-store/kv"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/user"
"github.com/superseriousbusiness/gotosocial/internal/api/security"
@ -38,7 +37,6 @@ type UserStandardTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
tc typeutils.TypeConverter
federator federation.Federator
processor processing.Processor
@ -75,7 +73,7 @@ func (suite *UserStandardTestSuite) SetupTest() {
suite.db = testrig.NewTestDB()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.storage = testrig.NewTestStorage()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)
suite.userModule = user.New(suite.config, suite.processor).(*user.Module)

View file

@ -24,7 +24,6 @@ import (
"time"
"git.iim.gay/grufwub/go-store/kv"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/webfinger"
@ -43,7 +42,6 @@ type WebfingerStandardTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
tc typeutils.TypeConverter
federator federation.Federator
processor processing.Processor
@ -78,7 +76,7 @@ func (suite *WebfingerStandardTestSuite) SetupTest() {
suite.db = testrig.NewTestDB()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.storage = testrig.NewTestStorage()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)
suite.webfingerModule = webfinger.New(suite.config, suite.processor).(*webfinger.Module)

View file

@ -19,7 +19,6 @@
package bundb_test
import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -32,7 +31,6 @@ type BunDBStandardTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
// standard suite models
testTokens map[string]*gtsmodel.Token
@ -61,7 +59,7 @@ func (suite *BunDBStandardTestSuite) SetupSuite() {
func (suite *BunDBStandardTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
testrig.StandardDBSetup(suite.db, suite.testAccounts)
}

View file

@ -41,7 +41,6 @@ type DereferencerStandardTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
storage *kv.KVStore
testRemoteStatuses map[string]vocab.ActivityStreamsNote
@ -64,7 +63,7 @@ func (suite *DereferencerStandardTestSuite) SetupSuite() {
func (suite *DereferencerStandardTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.storage = testrig.NewTestStorage()
suite.dereferencer = dereferencing.NewDereferencer(suite.config, suite.db, testrig.NewTestTypeConverter(suite.db), suite.mockTransportController(), testrig.NewTestMediaHandler(suite.db, suite.storage))
testrig.StandardDBSetup(suite.db, nil)
@ -80,7 +79,7 @@ func (suite *DereferencerStandardTestSuite) TearDownTest() {
// or note or attachment that we have stored, then just a 200 code will be returned, with an empty body.
func (suite *DereferencerStandardTestSuite) mockTransportController() transport.Controller {
do := func(req *http.Request) (*http.Response, error) {
suite.log.Debugf("received request for %s", req.URL)
logrus.Debugf("received request for %s", req.URL)
responseBytes := []byte{}
responseType := ""
@ -135,7 +134,7 @@ func (suite *DereferencerStandardTestSuite) mockTransportController() transport.
if len(responseBytes) != 0 {
// we found something, so print what we're going to return
suite.log.Debugf("returning response %s", string(responseBytes))
logrus.Debugf("returning response %s", string(responseBytes))
}
responseLength = len(responseBytes)

View file

@ -21,7 +21,6 @@ package federatingdb_test
import (
"context"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -37,7 +36,6 @@ type FederatingDBTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
tc typeutils.TypeConverter
federatingDB federatingdb.DB
@ -68,7 +66,7 @@ func (suite *FederatingDBTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.federatingDB = testrig.NewTestFederatingDB(suite.db)
testrig.StandardDBSetup(suite.db, suite.testAccounts)
}

View file

@ -27,7 +27,6 @@ import (
"git.iim.gay/grufwub/go-store/kv"
"github.com/go-fed/activity/pub"
"github.com/go-fed/httpsig"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
@ -44,7 +43,6 @@ type ProtocolTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
storage *kv.KVStore
typeConverter typeutils.TypeConverter
accounts map[string]*gtsmodel.Account
@ -56,7 +54,7 @@ func (suite *ProtocolTestSuite) SetupSuite() {
// setup standard items
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.storage = testrig.NewTestStorage()
suite.typeConverter = testrig.NewTestTypeConverter(suite.db)
suite.accounts = testrig.NewTestAccounts()

View file

@ -25,10 +25,10 @@ import (
"github.com/sirupsen/logrus"
)
// New initializes the global Logrus logger to the specified level
// Initialize initializes the global Logrus logger to the specified level
// It also sets the output to log.outputSplitter,
// so you get error logs on stderr and normal logs on stdout.
func New(level string) error {
func Initialize(level string) error {
logrus.SetOutput(&outputSplitter{})
logLevel, err := logrus.ParseLevel(level)

View file

@ -19,16 +19,15 @@
package media
import (
"github.com/superseriousbusiness/gotosocial/internal/log"
"io/ioutil"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
)
type MediaUtilTestSuite struct {
suite.Suite
log *logrus.Logger
}
/*
@ -37,10 +36,12 @@ type MediaUtilTestSuite struct {
// SetupSuite sets some variables on the suite that we can use as consts (more or less) throughout
func (suite *MediaUtilTestSuite) SetupSuite() {
// some of our subsequent entities need a log so create this here
log := logrus.New()
log.SetLevel(logrus.TraceLevel)
suite.log = log
// doesn't use testrig.InitTestLog() helper to prevent import cycle
err := log.Initialize("trace")
if err != nil {
panic(err)
}
}
func (suite *MediaUtilTestSuite) TearDownSuite() {

View file

@ -21,7 +21,6 @@ package account_test
import (
"git.iim.gay/grufwub/go-store/kv"
"github.com/go-fed/activity/pub"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -41,7 +40,6 @@ type AccountStandardTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
tc typeutils.TypeConverter
storage *kv.KVStore
mediaHandler media.Handler
@ -77,7 +75,7 @@ func (suite *AccountStandardTestSuite) SetupSuite() {
func (suite *AccountStandardTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.storage = testrig.NewTestStorage()
suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage)

View file

@ -28,7 +28,6 @@ import (
"git.iim.gay/grufwub/go-store/kv"
"github.com/go-fed/activity/streams"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -48,7 +47,6 @@ type ProcessingStandardTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
storage *kv.KVStore
typeconverter typeutils.TypeConverter
transportController transport.Controller
@ -100,7 +98,7 @@ func (suite *ProcessingStandardTestSuite) SetupSuite() {
func (suite *ProcessingStandardTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.storage = testrig.NewTestStorage()
suite.typeconverter = testrig.NewTestTypeConverter(suite.db)

View file

@ -19,7 +19,6 @@
package status_test
import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -34,7 +33,6 @@ type StatusStandardTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
typeConverter typeutils.TypeConverter
fromClientAPIChan chan messages.FromClientAPI

View file

@ -67,7 +67,7 @@ func (suite *UtilTestSuite) SetupSuite() {
func (suite *UtilTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.typeConverter = testrig.NewTestTypeConverter(suite.db)
suite.fromClientAPIChan = make(chan messages.FromClientAPI, 100)
suite.status = status.New(suite.db, suite.typeConverter, suite.config, suite.fromClientAPIChan)

View file

@ -19,7 +19,6 @@
package streaming_test
import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
@ -34,7 +33,6 @@ type StreamingTestSuite struct {
testTokens map[string]*gtsmodel.Token
db db.DB
oauthServer oauth.Server
log *logrus.Logger
streamingProcessor streaming.Processor
}
@ -44,7 +42,7 @@ func (suite *StreamingTestSuite) SetupTest() {
suite.testTokens = testrig.NewTestTokens()
suite.db = testrig.NewTestDB()
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.streamingProcessor = streaming.New(suite.db, suite.oauthServer)
testrig.StandardDBSetup(suite.db, suite.testAccounts)

View file

@ -40,7 +40,7 @@ func (suite *GetTestSuite) SetupSuite() {
func (suite *GetTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.tc = testrig.NewTestTypeConverter(suite.db)
testrig.StandardDBSetup(suite.db, nil)

View file

@ -41,7 +41,7 @@ func (suite *IndexTestSuite) SetupSuite() {
func (suite *IndexTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.tc = testrig.NewTestTypeConverter(suite.db)
testrig.StandardDBSetup(suite.db, nil)

View file

@ -38,7 +38,7 @@ func (suite *ManagerTestSuite) SetupSuite() {
func (suite *ManagerTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.tc = testrig.NewTestTypeConverter(suite.db)
testrig.StandardDBSetup(suite.db, nil)

View file

@ -19,7 +19,6 @@
package timeline_test
import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -32,7 +31,6 @@ type TimelineStandardTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
tc typeutils.TypeConverter
testAccounts map[string]*gtsmodel.Account

View file

@ -19,7 +19,6 @@
package trans_test
import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/testrig"
@ -28,12 +27,11 @@ import (
type TransTestSuite struct {
suite.Suite
db db.DB
log *logrus.Logger
}
func (suite *TransTestSuite) SetupTest() {
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
testrig.StandardDBSetup(suite.db, nil)
}

View file

@ -20,7 +20,6 @@ package typeutils_test
import (
"github.com/go-fed/activity/streams/vocab"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -327,7 +326,6 @@ type TypeUtilsTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
testAccounts map[string]*gtsmodel.Account
testStatuses map[string]*gtsmodel.Status
testPeople map[string]vocab.ActivityStreamsPerson
@ -338,7 +336,7 @@ type TypeUtilsTestSuite struct {
func (suite *TypeUtilsTestSuite) SetupSuite() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.testAccounts = testrig.NewTestAccounts()
suite.testStatuses = testrig.NewTestStatuses()
suite.testPeople = testrig.NewTestFediPeople()

View file

@ -20,15 +20,12 @@ package testrig
import (
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/sirupsen/logrus"
)
// NewTestLog returns a trace level logger for testing
func NewTestLog() *logrus.Logger {
err := log.New("trace")
// InitTestLog sets the global logger to trace level for logging
func InitTestLog() {
err := log.Initialize("trace")
if err != nil {
panic(err)
}
return logrus.StandardLogger()
}