fileserver_test.go (4452B)
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 fileserver_test 19 20 import ( 21 "context" 22 23 "github.com/stretchr/testify/suite" 24 "github.com/superseriousbusiness/gotosocial/internal/api/fileserver" 25 "github.com/superseriousbusiness/gotosocial/internal/db" 26 "github.com/superseriousbusiness/gotosocial/internal/email" 27 "github.com/superseriousbusiness/gotosocial/internal/federation" 28 "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 29 "github.com/superseriousbusiness/gotosocial/internal/log" 30 "github.com/superseriousbusiness/gotosocial/internal/media" 31 "github.com/superseriousbusiness/gotosocial/internal/oauth" 32 "github.com/superseriousbusiness/gotosocial/internal/processing" 33 "github.com/superseriousbusiness/gotosocial/internal/state" 34 "github.com/superseriousbusiness/gotosocial/internal/storage" 35 "github.com/superseriousbusiness/gotosocial/internal/typeutils" 36 "github.com/superseriousbusiness/gotosocial/internal/visibility" 37 "github.com/superseriousbusiness/gotosocial/testrig" 38 ) 39 40 type FileserverTestSuite struct { 41 // standard suite interfaces 42 suite.Suite 43 db db.DB 44 storage *storage.Driver 45 state state.State 46 federator federation.Federator 47 tc typeutils.TypeConverter 48 processor *processing.Processor 49 mediaManager *media.Manager 50 oauthServer oauth.Server 51 emailSender email.Sender 52 53 // standard suite models 54 testTokens map[string]*gtsmodel.Token 55 testClients map[string]*gtsmodel.Client 56 testApplications map[string]*gtsmodel.Application 57 testUsers map[string]*gtsmodel.User 58 testAccounts map[string]*gtsmodel.Account 59 testAttachments map[string]*gtsmodel.MediaAttachment 60 61 // item being tested 62 fileServer *fileserver.Module 63 } 64 65 /* 66 TEST INFRASTRUCTURE 67 */ 68 69 func (suite *FileserverTestSuite) SetupSuite() { 70 testrig.StartWorkers(&suite.state) 71 72 testrig.InitTestConfig() 73 testrig.InitTestLog() 74 75 suite.db = testrig.NewTestDB(&suite.state) 76 suite.state.DB = suite.db 77 suite.storage = testrig.NewInMemoryStorage() 78 suite.state.Storage = suite.storage 79 80 suite.mediaManager = testrig.NewTestMediaManager(&suite.state) 81 suite.federator = testrig.NewTestFederator(&suite.state, testrig.NewTestTransportController(&suite.state, testrig.NewMockHTTPClient(nil, "../../../testrig/media")), suite.mediaManager) 82 suite.processor = testrig.NewTestProcessor(&suite.state, suite.federator, suite.emailSender, suite.mediaManager) 83 84 suite.tc = testrig.NewTestTypeConverter(suite.db) 85 86 testrig.StartTimelines( 87 &suite.state, 88 visibility.NewFilter(&suite.state), 89 suite.tc, 90 ) 91 92 suite.mediaManager = testrig.NewTestMediaManager(&suite.state) 93 suite.oauthServer = testrig.NewTestOauthServer(suite.db) 94 suite.emailSender = testrig.NewEmailSender("../../../web/template/", nil) 95 96 suite.fileServer = fileserver.New(suite.processor) 97 } 98 99 func (suite *FileserverTestSuite) SetupTest() { 100 suite.state.Caches.Init() 101 testrig.StartWorkers(&suite.state) 102 103 testrig.StandardDBSetup(suite.db, nil) 104 testrig.StandardStorageSetup(suite.storage, "../../../testrig/media") 105 suite.testTokens = testrig.NewTestTokens() 106 suite.testClients = testrig.NewTestClients() 107 suite.testApplications = testrig.NewTestApplications() 108 suite.testUsers = testrig.NewTestUsers() 109 suite.testAccounts = testrig.NewTestAccounts() 110 suite.testAttachments = testrig.NewTestAttachments() 111 } 112 113 func (suite *FileserverTestSuite) TearDownSuite() { 114 if err := suite.db.Stop(context.Background()); err != nil { 115 log.Panicf(nil, "error closing db connection: %s", err) 116 } 117 testrig.StopWorkers(&suite.state) 118 } 119 120 func (suite *FileserverTestSuite) TearDownTest() { 121 testrig.StandardDBTeardown(suite.db) 122 testrig.StandardStorageTeardown(suite.storage) 123 testrig.StopWorkers(&suite.state) 124 }