account_test.go (4958B)
1 // GoToSocial 2 // Copyright (C) GoToSocial Authors admin@gotosocial.org 3 // SPDX-License-Identifier: AGPL-3.0-or-later 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package account_test 19 20 import ( 21 "context" 22 23 "github.com/stretchr/testify/suite" 24 "github.com/superseriousbusiness/gotosocial/internal/db" 25 "github.com/superseriousbusiness/gotosocial/internal/email" 26 "github.com/superseriousbusiness/gotosocial/internal/federation" 27 "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 28 "github.com/superseriousbusiness/gotosocial/internal/media" 29 "github.com/superseriousbusiness/gotosocial/internal/messages" 30 "github.com/superseriousbusiness/gotosocial/internal/oauth" 31 "github.com/superseriousbusiness/gotosocial/internal/processing" 32 "github.com/superseriousbusiness/gotosocial/internal/processing/account" 33 "github.com/superseriousbusiness/gotosocial/internal/state" 34 "github.com/superseriousbusiness/gotosocial/internal/storage" 35 "github.com/superseriousbusiness/gotosocial/internal/transport" 36 "github.com/superseriousbusiness/gotosocial/internal/typeutils" 37 "github.com/superseriousbusiness/gotosocial/internal/visibility" 38 "github.com/superseriousbusiness/gotosocial/testrig" 39 ) 40 41 type AccountStandardTestSuite struct { 42 // standard suite interfaces 43 suite.Suite 44 db db.DB 45 tc typeutils.TypeConverter 46 storage *storage.Driver 47 state state.State 48 mediaManager *media.Manager 49 oauthServer oauth.Server 50 fromClientAPIChan chan messages.FromClientAPI 51 transportController transport.Controller 52 federator federation.Federator 53 emailSender email.Sender 54 sentEmails map[string]string 55 56 // standard suite models 57 testTokens map[string]*gtsmodel.Token 58 testClients map[string]*gtsmodel.Client 59 testApplications map[string]*gtsmodel.Application 60 testUsers map[string]*gtsmodel.User 61 testAccounts map[string]*gtsmodel.Account 62 testFollows map[string]*gtsmodel.Follow 63 testAttachments map[string]*gtsmodel.MediaAttachment 64 testStatuses map[string]*gtsmodel.Status 65 66 // module being tested 67 accountProcessor account.Processor 68 } 69 70 func (suite *AccountStandardTestSuite) SetupSuite() { 71 suite.testTokens = testrig.NewTestTokens() 72 suite.testClients = testrig.NewTestClients() 73 suite.testApplications = testrig.NewTestApplications() 74 suite.testUsers = testrig.NewTestUsers() 75 suite.testAccounts = testrig.NewTestAccounts() 76 suite.testFollows = testrig.NewTestFollows() 77 suite.testAttachments = testrig.NewTestAttachments() 78 suite.testStatuses = testrig.NewTestStatuses() 79 } 80 81 func (suite *AccountStandardTestSuite) SetupTest() { 82 suite.state.Caches.Init() 83 testrig.StartWorkers(&suite.state) 84 85 testrig.InitTestConfig() 86 testrig.InitTestLog() 87 88 suite.db = testrig.NewTestDB(&suite.state) 89 suite.state.DB = suite.db 90 suite.tc = testrig.NewTestTypeConverter(suite.db) 91 92 testrig.StartTimelines( 93 &suite.state, 94 visibility.NewFilter(&suite.state), 95 suite.tc, 96 ) 97 98 suite.storage = testrig.NewInMemoryStorage() 99 suite.state.Storage = suite.storage 100 suite.mediaManager = testrig.NewTestMediaManager(&suite.state) 101 suite.oauthServer = testrig.NewTestOauthServer(suite.db) 102 103 suite.fromClientAPIChan = make(chan messages.FromClientAPI, 100) 104 suite.state.Workers.EnqueueClientAPI = func(ctx context.Context, msgs ...messages.FromClientAPI) { 105 for _, msg := range msgs { 106 suite.fromClientAPIChan <- msg 107 } 108 } 109 110 suite.transportController = testrig.NewTestTransportController(&suite.state, testrig.NewMockHTTPClient(nil, "../../../testrig/media")) 111 suite.federator = testrig.NewTestFederator(&suite.state, suite.transportController, suite.mediaManager) 112 suite.sentEmails = make(map[string]string) 113 suite.emailSender = testrig.NewEmailSender("../../../web/template/", suite.sentEmails) 114 115 filter := visibility.NewFilter(&suite.state) 116 suite.accountProcessor = account.New(&suite.state, suite.tc, suite.mediaManager, suite.oauthServer, suite.federator, filter, processing.GetParseMentionFunc(suite.db, suite.federator)) 117 testrig.StandardDBSetup(suite.db, nil) 118 testrig.StandardStorageSetup(suite.storage, "../../../testrig/media") 119 } 120 121 func (suite *AccountStandardTestSuite) TearDownTest() { 122 testrig.StandardDBTeardown(suite.db) 123 testrig.StandardStorageTeardown(suite.storage) 124 testrig.StopWorkers(&suite.state) 125 }