gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

federator_test.go (3424B)


      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 federation_test
     19 
     20 import (
     21 	"github.com/stretchr/testify/suite"
     22 
     23 	"github.com/superseriousbusiness/gotosocial/internal/federation"
     24 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     25 	"github.com/superseriousbusiness/gotosocial/internal/state"
     26 	"github.com/superseriousbusiness/gotosocial/internal/storage"
     27 	"github.com/superseriousbusiness/gotosocial/internal/transport"
     28 	"github.com/superseriousbusiness/gotosocial/internal/typeutils"
     29 	"github.com/superseriousbusiness/gotosocial/internal/visibility"
     30 	"github.com/superseriousbusiness/gotosocial/testrig"
     31 )
     32 
     33 type FederatorStandardTestSuite struct {
     34 	suite.Suite
     35 	storage             *storage.Driver
     36 	state               state.State
     37 	typeconverter       typeutils.TypeConverter
     38 	transportController transport.Controller
     39 	httpClient          *testrig.MockHTTPClient
     40 	federator           federation.Federator
     41 
     42 	testAccounts   map[string]*gtsmodel.Account
     43 	testStatuses   map[string]*gtsmodel.Status
     44 	testActivities map[string]testrig.ActivityWithSignature
     45 	testTombstones map[string]*gtsmodel.Tombstone
     46 }
     47 
     48 func (suite *FederatorStandardTestSuite) SetupSuite() {
     49 	suite.testAccounts = testrig.NewTestAccounts()
     50 	suite.testStatuses = testrig.NewTestStatuses()
     51 	suite.testActivities = testrig.NewTestActivities(suite.testAccounts)
     52 	suite.testTombstones = testrig.NewTestTombstones()
     53 }
     54 
     55 func (suite *FederatorStandardTestSuite) SetupTest() {
     56 	suite.state.Caches.Init()
     57 	testrig.StartWorkers(&suite.state)
     58 
     59 	testrig.InitTestConfig()
     60 	testrig.InitTestLog()
     61 
     62 	suite.state.DB = testrig.NewTestDB(&suite.state)
     63 	suite.testActivities = testrig.NewTestActivities(suite.testAccounts)
     64 	suite.storage = testrig.NewInMemoryStorage()
     65 	suite.state.Storage = suite.storage
     66 	suite.typeconverter = testrig.NewTestTypeConverter(suite.state.DB)
     67 
     68 	testrig.StartTimelines(
     69 		&suite.state,
     70 		visibility.NewFilter(&suite.state),
     71 		suite.typeconverter,
     72 	)
     73 
     74 	suite.httpClient = testrig.NewMockHTTPClient(nil, "../../testrig/media")
     75 	suite.httpClient.TestRemotePeople = testrig.NewTestFediPeople()
     76 	suite.httpClient.TestRemoteStatuses = testrig.NewTestFediStatuses()
     77 
     78 	suite.transportController = testrig.NewTestTransportController(&suite.state, suite.httpClient)
     79 	suite.federator = testrig.NewTestFederator(&suite.state, suite.transportController, testrig.NewTestMediaManager(&suite.state))
     80 
     81 	testrig.StandardDBSetup(suite.state.DB, nil)
     82 	testrig.StandardStorageSetup(suite.storage, "../../testrig/media")
     83 }
     84 
     85 func (suite *FederatorStandardTestSuite) TearDownTest() {
     86 	testrig.StandardDBTeardown(suite.state.DB)
     87 	testrig.StandardStorageTeardown(suite.storage)
     88 	testrig.StopWorkers(&suite.state)
     89 }