summaryrefslogtreecommitdiff
path: root/internal/timeline/manager_test.go
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-08-15 18:43:08 +0200
committerLibravatar GitHub <noreply@github.com>2021-08-15 18:43:08 +0200
commitff406be68f0fe6fc0b2dae9a091ce164ac039b3f (patch)
tree622473ad500239f890b116f8bd30164b92a7dfc5 /internal/timeline/manager_test.go
parentDon't run tests+lint on merge to main (#139) (diff)
downloadgotosocial-ff406be68f0fe6fc0b2dae9a091ce164ac039b3f.tar.xz
Timeline loop fix (#140)
* uwu we made a fucky wucky * uwu we made a fucky wucky * work on timeline fixes a little * fiddle with tests some more * bleep bloop more tests * more tests * update drone yml * update some sturf * make the timeline code a bit lazier * go fmt * fix drone.yml
Diffstat (limited to 'internal/timeline/manager_test.go')
-rw-r--r--internal/timeline/manager_test.go142
1 files changed, 142 insertions, 0 deletions
diff --git a/internal/timeline/manager_test.go b/internal/timeline/manager_test.go
new file mode 100644
index 000000000..9b975a5ce
--- /dev/null
+++ b/internal/timeline/manager_test.go
@@ -0,0 +1,142 @@
+/*
+ GoToSocial
+ Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package timeline_test
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/suite"
+ "github.com/superseriousbusiness/gotosocial/testrig"
+)
+
+type ManagerTestSuite struct {
+ TimelineStandardTestSuite
+}
+
+func (suite *ManagerTestSuite) SetupSuite() {
+ suite.testAccounts = testrig.NewTestAccounts()
+ suite.testStatuses = testrig.NewTestStatuses()
+}
+
+func (suite *ManagerTestSuite) SetupTest() {
+ suite.config = testrig.NewTestConfig()
+ suite.db = testrig.NewTestDB()
+ suite.log = testrig.NewTestLog()
+ suite.tc = testrig.NewTestTypeConverter(suite.db)
+
+ testrig.StandardDBSetup(suite.db, nil)
+
+ manager := testrig.NewTestTimelineManager(suite.db)
+ suite.manager = manager
+}
+
+func (suite *ManagerTestSuite) TearDownTest() {
+ testrig.StandardDBTeardown(suite.db)
+}
+
+func (suite *ManagerTestSuite) TestManagerIntegration() {
+ testAccount := suite.testAccounts["local_account_1"]
+
+ // should start at 0
+ indexedLen := suite.manager.GetIndexedLength(testAccount.ID)
+ suite.Equal(0, indexedLen)
+
+ // oldestIndexed should be empty string since there's nothing indexed
+ oldestIndexed, err := suite.manager.GetOldestIndexedID(testAccount.ID)
+ suite.NoError(err)
+ suite.Empty(oldestIndexed)
+
+ // trigger status preparation
+ err = suite.manager.PrepareXFromTop(testAccount.ID, 20)
+ suite.NoError(err)
+
+ // local_account_1 can see 11 statuses out of the testrig statuses in its home timeline
+ indexedLen = suite.manager.GetIndexedLength(testAccount.ID)
+ suite.Equal(11, indexedLen)
+
+ // oldest should now be set
+ oldestIndexed, err = suite.manager.GetOldestIndexedID(testAccount.ID)
+ suite.NoError(err)
+ suite.Equal("01F8MH75CBF9JFX4ZAD54N0W0R", oldestIndexed)
+
+ // get hometimeline
+ statuses, err := suite.manager.HomeTimeline(testAccount.ID, "", "", "", 20, false)
+ suite.NoError(err)
+ suite.Len(statuses, 11)
+
+ // now wipe the last status from all timelines, as though it had been deleted by the owner
+ err = suite.manager.WipeStatusFromAllTimelines("01F8MH75CBF9JFX4ZAD54N0W0R")
+ suite.NoError(err)
+
+ // timeline should be shorter
+ indexedLen = suite.manager.GetIndexedLength(testAccount.ID)
+ suite.Equal(10, indexedLen)
+
+ // oldest should now be different
+ oldestIndexed, err = suite.manager.GetOldestIndexedID(testAccount.ID)
+ suite.NoError(err)
+ suite.Equal("01F8MH82FYRXD2RC6108DAJ5HB", 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(testAccount.ID, "01F8MH82FYRXD2RC6108DAJ5HB")
+ suite.NoError(err)
+ suite.Equal(2, removed) // 1 status should be removed, but from both indexed and prepared, so 2 removals total
+
+ // timeline should be shorter
+ indexedLen = suite.manager.GetIndexedLength(testAccount.ID)
+ suite.Equal(9, indexedLen)
+
+ // oldest should now be different
+ oldestIndexed, err = suite.manager.GetOldestIndexedID(testAccount.ID)
+ suite.NoError(err)
+ suite.Equal("01F8MHAAY43M6RJ473VQFCVH37", oldestIndexed)
+
+ // now remove all entries by local_account_2 from the timeline
+ err = suite.manager.WipeStatusesFromAccountID(testAccount.ID, suite.testAccounts["local_account_2"].ID)
+ suite.NoError(err)
+
+ // timeline should be empty now
+ indexedLen = suite.manager.GetIndexedLength(testAccount.ID)
+ suite.Equal(5, indexedLen)
+
+ // ingest 1 into the timeline
+ status1 := suite.testStatuses["admin_account_status_1"]
+ ingested, err := suite.manager.Ingest(status1, testAccount.ID)
+ suite.NoError(err)
+ suite.True(ingested)
+
+ // ingest and prepare another one into the timeline
+ status2 := suite.testStatuses["local_account_2_status_1"]
+ ingested, err = suite.manager.IngestAndPrepare(status2, testAccount.ID)
+ suite.NoError(err)
+ suite.True(ingested)
+
+ // timeline should be longer now
+ indexedLen = suite.manager.GetIndexedLength(testAccount.ID)
+ suite.Equal(7, indexedLen)
+
+ // try to ingest status 2 again
+ ingested, err = suite.manager.IngestAndPrepare(status2, testAccount.ID)
+ suite.NoError(err)
+ suite.False(ingested) // should be false since it's a duplicate
+}
+
+func TestManagerTestSuite(t *testing.T) {
+ suite.Run(t, new(ManagerTestSuite))
+}