user_test.go (4430B)
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 users_test 19 20 import ( 21 "github.com/gin-gonic/gin" 22 "github.com/stretchr/testify/suite" 23 "github.com/superseriousbusiness/gotosocial/internal/api/activitypub/users" 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/middleware" 30 "github.com/superseriousbusiness/gotosocial/internal/processing" 31 "github.com/superseriousbusiness/gotosocial/internal/state" 32 "github.com/superseriousbusiness/gotosocial/internal/storage" 33 "github.com/superseriousbusiness/gotosocial/internal/typeutils" 34 "github.com/superseriousbusiness/gotosocial/internal/visibility" 35 "github.com/superseriousbusiness/gotosocial/testrig" 36 ) 37 38 type UserStandardTestSuite struct { 39 // standard suite interfaces 40 suite.Suite 41 db db.DB 42 tc typeutils.TypeConverter 43 mediaManager *media.Manager 44 federator federation.Federator 45 emailSender email.Sender 46 processor *processing.Processor 47 storage *storage.Driver 48 state state.State 49 50 // standard suite models 51 testTokens map[string]*gtsmodel.Token 52 testClients map[string]*gtsmodel.Client 53 testApplications map[string]*gtsmodel.Application 54 testUsers map[string]*gtsmodel.User 55 testAccounts map[string]*gtsmodel.Account 56 testAttachments map[string]*gtsmodel.MediaAttachment 57 testStatuses map[string]*gtsmodel.Status 58 testBlocks map[string]*gtsmodel.Block 59 testActivities map[string]testrig.ActivityWithSignature 60 61 // module being tested 62 userModule *users.Module 63 64 signatureCheck gin.HandlerFunc 65 } 66 67 func (suite *UserStandardTestSuite) SetupSuite() { 68 suite.testTokens = testrig.NewTestTokens() 69 suite.testClients = testrig.NewTestClients() 70 suite.testApplications = testrig.NewTestApplications() 71 suite.testUsers = testrig.NewTestUsers() 72 suite.testAccounts = testrig.NewTestAccounts() 73 suite.testAttachments = testrig.NewTestAttachments() 74 suite.testStatuses = testrig.NewTestStatuses() 75 suite.testBlocks = testrig.NewTestBlocks() 76 suite.testActivities = testrig.NewTestActivities(suite.testAccounts) 77 } 78 79 func (suite *UserStandardTestSuite) SetupTest() { 80 suite.state.Caches.Init() 81 testrig.StartWorkers(&suite.state) 82 83 testrig.InitTestConfig() 84 testrig.InitTestLog() 85 86 suite.db = testrig.NewTestDB(&suite.state) 87 suite.state.DB = suite.db 88 suite.tc = testrig.NewTestTypeConverter(suite.db) 89 90 testrig.StartTimelines( 91 &suite.state, 92 visibility.NewFilter(&suite.state), 93 suite.tc, 94 ) 95 96 suite.storage = testrig.NewInMemoryStorage() 97 suite.state.Storage = suite.storage 98 suite.mediaManager = testrig.NewTestMediaManager(&suite.state) 99 suite.federator = testrig.NewTestFederator(&suite.state, testrig.NewTestTransportController(&suite.state, testrig.NewMockHTTPClient(nil, "../../../../testrig/media")), suite.mediaManager) 100 suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil) 101 suite.processor = testrig.NewTestProcessor(&suite.state, suite.federator, suite.emailSender, suite.mediaManager) 102 suite.userModule = users.New(suite.processor) 103 testrig.StandardDBSetup(suite.db, suite.testAccounts) 104 testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") 105 106 suite.signatureCheck = middleware.SignatureCheck(suite.db.IsURIBlocked) 107 } 108 109 func (suite *UserStandardTestSuite) TearDownTest() { 110 testrig.StandardDBTeardown(suite.db) 111 testrig.StandardStorageTeardown(suite.storage) 112 testrig.StopWorkers(&suite.state) 113 }