2021-09-10 15:36:10 +03:00
|
|
|
/*
|
|
|
|
GoToSocial
|
2021-12-20 20:42:19 +03:00
|
|
|
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
|
2021-09-10 15:36:10 +03:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package account_test
|
|
|
|
|
|
|
|
import (
|
2022-04-28 15:23:11 +03:00
|
|
|
"context"
|
|
|
|
|
2021-11-13 14:29:08 +03:00
|
|
|
"codeberg.org/gruf/go-store/kv"
|
2021-09-10 15:36:10 +03:00
|
|
|
"github.com/stretchr/testify/suite"
|
2022-05-15 12:16:43 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/concurrency"
|
2021-09-10 15:36:10 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
2021-10-31 17:46:23 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/email"
|
2021-09-10 15:36:10 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/federation"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/media"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
2022-03-29 12:54:56 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
2021-09-10 15:36:10 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/account"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/transport"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AccountStandardTestSuite struct {
|
|
|
|
// standard suite interfaces
|
|
|
|
suite.Suite
|
|
|
|
db db.DB
|
|
|
|
tc typeutils.TypeConverter
|
2021-09-11 22:12:47 +03:00
|
|
|
storage *kv.KVStore
|
2021-12-28 18:36:00 +03:00
|
|
|
mediaManager media.Manager
|
2021-09-10 15:36:10 +03:00
|
|
|
oauthServer oauth.Server
|
|
|
|
fromClientAPIChan chan messages.FromClientAPI
|
|
|
|
transportController transport.Controller
|
|
|
|
federator federation.Federator
|
2021-10-31 17:46:23 +03:00
|
|
|
emailSender email.Sender
|
|
|
|
sentEmails map[string]string
|
2021-09-10 15:36:10 +03:00
|
|
|
|
|
|
|
// standard suite models
|
|
|
|
testTokens map[string]*gtsmodel.Token
|
|
|
|
testClients map[string]*gtsmodel.Client
|
|
|
|
testApplications map[string]*gtsmodel.Application
|
|
|
|
testUsers map[string]*gtsmodel.User
|
|
|
|
testAccounts map[string]*gtsmodel.Account
|
|
|
|
testAttachments map[string]*gtsmodel.MediaAttachment
|
|
|
|
testStatuses map[string]*gtsmodel.Status
|
|
|
|
|
|
|
|
// module being tested
|
|
|
|
accountProcessor account.Processor
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *AccountStandardTestSuite) SetupSuite() {
|
|
|
|
suite.testTokens = testrig.NewTestTokens()
|
|
|
|
suite.testClients = testrig.NewTestClients()
|
|
|
|
suite.testApplications = testrig.NewTestApplications()
|
|
|
|
suite.testUsers = testrig.NewTestUsers()
|
|
|
|
suite.testAccounts = testrig.NewTestAccounts()
|
|
|
|
suite.testAttachments = testrig.NewTestAttachments()
|
|
|
|
suite.testStatuses = testrig.NewTestStatuses()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *AccountStandardTestSuite) SetupTest() {
|
2021-10-11 15:37:33 +03:00
|
|
|
testrig.InitTestLog()
|
2021-12-07 15:31:39 +03:00
|
|
|
testrig.InitTestConfig()
|
|
|
|
|
2022-05-15 12:16:43 +03:00
|
|
|
fedWorker := concurrency.NewWorkerPool[messages.FromFederator](-1, -1)
|
|
|
|
clientWorker := concurrency.NewWorkerPool[messages.FromClientAPI](-1, -1)
|
2022-04-28 15:23:11 +03:00
|
|
|
clientWorker.SetProcessor(func(_ context.Context, msg messages.FromClientAPI) error {
|
|
|
|
suite.fromClientAPIChan <- msg
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
_ = fedWorker.Start()
|
|
|
|
_ = clientWorker.Start()
|
|
|
|
|
2021-12-07 15:31:39 +03:00
|
|
|
suite.db = testrig.NewTestDB()
|
2021-09-10 15:36:10 +03:00
|
|
|
suite.tc = testrig.NewTestTypeConverter(suite.db)
|
|
|
|
suite.storage = testrig.NewTestStorage()
|
2021-12-28 18:36:00 +03:00
|
|
|
suite.mediaManager = testrig.NewTestMediaManager(suite.db, suite.storage)
|
2021-09-10 15:36:10 +03:00
|
|
|
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
|
|
|
|
suite.fromClientAPIChan = make(chan messages.FromClientAPI, 100)
|
2022-06-11 12:01:34 +03:00
|
|
|
suite.transportController = testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil, "../../../testrig/media"), suite.db, fedWorker)
|
2022-04-28 15:23:11 +03:00
|
|
|
suite.federator = testrig.NewTestFederator(suite.db, suite.transportController, suite.storage, suite.mediaManager, fedWorker)
|
2021-10-31 17:46:23 +03:00
|
|
|
suite.sentEmails = make(map[string]string)
|
|
|
|
suite.emailSender = testrig.NewEmailSender("../../../web/template/", suite.sentEmails)
|
2022-04-28 15:23:11 +03:00
|
|
|
suite.accountProcessor = account.New(suite.db, suite.tc, suite.mediaManager, suite.oauthServer, clientWorker, suite.federator, processing.GetParseMentionFunc(suite.db, suite.federator))
|
2021-09-10 15:36:10 +03:00
|
|
|
testrig.StandardDBSetup(suite.db, nil)
|
|
|
|
testrig.StandardStorageSetup(suite.storage, "../../../testrig/media")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *AccountStandardTestSuite) TearDownTest() {
|
|
|
|
testrig.StandardDBTeardown(suite.db)
|
|
|
|
testrig.StandardStorageTeardown(suite.storage)
|
|
|
|
}
|