diff options
| author | 2022-05-16 18:48:59 +0200 | |
|---|---|---|
| committer | 2022-05-16 18:48:59 +0200 | |
| commit | 5ef41ba3f21f4c2105f668fc35b6284749e17775 (patch) | |
| tree | bd77afe69fab45d411bc6604f35737dcb941acda /internal/timeline | |
| parent | testrig: override bind address from environment variable (#577) (diff) | |
| download | gotosocial-5ef41ba3f21f4c2105f668fc35b6284749e17775.tar.xz | |
[chore] Timeline test updates (#578)
* add admin boost of zork to test model
* update tests to make them more determinate
* remove printf call
Diffstat (limited to 'internal/timeline')
| -rw-r--r-- | internal/timeline/get_test.go | 37 | ||||
| -rw-r--r-- | internal/timeline/index_test.go | 4 | ||||
| -rw-r--r-- | internal/timeline/manager_test.go | 10 | 
3 files changed, 31 insertions, 20 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 diff --git a/internal/timeline/index_test.go b/internal/timeline/index_test.go index b08fbf296..ae7ec40ab 100644 --- a/internal/timeline/index_test.go +++ b/internal/timeline/index_test.go @@ -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()) diff --git a/internal/timeline/manager_test.go b/internal/timeline/manager_test.go index efa4ee261..8eb92a4e3 100644 --- a/internal/timeline/manager_test.go +++ b/internal/timeline/manager_test.go @@ -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) | 
