refetch_test.go (2610B)
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 media_test 19 20 import ( 21 "context" 22 "testing" 23 24 "github.com/stretchr/testify/suite" 25 ) 26 27 type RefetchTestSuite struct { 28 MediaStandardTestSuite 29 } 30 31 func (suite *RefetchTestSuite) TestRefetchEmojisNothingToDo() { 32 ctx := context.Background() 33 34 adminAccount := suite.testAccounts["admin_account"] 35 transport, err := suite.transportController.NewTransportForUsername(ctx, adminAccount.Username) 36 if err != nil { 37 suite.FailNow(err.Error()) 38 } 39 40 refetched, err := suite.manager.RefetchEmojis(ctx, "", transport.DereferenceMedia) 41 suite.NoError(err) 42 suite.Equal(0, refetched) 43 } 44 45 func (suite *RefetchTestSuite) TestRefetchEmojis() { 46 ctx := context.Background() 47 48 if err := suite.storage.Delete(ctx, suite.testEmojis["yell"].ImagePath); err != nil { 49 suite.FailNow(err.Error()) 50 } 51 52 adminAccount := suite.testAccounts["admin_account"] 53 transport, err := suite.transportController.NewTransportForUsername(ctx, adminAccount.Username) 54 if err != nil { 55 suite.FailNow(err.Error()) 56 } 57 58 refetched, err := suite.manager.RefetchEmojis(ctx, "", transport.DereferenceMedia) 59 suite.NoError(err) 60 suite.Equal(1, refetched) 61 } 62 63 func (suite *RefetchTestSuite) TestRefetchEmojisLocal() { 64 ctx := context.Background() 65 66 // delete the image for a LOCAL emoji 67 if err := suite.storage.Delete(ctx, suite.testEmojis["rainbow"].ImagePath); err != nil { 68 suite.FailNow(err.Error()) 69 } 70 71 adminAccount := suite.testAccounts["admin_account"] 72 transport, err := suite.transportController.NewTransportForUsername(ctx, adminAccount.Username) 73 if err != nil { 74 suite.FailNow(err.Error()) 75 } 76 77 refetched, err := suite.manager.RefetchEmojis(ctx, "", transport.DereferenceMedia) 78 suite.NoError(err) 79 suite.Equal(0, refetched) // shouldn't refetch anything because local 80 } 81 82 func TestRefetchTestSuite(t *testing.T) { 83 suite.Run(t, &RefetchTestSuite{}) 84 }