gtsocial-umbx

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

timeline_test.go (2977B)


      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 timeline_test
     19 
     20 import (
     21 	"context"
     22 	"sort"
     23 
     24 	"github.com/stretchr/testify/suite"
     25 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     26 	"github.com/superseriousbusiness/gotosocial/internal/state"
     27 	"github.com/superseriousbusiness/gotosocial/internal/visibility"
     28 	"github.com/superseriousbusiness/gotosocial/testrig"
     29 )
     30 
     31 type TimelineStandardTestSuite struct {
     32 	suite.Suite
     33 	state *state.State
     34 
     35 	testAccounts    map[string]*gtsmodel.Account
     36 	testStatuses    map[string]*gtsmodel.Status
     37 	highestStatusID string
     38 	lowestStatusID  string
     39 }
     40 
     41 func (suite *TimelineStandardTestSuite) SetupSuite() {
     42 	suite.testAccounts = testrig.NewTestAccounts()
     43 	suite.testStatuses = testrig.NewTestStatuses()
     44 }
     45 
     46 func (suite *TimelineStandardTestSuite) SetupTest() {
     47 	suite.state = new(state.State)
     48 
     49 	suite.state.Caches.Init()
     50 	testrig.StartWorkers(suite.state)
     51 
     52 	testrig.InitTestConfig()
     53 	testrig.InitTestLog()
     54 
     55 	suite.state.DB = testrig.NewTestDB(suite.state)
     56 
     57 	testrig.StartTimelines(
     58 		suite.state,
     59 		visibility.NewFilter(suite.state),
     60 		testrig.NewTestTypeConverter(suite.state.DB),
     61 	)
     62 
     63 	testrig.StandardDBSetup(suite.state.DB, nil)
     64 }
     65 
     66 func (suite *TimelineStandardTestSuite) TearDownTest() {
     67 	testrig.StandardDBTeardown(suite.state.DB)
     68 	testrig.StopWorkers(suite.state)
     69 }
     70 
     71 func (suite *TimelineStandardTestSuite) fillTimeline(timelineID string) {
     72 	// Put testrig statuses in a determinate order
     73 	// since we can't trust a map to keep order.
     74 	statuses := []*gtsmodel.Status{}
     75 	for _, s := range suite.testStatuses {
     76 		statuses = append(statuses, s)
     77 	}
     78 
     79 	sort.Slice(statuses, func(i, j int) bool {
     80 		return statuses[i].ID > statuses[j].ID
     81 	})
     82 
     83 	// Statuses are now highest -> lowest.
     84 	suite.highestStatusID = statuses[0].ID
     85 	suite.lowestStatusID = statuses[len(statuses)-1].ID
     86 	if suite.highestStatusID < suite.lowestStatusID {
     87 		suite.FailNow("", "statuses weren't ordered properly by sort")
     88 	}
     89 
     90 	// Put all test statuses into the timeline; we don't
     91 	// need to be fussy about who sees what for these tests.
     92 	for _, status := range statuses {
     93 		if _, err := suite.state.Timelines.Home.IngestOne(context.Background(), timelineID, status); err != nil {
     94 			suite.FailNow(err.Error())
     95 		}
     96 	}
     97 }