gtsocial-umbx

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

user_test.go (3755B)


      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 user_test
     19 
     20 import (
     21 	"github.com/stretchr/testify/suite"
     22 	"github.com/superseriousbusiness/gotosocial/internal/api/client/user"
     23 	"github.com/superseriousbusiness/gotosocial/internal/db"
     24 	"github.com/superseriousbusiness/gotosocial/internal/email"
     25 	"github.com/superseriousbusiness/gotosocial/internal/federation"
     26 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     27 	"github.com/superseriousbusiness/gotosocial/internal/media"
     28 	"github.com/superseriousbusiness/gotosocial/internal/processing"
     29 	"github.com/superseriousbusiness/gotosocial/internal/state"
     30 	"github.com/superseriousbusiness/gotosocial/internal/storage"
     31 	"github.com/superseriousbusiness/gotosocial/internal/typeutils"
     32 	"github.com/superseriousbusiness/gotosocial/internal/visibility"
     33 	"github.com/superseriousbusiness/gotosocial/testrig"
     34 )
     35 
     36 type UserStandardTestSuite struct {
     37 	suite.Suite
     38 	db           db.DB
     39 	tc           typeutils.TypeConverter
     40 	mediaManager *media.Manager
     41 	federator    federation.Federator
     42 	emailSender  email.Sender
     43 	processor    *processing.Processor
     44 	storage      *storage.Driver
     45 	state        state.State
     46 
     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 
     53 	sentEmails map[string]string
     54 
     55 	userModule *user.Module
     56 }
     57 
     58 func (suite *UserStandardTestSuite) SetupTest() {
     59 	suite.state.Caches.Init()
     60 	testrig.StartWorkers(&suite.state)
     61 
     62 	testrig.InitTestConfig()
     63 	testrig.InitTestLog()
     64 
     65 	suite.testTokens = testrig.NewTestTokens()
     66 	suite.testClients = testrig.NewTestClients()
     67 	suite.testApplications = testrig.NewTestApplications()
     68 	suite.testUsers = testrig.NewTestUsers()
     69 	suite.testAccounts = testrig.NewTestAccounts()
     70 
     71 	suite.db = testrig.NewTestDB(&suite.state)
     72 	suite.state.DB = suite.db
     73 	suite.storage = testrig.NewInMemoryStorage()
     74 	suite.state.Storage = suite.storage
     75 
     76 	suite.tc = testrig.NewTestTypeConverter(suite.db)
     77 
     78 	testrig.StartTimelines(
     79 		&suite.state,
     80 		visibility.NewFilter(&suite.state),
     81 		suite.tc,
     82 	)
     83 
     84 	suite.mediaManager = testrig.NewTestMediaManager(&suite.state)
     85 	suite.federator = testrig.NewTestFederator(&suite.state, testrig.NewTestTransportController(&suite.state, testrig.NewMockHTTPClient(nil, "../../../../testrig/media")), suite.mediaManager)
     86 	suite.sentEmails = make(map[string]string)
     87 	suite.emailSender = testrig.NewEmailSender("../../../../web/template/", suite.sentEmails)
     88 	suite.processor = testrig.NewTestProcessor(&suite.state, suite.federator, suite.emailSender, suite.mediaManager)
     89 	suite.userModule = user.New(suite.processor)
     90 	testrig.StandardDBSetup(suite.db, suite.testAccounts)
     91 	testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media")
     92 }
     93 
     94 func (suite *UserStandardTestSuite) TearDownTest() {
     95 	testrig.StandardDBTeardown(suite.db)
     96 	testrig.StandardStorageTeardown(suite.storage)
     97 	testrig.StopWorkers(&suite.state)
     98 }