gtsocial-umbx

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

prune_test.go (3497B)


      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 	"testing"
     23 
     24 	"github.com/stretchr/testify/suite"
     25 )
     26 
     27 type PruneTestSuite struct {
     28 	TimelineStandardTestSuite
     29 }
     30 
     31 func (suite *PruneTestSuite) TestPrune() {
     32 	var (
     33 		ctx                        = context.Background()
     34 		testAccountID              = suite.testAccounts["local_account_1"].ID
     35 		desiredPreparedItemsLength = 5
     36 		desiredIndexedItemsLength  = 5
     37 	)
     38 
     39 	suite.fillTimeline(testAccountID)
     40 
     41 	pruned, err := suite.state.Timelines.Home.Prune(ctx, testAccountID, desiredPreparedItemsLength, desiredIndexedItemsLength)
     42 	suite.NoError(err)
     43 	suite.Equal(12, pruned)
     44 	suite.Equal(5, suite.state.Timelines.Home.GetIndexedLength(ctx, testAccountID))
     45 }
     46 
     47 func (suite *PruneTestSuite) TestPruneTwice() {
     48 	var (
     49 		ctx                        = context.Background()
     50 		testAccountID              = suite.testAccounts["local_account_1"].ID
     51 		desiredPreparedItemsLength = 5
     52 		desiredIndexedItemsLength  = 5
     53 	)
     54 
     55 	suite.fillTimeline(testAccountID)
     56 
     57 	pruned, err := suite.state.Timelines.Home.Prune(ctx, testAccountID, desiredPreparedItemsLength, desiredIndexedItemsLength)
     58 	suite.NoError(err)
     59 	suite.Equal(12, pruned)
     60 	suite.Equal(5, suite.state.Timelines.Home.GetIndexedLength(ctx, testAccountID))
     61 
     62 	// Prune same again, nothing should be pruned this time.
     63 	pruned, err = suite.state.Timelines.Home.Prune(ctx, testAccountID, desiredPreparedItemsLength, desiredIndexedItemsLength)
     64 	suite.NoError(err)
     65 	suite.Equal(0, pruned)
     66 	suite.Equal(5, suite.state.Timelines.Home.GetIndexedLength(ctx, testAccountID))
     67 }
     68 
     69 func (suite *PruneTestSuite) TestPruneTo0() {
     70 	var (
     71 		ctx                        = context.Background()
     72 		testAccountID              = suite.testAccounts["local_account_1"].ID
     73 		desiredPreparedItemsLength = 0
     74 		desiredIndexedItemsLength  = 0
     75 	)
     76 
     77 	suite.fillTimeline(testAccountID)
     78 
     79 	pruned, err := suite.state.Timelines.Home.Prune(ctx, testAccountID, desiredPreparedItemsLength, desiredIndexedItemsLength)
     80 	suite.NoError(err)
     81 	suite.Equal(17, pruned)
     82 	suite.Equal(0, suite.state.Timelines.Home.GetIndexedLength(ctx, testAccountID))
     83 }
     84 
     85 func (suite *PruneTestSuite) TestPruneToInfinityAndBeyond() {
     86 	var (
     87 		ctx                        = context.Background()
     88 		testAccountID              = suite.testAccounts["local_account_1"].ID
     89 		desiredPreparedItemsLength = 9999999
     90 		desiredIndexedItemsLength  = 9999999
     91 	)
     92 
     93 	suite.fillTimeline(testAccountID)
     94 
     95 	pruned, err := suite.state.Timelines.Home.Prune(ctx, testAccountID, desiredPreparedItemsLength, desiredIndexedItemsLength)
     96 	suite.NoError(err)
     97 	suite.Equal(0, pruned)
     98 	suite.Equal(17, suite.state.Timelines.Home.GetIndexedLength(ctx, testAccountID))
     99 }
    100 
    101 func TestPruneTestSuite(t *testing.T) {
    102 	suite.Run(t, new(PruneTestSuite))
    103 }