diff options
Diffstat (limited to 'internal/timeline/get_test.go')
-rw-r--r-- | internal/timeline/get_test.go | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/internal/timeline/get_test.go b/internal/timeline/get_test.go index dacf391fb..3af0ae2f6 100644 --- a/internal/timeline/get_test.go +++ b/internal/timeline/get_test.go @@ -20,10 +20,12 @@ package timeline_test import ( "context" + "sort" "testing" "time" "github.com/stretchr/testify/suite" + "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/timeline" "github.com/superseriousbusiness/gotosocial/internal/visibility" @@ -62,8 +64,17 @@ func (suite *GetTestSuite) SetupTest() { suite.FailNow(err.Error()) } - // prepare the timeline by just shoving all test statuses in it -- let's not be fussy about who sees what + // put the status IDs in a determinate order since we can't trust a map to keep its order + statuses := []*gtsmodel.Status{} for _, s := range suite.testStatuses { + statuses = append(statuses, s) + } + sort.Slice(statuses, func(i, j int) bool { + return statuses[i].ID > statuses[j].ID + }) + + // prepare the timeline by just shoving all test statuses in it -- let's not be fussy about who sees what + for _, s := range statuses { _, err := tl.IndexAndPrepareOne(context.Background(), s.GetID(), s.BoostOfID, s.AccountID, s.BoostOfAccountID) if err != nil { suite.FailNow(err.Error()) @@ -85,7 +96,7 @@ func (suite *GetTestSuite) TestGetDefault() { } // we only have 16 statuses in the test suite - suite.Len(statuses, 16) + suite.Len(statuses, 17) // statuses should be sorted highest to lowest ID var highest string @@ -171,14 +182,14 @@ func (suite *GetTestSuite) TestGetMaxIDPrepareNext() { } func (suite *GetTestSuite) TestGetMinID() { - // ask for 10 with a min ID somewhere in the middle of the stack + // ask for 15 with a min ID somewhere in the middle of the stack statuses, err := suite.timeline.Get(context.Background(), 10, "", "01F8MHBQCBTDKN6X5VHGMMN4MA", "", false) if err != nil { suite.FailNow(err.Error()) } - // we should only get 9 statuses back, since we asked for a min ID that excludes some of our entries - suite.Len(statuses, 9) + // we should only get 10 statuses back, since we asked for a min ID that excludes some of our entries + suite.Len(statuses, 10) // statuses should be sorted highest to lowest ID var highest string @@ -193,14 +204,14 @@ func (suite *GetTestSuite) TestGetMinID() { } func (suite *GetTestSuite) TestGetSinceID() { - // ask for 10 with a since ID somewhere in the middle of the stack - statuses, err := suite.timeline.Get(context.Background(), 10, "", "", "01F8MHBQCBTDKN6X5VHGMMN4MA", false) + // ask for 15 with a since ID somewhere in the middle of the stack + statuses, err := suite.timeline.Get(context.Background(), 15, "", "", "01F8MHBQCBTDKN6X5VHGMMN4MA", false) if err != nil { suite.FailNow(err.Error()) } - // we should only get 9 statuses back, since we asked for a since ID that excludes some of our entries - suite.Len(statuses, 9) + // we should only get 10 statuses back, since we asked for a since ID that excludes some of our entries + suite.Len(statuses, 10) // statuses should be sorted highest to lowest ID var highest string @@ -215,14 +226,14 @@ func (suite *GetTestSuite) TestGetSinceID() { } func (suite *GetTestSuite) TestGetSinceIDPrepareNext() { - // ask for 10 with a since ID somewhere in the middle of the stack - statuses, err := suite.timeline.Get(context.Background(), 10, "", "", "01F8MHBQCBTDKN6X5VHGMMN4MA", true) + // ask for 15 with a since ID somewhere in the middle of the stack + statuses, err := suite.timeline.Get(context.Background(), 15, "", "", "01F8MHBQCBTDKN6X5VHGMMN4MA", true) if err != nil { suite.FailNow(err.Error()) } - // we should only get 9 statuses back, since we asked for a since ID that excludes some of our entries - suite.Len(statuses, 9) + // we should only get 10 statuses back, since we asked for a since ID that excludes some of our entries + suite.Len(statuses, 10) // statuses should be sorted highest to lowest ID var highest string |