gtsocial-umbx

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

processor_test.go (6309B)


      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 processing_test
     19 
     20 import (
     21 	"context"
     22 
     23 	"github.com/stretchr/testify/suite"
     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/oauth"
     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/stream"
     34 	"github.com/superseriousbusiness/gotosocial/internal/transport"
     35 	"github.com/superseriousbusiness/gotosocial/internal/typeutils"
     36 	"github.com/superseriousbusiness/gotosocial/internal/visibility"
     37 	"github.com/superseriousbusiness/gotosocial/testrig"
     38 )
     39 
     40 type ProcessingStandardTestSuite struct {
     41 	// standard suite interfaces
     42 	suite.Suite
     43 	db                  db.DB
     44 	storage             *storage.Driver
     45 	state               state.State
     46 	mediaManager        *media.Manager
     47 	typeconverter       typeutils.TypeConverter
     48 	httpClient          *testrig.MockHTTPClient
     49 	transportController transport.Controller
     50 	federator           federation.Federator
     51 	oauthServer         oauth.Server
     52 	emailSender         email.Sender
     53 
     54 	// standard suite models
     55 	testTokens       map[string]*gtsmodel.Token
     56 	testClients      map[string]*gtsmodel.Client
     57 	testApplications map[string]*gtsmodel.Application
     58 	testUsers        map[string]*gtsmodel.User
     59 	testAccounts     map[string]*gtsmodel.Account
     60 	testFollows      map[string]*gtsmodel.Follow
     61 	testAttachments  map[string]*gtsmodel.MediaAttachment
     62 	testStatuses     map[string]*gtsmodel.Status
     63 	testTags         map[string]*gtsmodel.Tag
     64 	testMentions     map[string]*gtsmodel.Mention
     65 	testAutheds      map[string]*oauth.Auth
     66 	testBlocks       map[string]*gtsmodel.Block
     67 	testActivities   map[string]testrig.ActivityWithSignature
     68 	testLists        map[string]*gtsmodel.List
     69 
     70 	processor *processing.Processor
     71 }
     72 
     73 func (suite *ProcessingStandardTestSuite) SetupSuite() {
     74 	suite.testTokens = testrig.NewTestTokens()
     75 	suite.testClients = testrig.NewTestClients()
     76 	suite.testApplications = testrig.NewTestApplications()
     77 	suite.testUsers = testrig.NewTestUsers()
     78 	suite.testAccounts = testrig.NewTestAccounts()
     79 	suite.testFollows = testrig.NewTestFollows()
     80 	suite.testAttachments = testrig.NewTestAttachments()
     81 	suite.testStatuses = testrig.NewTestStatuses()
     82 	suite.testTags = testrig.NewTestTags()
     83 	suite.testMentions = testrig.NewTestMentions()
     84 	suite.testAutheds = map[string]*oauth.Auth{
     85 		"local_account_1": {
     86 			Application: suite.testApplications["local_account_1"],
     87 			User:        suite.testUsers["local_account_1"],
     88 			Account:     suite.testAccounts["local_account_1"],
     89 		},
     90 	}
     91 	suite.testBlocks = testrig.NewTestBlocks()
     92 	suite.testLists = testrig.NewTestLists()
     93 }
     94 
     95 func (suite *ProcessingStandardTestSuite) SetupTest() {
     96 	suite.state.Caches.Init()
     97 	testrig.StartWorkers(&suite.state)
     98 
     99 	testrig.InitTestConfig()
    100 	testrig.InitTestLog()
    101 
    102 	suite.db = testrig.NewTestDB(&suite.state)
    103 	suite.state.DB = suite.db
    104 	suite.testActivities = testrig.NewTestActivities(suite.testAccounts)
    105 	suite.storage = testrig.NewInMemoryStorage()
    106 	suite.state.Storage = suite.storage
    107 	suite.typeconverter = testrig.NewTestTypeConverter(suite.db)
    108 
    109 	testrig.StartTimelines(
    110 		&suite.state,
    111 		visibility.NewFilter(&suite.state),
    112 		suite.typeconverter,
    113 	)
    114 
    115 	suite.httpClient = testrig.NewMockHTTPClient(nil, "../../testrig/media")
    116 	suite.httpClient.TestRemotePeople = testrig.NewTestFediPeople()
    117 	suite.httpClient.TestRemoteStatuses = testrig.NewTestFediStatuses()
    118 
    119 	suite.transportController = testrig.NewTestTransportController(&suite.state, suite.httpClient)
    120 	suite.mediaManager = testrig.NewTestMediaManager(&suite.state)
    121 	suite.federator = testrig.NewTestFederator(&suite.state, suite.transportController, suite.mediaManager)
    122 	suite.oauthServer = testrig.NewTestOauthServer(suite.db)
    123 	suite.emailSender = testrig.NewEmailSender("../../web/template/", nil)
    124 
    125 	suite.processor = processing.NewProcessor(suite.typeconverter, suite.federator, suite.oauthServer, suite.mediaManager, &suite.state, suite.emailSender)
    126 	suite.state.Workers.EnqueueClientAPI = suite.processor.EnqueueClientAPI
    127 	suite.state.Workers.EnqueueFederator = suite.processor.EnqueueFederator
    128 
    129 	testrig.StandardDBSetup(suite.db, suite.testAccounts)
    130 	testrig.StandardStorageSetup(suite.storage, "../../testrig/media")
    131 }
    132 
    133 func (suite *ProcessingStandardTestSuite) TearDownTest() {
    134 	testrig.StandardDBTeardown(suite.db)
    135 	testrig.StandardStorageTeardown(suite.storage)
    136 	testrig.StopWorkers(&suite.state)
    137 }
    138 
    139 func (suite *ProcessingStandardTestSuite) openStreams(ctx context.Context, account *gtsmodel.Account, listIDs []string) map[string]*stream.Stream {
    140 	streams := make(map[string]*stream.Stream)
    141 
    142 	for _, streamType := range []string{
    143 		stream.TimelineHome,
    144 		stream.TimelinePublic,
    145 		stream.TimelineNotifications,
    146 	} {
    147 		stream, err := suite.processor.Stream().Open(ctx, account, streamType)
    148 		if err != nil {
    149 			suite.FailNow(err.Error())
    150 		}
    151 
    152 		streams[streamType] = stream
    153 	}
    154 
    155 	for _, listID := range listIDs {
    156 		streamType := stream.TimelineList + ":" + listID
    157 
    158 		stream, err := suite.processor.Stream().Open(ctx, account, streamType)
    159 		if err != nil {
    160 			suite.FailNow(err.Error())
    161 		}
    162 
    163 		streams[streamType] = stream
    164 	}
    165 
    166 	return streams
    167 }