gtsocial-umbx

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

transport_test.go (3833B)


      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 transport_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/processing"
     30 	"github.com/superseriousbusiness/gotosocial/internal/state"
     31 	"github.com/superseriousbusiness/gotosocial/internal/storage"
     32 	"github.com/superseriousbusiness/gotosocial/internal/transport"
     33 	"github.com/superseriousbusiness/gotosocial/internal/visibility"
     34 	"github.com/superseriousbusiness/gotosocial/testrig"
     35 )
     36 
     37 type TransportTestSuite struct {
     38 	// standard suite interfaces
     39 	suite.Suite
     40 	db           db.DB
     41 	storage      *storage.Driver
     42 	mediaManager *media.Manager
     43 	federator    federation.Federator
     44 	processor    *processing.Processor
     45 	emailSender  email.Sender
     46 	sentEmails   map[string]string
     47 	state        state.State
     48 
     49 	// standard suite models
     50 	testTokens       map[string]*gtsmodel.Token
     51 	testClients      map[string]*gtsmodel.Client
     52 	testApplications map[string]*gtsmodel.Application
     53 	testUsers        map[string]*gtsmodel.User
     54 	testAccounts     map[string]*gtsmodel.Account
     55 
     56 	transport transport.Transport
     57 }
     58 
     59 func (suite *TransportTestSuite) SetupSuite() {
     60 	suite.testTokens = testrig.NewTestTokens()
     61 	suite.testClients = testrig.NewTestClients()
     62 	suite.testApplications = testrig.NewTestApplications()
     63 	suite.testUsers = testrig.NewTestUsers()
     64 	suite.testAccounts = testrig.NewTestAccounts()
     65 }
     66 
     67 func (suite *TransportTestSuite) SetupTest() {
     68 	suite.state.Caches.Init()
     69 	testrig.StartWorkers(&suite.state)
     70 
     71 	testrig.InitTestConfig()
     72 	testrig.InitTestLog()
     73 
     74 	suite.db = testrig.NewTestDB(&suite.state)
     75 	suite.state.DB = suite.db
     76 	suite.storage = testrig.NewInMemoryStorage()
     77 	suite.state.Storage = suite.storage
     78 
     79 	testrig.StartTimelines(
     80 		&suite.state,
     81 		visibility.NewFilter(&suite.state),
     82 		testrig.NewTestTypeConverter(suite.db),
     83 	)
     84 
     85 	suite.mediaManager = testrig.NewTestMediaManager(&suite.state)
     86 	suite.federator = testrig.NewTestFederator(&suite.state, testrig.NewTestTransportController(&suite.state, testrig.NewMockHTTPClient(nil, "../../testrig/media")), suite.mediaManager)
     87 	suite.sentEmails = make(map[string]string)
     88 	suite.emailSender = testrig.NewEmailSender("../../web/template/", suite.sentEmails)
     89 	suite.processor = testrig.NewTestProcessor(&suite.state, suite.federator, suite.emailSender, suite.mediaManager)
     90 
     91 	testrig.StandardDBSetup(suite.db, nil)
     92 	testrig.StandardStorageSetup(suite.storage, "../../testrig/media")
     93 
     94 	ts, err := suite.federator.TransportController().NewTransportForUsername(context.TODO(), "")
     95 	if err != nil {
     96 		suite.FailNow(err.Error())
     97 	}
     98 	suite.transport = ts
     99 }
    100 
    101 func (suite *TransportTestSuite) TearDownTest() {
    102 	testrig.StandardDBTeardown(suite.db)
    103 	testrig.StandardStorageTeardown(suite.storage)
    104 	testrig.StopWorkers(&suite.state)
    105 }