gtsocial-umbx

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

status_test.go (4129B)


      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 status_test
     19 
     20 import (
     21 	"github.com/stretchr/testify/suite"
     22 	"github.com/superseriousbusiness/gotosocial/internal/db"
     23 	"github.com/superseriousbusiness/gotosocial/internal/federation"
     24 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     25 	"github.com/superseriousbusiness/gotosocial/internal/media"
     26 	"github.com/superseriousbusiness/gotosocial/internal/processing"
     27 	"github.com/superseriousbusiness/gotosocial/internal/processing/status"
     28 	"github.com/superseriousbusiness/gotosocial/internal/state"
     29 	"github.com/superseriousbusiness/gotosocial/internal/storage"
     30 	"github.com/superseriousbusiness/gotosocial/internal/transport"
     31 	"github.com/superseriousbusiness/gotosocial/internal/typeutils"
     32 	"github.com/superseriousbusiness/gotosocial/internal/visibility"
     33 	"github.com/superseriousbusiness/gotosocial/testrig"
     34 )
     35 
     36 type StatusStandardTestSuite struct {
     37 	suite.Suite
     38 	db            db.DB
     39 	typeConverter typeutils.TypeConverter
     40 	tc            transport.Controller
     41 	storage       *storage.Driver
     42 	state         state.State
     43 	mediaManager  *media.Manager
     44 	federator     federation.Federator
     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 	testAttachments  map[string]*gtsmodel.MediaAttachment
     53 	testStatuses     map[string]*gtsmodel.Status
     54 	testTags         map[string]*gtsmodel.Tag
     55 	testMentions     map[string]*gtsmodel.Mention
     56 
     57 	// module being tested
     58 	status status.Processor
     59 }
     60 
     61 func (suite *StatusStandardTestSuite) SetupSuite() {
     62 	suite.testTokens = testrig.NewTestTokens()
     63 	suite.testClients = testrig.NewTestClients()
     64 	suite.testApplications = testrig.NewTestApplications()
     65 	suite.testUsers = testrig.NewTestUsers()
     66 	suite.testAccounts = testrig.NewTestAccounts()
     67 	suite.testAttachments = testrig.NewTestAttachments()
     68 	suite.testStatuses = testrig.NewTestStatuses()
     69 	suite.testTags = testrig.NewTestTags()
     70 	suite.testMentions = testrig.NewTestMentions()
     71 }
     72 
     73 func (suite *StatusStandardTestSuite) SetupTest() {
     74 	suite.state.Caches.Init()
     75 	testrig.StartWorkers(&suite.state)
     76 
     77 	testrig.InitTestConfig()
     78 	testrig.InitTestLog()
     79 
     80 	suite.db = testrig.NewTestDB(&suite.state)
     81 	suite.typeConverter = testrig.NewTestTypeConverter(suite.db)
     82 	suite.state.DB = suite.db
     83 
     84 	suite.tc = testrig.NewTestTransportController(&suite.state, testrig.NewMockHTTPClient(nil, "../../../testrig/media"))
     85 	suite.storage = testrig.NewInMemoryStorage()
     86 	suite.state.Storage = suite.storage
     87 	suite.mediaManager = testrig.NewTestMediaManager(&suite.state)
     88 	suite.federator = testrig.NewTestFederator(&suite.state, suite.tc, suite.mediaManager)
     89 
     90 	filter := visibility.NewFilter(&suite.state)
     91 	testrig.StartTimelines(
     92 		&suite.state,
     93 		filter,
     94 		testrig.NewTestTypeConverter(suite.db),
     95 	)
     96 
     97 	suite.status = status.New(&suite.state, suite.federator, suite.typeConverter, filter, processing.GetParseMentionFunc(suite.db, suite.federator))
     98 
     99 	testrig.StandardDBSetup(suite.db, suite.testAccounts)
    100 	testrig.StandardStorageSetup(suite.storage, "../../../testrig/media")
    101 }
    102 
    103 func (suite *StatusStandardTestSuite) TearDownTest() {
    104 	testrig.StandardDBTeardown(suite.db)
    105 	testrig.StandardStorageTeardown(suite.storage)
    106 	testrig.StopWorkers(&suite.state)
    107 }