reports_test.go (3935B)
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 reports_test 19 20 import ( 21 "github.com/stretchr/testify/suite" 22 "github.com/superseriousbusiness/gotosocial/internal/api/client/reports" 23 "github.com/superseriousbusiness/gotosocial/internal/db" 24 "github.com/superseriousbusiness/gotosocial/internal/email" 25 "github.com/superseriousbusiness/gotosocial/internal/federation" 26 "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 27 "github.com/superseriousbusiness/gotosocial/internal/media" 28 "github.com/superseriousbusiness/gotosocial/internal/processing" 29 "github.com/superseriousbusiness/gotosocial/internal/state" 30 "github.com/superseriousbusiness/gotosocial/internal/storage" 31 "github.com/superseriousbusiness/gotosocial/internal/visibility" 32 "github.com/superseriousbusiness/gotosocial/testrig" 33 ) 34 35 type ReportsStandardTestSuite struct { 36 suite.Suite 37 db db.DB 38 storage *storage.Driver 39 mediaManager *media.Manager 40 federator federation.Federator 41 processor *processing.Processor 42 emailSender email.Sender 43 sentEmails map[string]string 44 state state.State 45 46 // standard suite models 47 testTokens map[string]*gtsmodel.Token 48 testClients map[string]*gtsmodel.Client 49 testApplications map[string]*gtsmodel.Application 50 testUsers map[string]*gtsmodel.User 51 testAccounts map[string]*gtsmodel.Account 52 testStatuses map[string]*gtsmodel.Status 53 testReports map[string]*gtsmodel.Report 54 55 // module being tested 56 reportsModule *reports.Module 57 } 58 59 func (suite *ReportsStandardTestSuite) SetupSuite() { 60 suite.testTokens = testrig.NewTestTokens() 61 suite.testClients = testrig.NewTestClients() 62 suite.testApplications = testrig.NewTestApplications() 63 suite.testUsers = testrig.NewTestUsers() 64 suite.testAccounts = testrig.NewTestAccounts() 65 suite.testStatuses = testrig.NewTestStatuses() 66 suite.testReports = testrig.NewTestReports() 67 } 68 69 func (suite *ReportsStandardTestSuite) SetupTest() { 70 suite.state.Caches.Init() 71 testrig.StartWorkers(&suite.state) 72 73 testrig.InitTestConfig() 74 testrig.InitTestLog() 75 76 suite.db = testrig.NewTestDB(&suite.state) 77 suite.state.DB = suite.db 78 suite.storage = testrig.NewInMemoryStorage() 79 suite.state.Storage = suite.storage 80 81 testrig.StartTimelines( 82 &suite.state, 83 visibility.NewFilter(&suite.state), 84 testrig.NewTestTypeConverter(suite.db), 85 ) 86 87 suite.mediaManager = testrig.NewTestMediaManager(&suite.state) 88 suite.federator = testrig.NewTestFederator(&suite.state, testrig.NewTestTransportController(&suite.state, testrig.NewMockHTTPClient(nil, "../../../../testrig/media")), suite.mediaManager) 89 suite.sentEmails = make(map[string]string) 90 suite.emailSender = testrig.NewEmailSender("../../../../web/template/", suite.sentEmails) 91 suite.processor = testrig.NewTestProcessor(&suite.state, suite.federator, suite.emailSender, suite.mediaManager) 92 suite.reportsModule = reports.New(suite.processor) 93 testrig.StandardDBSetup(suite.db, nil) 94 testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") 95 } 96 97 func (suite *ReportsStandardTestSuite) TearDownTest() { 98 testrig.StandardDBTeardown(suite.db) 99 testrig.StandardStorageTeardown(suite.storage) 100 testrig.StopWorkers(&suite.state) 101 }