[chore] Timeline test updates (#578)

* add admin boost of zork to test model

* update tests to make them more determinate

* remove printf call
This commit is contained in:
tobi 2022-05-16 18:48:59 +02:00 committed by GitHub
parent 27a3c1dc56
commit 5ef41ba3f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 21 deletions

View file

@ -43,7 +43,7 @@ func (suite *BasicTestSuite) TestGetAllStatuses() {
s := []*gtsmodel.Status{}
err := suite.db.GetAll(context.Background(), &s)
suite.NoError(err)
suite.Len(s, 16)
suite.Len(s, 17)
}
func (suite *BasicTestSuite) TestGetAllNotNull() {

View file

@ -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

View file

@ -76,7 +76,7 @@ func (suite *IndexTestSuite) TestIndexBeforeLowID() {
postID, err := suite.timeline.OldestIndexedItemID(context.Background())
suite.NoError(err)
suite.Equal("01F8MHBQCBTDKN6X5VHGMMN4MA", postID)
suite.Equal("01F8MHC0H0A7XHTVH5F596ZKBM", postID)
indexLength := suite.timeline.ItemIndexLength(context.Background())
suite.Equal(9, indexLength)
@ -105,7 +105,7 @@ func (suite *IndexTestSuite) TestIndexBehindHighID() {
// the newest indexed post should be the highest one we have in our testrig
postID, err := suite.timeline.NewestIndexedItemID(context.Background())
suite.NoError(err)
suite.Equal("01G20ZM733MGN8J344T4ZDDFY1", postID)
suite.Equal("01G36SF3V6Y6V5BF9P4R7PQG7G", postID)
// indexLength should be 9 because that's all this user has hometimelineable
indexLength := suite.timeline.ItemIndexLength(context.Background())

View file

@ -84,7 +84,7 @@ func (suite *ManagerTestSuite) TestManagerIntegration() {
// oldest should now be set
oldestIndexed, err = suite.manager.GetOldestIndexedID(context.Background(), testAccount.ID)
suite.NoError(err)
suite.Equal("01F8MH75CBF9JFX4ZAD54N0W0R", oldestIndexed)
suite.Equal("01F8MH82FYRXD2RC6108DAJ5HB", oldestIndexed)
// get hometimeline
statuses, err := suite.manager.GetTimeline(context.Background(), testAccount.ID, "", "", "", 20, false)
@ -92,7 +92,7 @@ func (suite *ManagerTestSuite) TestManagerIntegration() {
suite.Len(statuses, 15)
// now wipe the last status from all timelines, as though it had been deleted by the owner
err = suite.manager.WipeItemFromAllTimelines(context.Background(), "01F8MH75CBF9JFX4ZAD54N0W0R")
err = suite.manager.WipeItemFromAllTimelines(context.Background(), "01F8MH82FYRXD2RC6108DAJ5HB")
suite.NoError(err)
// timeline should be shorter
@ -102,10 +102,10 @@ func (suite *ManagerTestSuite) TestManagerIntegration() {
// oldest should now be different
oldestIndexed, err = suite.manager.GetOldestIndexedID(context.Background(), testAccount.ID)
suite.NoError(err)
suite.Equal("01F8MH82FYRXD2RC6108DAJ5HB", oldestIndexed)
suite.Equal("01F8MHAAY43M6RJ473VQFCVH37", oldestIndexed)
// delete the new oldest status specifically from this timeline, as though local_account_1 had muted or blocked it
removed, err := suite.manager.Remove(context.Background(), testAccount.ID, "01F8MH82FYRXD2RC6108DAJ5HB")
removed, err := suite.manager.Remove(context.Background(), testAccount.ID, "01F8MHAAY43M6RJ473VQFCVH37")
suite.NoError(err)
suite.Equal(2, removed) // 1 status should be removed, but from both indexed and prepared, so 2 removals total
@ -116,7 +116,7 @@ func (suite *ManagerTestSuite) TestManagerIntegration() {
// oldest should now be different
oldestIndexed, err = suite.manager.GetOldestIndexedID(context.Background(), testAccount.ID)
suite.NoError(err)
suite.Equal("01F8MHAAY43M6RJ473VQFCVH37", oldestIndexed)
suite.Equal("01F8MHAMCHF6Y650WCRSCP4WMY", oldestIndexed)
// now remove all entries by local_account_2 from the timeline
err = suite.manager.WipeItemsFromAccountID(context.Background(), testAccount.ID, suite.testAccounts["local_account_2"].ID)

View file

@ -1049,6 +1049,32 @@ func NewTestStatuses() map[string]*gtsmodel.Status {
Likeable: true,
ActivityStreamsType: ap.ObjectNote,
},
"admin_account_status_4": {
ID: "01G36SF3V6Y6V5BF9P4R7PQG7G",
URI: "http://localhost:8080/users/admin/statuses/01G36SF3V6Y6V5BF9P4R7PQG7G",
URL: "http://localhost:8080/@admin/statuses/01G36SF3V6Y6V5BF9P4R7PQG7G",
Content: "hello everyone!",
CreatedAt: TimeMustParse("2021-10-20T12:41:37+02:00"),
UpdatedAt: TimeMustParse("2021-10-20T12:41:37+02:00"),
Local: true,
AccountURI: "http://localhost:8080/users/admin",
AccountID: "01F8MH17FWEB39HZJ76B6VXSKF",
InReplyToID: "",
InReplyToAccountID: "",
InReplyToURI: "",
BoostOfID: "01F8MHAMCHF6Y650WCRSCP4WMY",
BoostOfAccountID: "01F8MH1H7YV1Z7D2C8K2730QBF",
ContentWarning: "introduction post",
Visibility: gtsmodel.VisibilityPublic,
Sensitive: true,
Language: "en",
CreatedWithApplicationID: "01F8MGXQRHYF5QPMTMXP78QC2F",
Federated: true,
Boostable: true,
Replyable: true,
Likeable: true,
ActivityStreamsType: ap.ObjectNote,
},
"local_account_1_status_1": {
ID: "01F8MHAMCHF6Y650WCRSCP4WMY",
URI: "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY",