2023-03-12 15:00:57 +00:00
|
|
|
// GoToSocial
|
|
|
|
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2021-05-08 12:25:55 +00:00
|
|
|
|
|
|
|
package federation_test
|
|
|
|
|
|
|
|
import (
|
2023-09-12 09:43:12 +00:00
|
|
|
"context"
|
|
|
|
|
2021-05-08 12:25:55 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2023-06-13 14:47:56 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/federation"
|
2024-02-27 12:22:05 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/filter/visibility"
|
2021-05-08 12:25:55 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
2023-03-01 18:26:53 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/state"
|
2022-07-03 10:08:30 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/storage"
|
2023-06-13 14:47:56 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/transport"
|
2021-05-08 12:25:55 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
|
|
|
)
|
|
|
|
|
2022-04-29 13:05:13 +00:00
|
|
|
type FederatorStandardTestSuite struct {
|
2021-05-08 12:25:55 +00:00
|
|
|
suite.Suite
|
2023-06-13 14:47:56 +00:00
|
|
|
storage *storage.Driver
|
|
|
|
state state.State
|
2023-09-23 16:44:11 +00:00
|
|
|
typeconverter *typeutils.Converter
|
2023-06-13 14:47:56 +00:00
|
|
|
transportController transport.Controller
|
|
|
|
httpClient *testrig.MockHTTPClient
|
2023-10-23 09:58:13 +00:00
|
|
|
federator *federation.Federator
|
2023-06-13 14:47:56 +00:00
|
|
|
|
2022-04-29 13:53:04 +00:00
|
|
|
testAccounts map[string]*gtsmodel.Account
|
2022-05-23 09:46:50 +00:00
|
|
|
testStatuses map[string]*gtsmodel.Status
|
2022-04-29 13:53:04 +00:00
|
|
|
testActivities map[string]testrig.ActivityWithSignature
|
2022-11-11 11:18:38 +00:00
|
|
|
testTombstones map[string]*gtsmodel.Tombstone
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 13:05:13 +00:00
|
|
|
func (suite *FederatorStandardTestSuite) SetupSuite() {
|
2022-04-29 13:53:04 +00:00
|
|
|
suite.testAccounts = testrig.NewTestAccounts()
|
2022-05-23 09:46:50 +00:00
|
|
|
suite.testStatuses = testrig.NewTestStatuses()
|
2023-06-13 14:47:56 +00:00
|
|
|
suite.testActivities = testrig.NewTestActivities(suite.testAccounts)
|
2022-11-11 11:18:38 +00:00
|
|
|
suite.testTombstones = testrig.NewTestTombstones()
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 13:05:13 +00:00
|
|
|
func (suite *FederatorStandardTestSuite) SetupTest() {
|
2023-06-13 14:47:56 +00:00
|
|
|
suite.state.Caches.Init()
|
2023-11-14 14:57:25 +00:00
|
|
|
testrig.StartNoopWorkers(&suite.state)
|
2023-06-13 14:47:56 +00:00
|
|
|
|
2021-12-07 12:31:39 +00:00
|
|
|
testrig.InitTestConfig()
|
2022-04-29 13:05:13 +00:00
|
|
|
testrig.InitTestLog()
|
2023-06-13 14:47:56 +00:00
|
|
|
|
|
|
|
suite.state.DB = testrig.NewTestDB(&suite.state)
|
|
|
|
suite.testActivities = testrig.NewTestActivities(suite.testAccounts)
|
|
|
|
suite.storage = testrig.NewInMemoryStorage()
|
|
|
|
suite.state.Storage = suite.storage
|
2023-09-23 16:44:11 +00:00
|
|
|
suite.typeconverter = typeutils.NewConverter(&suite.state)
|
2023-05-25 08:37:38 +00:00
|
|
|
|
|
|
|
testrig.StartTimelines(
|
|
|
|
&suite.state,
|
|
|
|
visibility.NewFilter(&suite.state),
|
2023-06-13 14:47:56 +00:00
|
|
|
suite.typeconverter,
|
2023-05-25 08:37:38 +00:00
|
|
|
)
|
|
|
|
|
2023-09-12 09:43:12 +00:00
|
|
|
// Ensure it's possible to deref
|
|
|
|
// main key of foss satan.
|
|
|
|
fossSatanPerson, err := suite.typeconverter.AccountToAS(context.Background(), suite.testAccounts["remote_account_1"])
|
|
|
|
if err != nil {
|
|
|
|
suite.FailNow(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
suite.httpClient = testrig.NewMockHTTPClient(nil, "../../testrig/media", fossSatanPerson)
|
2023-06-13 14:47:56 +00:00
|
|
|
suite.httpClient.TestRemotePeople = testrig.NewTestFediPeople()
|
|
|
|
suite.httpClient.TestRemoteStatuses = testrig.NewTestFediStatuses()
|
|
|
|
|
|
|
|
suite.transportController = testrig.NewTestTransportController(&suite.state, suite.httpClient)
|
|
|
|
suite.federator = testrig.NewTestFederator(&suite.state, suite.transportController, testrig.NewTestMediaManager(&suite.state))
|
|
|
|
|
|
|
|
testrig.StandardDBSetup(suite.state.DB, nil)
|
|
|
|
testrig.StandardStorageSetup(suite.storage, "../../testrig/media")
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 13:05:13 +00:00
|
|
|
func (suite *FederatorStandardTestSuite) TearDownTest() {
|
2023-06-13 14:47:56 +00:00
|
|
|
testrig.StandardDBTeardown(suite.state.DB)
|
|
|
|
testrig.StandardStorageTeardown(suite.storage)
|
|
|
|
testrig.StopWorkers(&suite.state)
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|