2021-09-10 12:36:10 +00:00
|
|
|
/*
|
|
|
|
GoToSocial
|
2021-12-20 17:42:19 +00:00
|
|
|
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
|
2021-09-10 12:36:10 +00: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 12:23:11 +00:00
|
|
|
"context"
|
|
|
|
|
2021-11-13 11:29:08 +00:00
|
|
|
"codeberg.org/gruf/go-store/kv"
|
2021-09-10 12:36:10 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
2021-11-13 16:29:43 +00:00
|
|
|
"github.com/superseriousbusiness/activity/pub"
|
2021-09-10 12:36:10 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
2021-10-31 14:46:23 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/email"
|
2021-09-10 12:36:10 +00: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 09:54:56 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
2021-09-10 12:36:10 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/account"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/transport"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
2022-04-28 12:23:11 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/worker"
|
2021-09-10 12:36:10 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AccountStandardTestSuite struct {
|
|
|
|
// standard suite interfaces
|
|
|
|
suite.Suite
|
|
|
|
db db.DB
|
|
|
|
tc typeutils.TypeConverter
|
2021-09-11 19:12:47 +00:00
|
|
|
storage *kv.KVStore
|
2021-12-28 15:36:00 +00:00
|
|
|
mediaManager media.Manager
|
2021-09-10 12:36:10 +00:00
|
|
|
oauthServer oauth.Server
|
|
|
|
fromClientAPIChan chan messages.FromClientAPI
|
|
|
|
httpClient pub.HttpClient
|
|
|
|
transportController transport.Controller
|
|
|
|
federator federation.Federator
|
2021-10-31 14:46:23 +00:00
|
|
|
emailSender email.Sender
|
|
|
|
sentEmails map[string]string
|
2021-09-10 12:36:10 +00: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 12:37:33 +00:00
|
|
|
testrig.InitTestLog()
|
2021-12-07 12:31:39 +00:00
|
|
|
testrig.InitTestConfig()
|
|
|
|
|
2022-04-28 12:23:11 +00:00
|
|
|
fedWorker := worker.New[messages.FromFederator](-1, -1)
|
|
|
|
clientWorker := worker.New[messages.FromClientAPI](-1, -1)
|
|
|
|
clientWorker.SetProcessor(func(_ context.Context, msg messages.FromClientAPI) error {
|
|
|
|
suite.fromClientAPIChan <- msg
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
_ = fedWorker.Start()
|
|
|
|
_ = clientWorker.Start()
|
|
|
|
|
2021-12-07 12:31:39 +00:00
|
|
|
suite.db = testrig.NewTestDB()
|
2021-09-10 12:36:10 +00:00
|
|
|
suite.tc = testrig.NewTestTypeConverter(suite.db)
|
|
|
|
suite.storage = testrig.NewTestStorage()
|
2021-12-28 15:36:00 +00:00
|
|
|
suite.mediaManager = testrig.NewTestMediaManager(suite.db, suite.storage)
|
2021-09-10 12:36:10 +00:00
|
|
|
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
|
|
|
|
suite.fromClientAPIChan = make(chan messages.FromClientAPI, 100)
|
|
|
|
suite.httpClient = testrig.NewMockHTTPClient(nil)
|
2022-04-28 12:23:11 +00:00
|
|
|
suite.transportController = testrig.NewTestTransportController(suite.httpClient, suite.db, fedWorker)
|
|
|
|
suite.federator = testrig.NewTestFederator(suite.db, suite.transportController, suite.storage, suite.mediaManager, fedWorker)
|
2021-10-31 14:46:23 +00:00
|
|
|
suite.sentEmails = make(map[string]string)
|
|
|
|
suite.emailSender = testrig.NewEmailSender("../../../web/template/", suite.sentEmails)
|
2022-04-28 12:23:11 +00: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 12:36:10 +00:00
|
|
|
testrig.StandardDBSetup(suite.db, nil)
|
|
|
|
testrig.StandardStorageSetup(suite.storage, "../../../testrig/media")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *AccountStandardTestSuite) TearDownTest() {
|
|
|
|
testrig.StandardDBTeardown(suite.db)
|
|
|
|
testrig.StandardStorageTeardown(suite.storage)
|
|
|
|
}
|