| 
									
										
										
										
											2023-09-04 15:55:17 +02:00
										 |  |  | // GoToSocial | 
					
						
							|  |  |  | // Copyright (C) GoToSocial Authors admin@gotosocial.org | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // 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 admin_test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2025-04-26 15:34:10 +02:00
										 |  |  | 	adminactions "code.superseriousbusiness.org/gotosocial/internal/admin" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/cleaner" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/db" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/email" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/federation" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/filter/interaction" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/filter/visibility" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/gtsmodel" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/media" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/messages" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/oauth" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/processing" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/processing/admin" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/state" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/storage" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/subscriptions" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/transport" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/internal/typeutils" | 
					
						
							|  |  |  | 	"code.superseriousbusiness.org/gotosocial/testrig" | 
					
						
							| 
									
										
										
										
											2023-09-04 15:55:17 +02:00
										 |  |  | 	"github.com/stretchr/testify/suite" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type AdminStandardTestSuite struct { | 
					
						
							|  |  |  | 	// standard suite interfaces | 
					
						
							|  |  |  | 	suite.Suite | 
					
						
							|  |  |  | 	db                  db.DB | 
					
						
							| 
									
										
										
										
											2023-09-23 17:44:11 +01:00
										 |  |  | 	tc                  *typeutils.Converter | 
					
						
							| 
									
										
										
										
											2023-09-04 15:55:17 +02:00
										 |  |  | 	storage             *storage.Driver | 
					
						
							|  |  |  | 	state               state.State | 
					
						
							|  |  |  | 	mediaManager        *media.Manager | 
					
						
							|  |  |  | 	oauthServer         oauth.Server | 
					
						
							|  |  |  | 	fromClientAPIChan   chan messages.FromClientAPI | 
					
						
							|  |  |  | 	transportController transport.Controller | 
					
						
							| 
									
										
										
										
											2023-10-23 10:58:13 +01:00
										 |  |  | 	federator           *federation.Federator | 
					
						
							| 
									
										
										
										
											2023-09-04 15:55:17 +02:00
										 |  |  | 	emailSender         email.Sender | 
					
						
							|  |  |  | 	sentEmails          map[string]string | 
					
						
							|  |  |  | 	processor           *processing.Processor | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// standard suite models | 
					
						
							|  |  |  | 	testTokens       map[string]*gtsmodel.Token | 
					
						
							|  |  |  | 	testApplications map[string]*gtsmodel.Application | 
					
						
							|  |  |  | 	testUsers        map[string]*gtsmodel.User | 
					
						
							|  |  |  | 	testAccounts     map[string]*gtsmodel.Account | 
					
						
							|  |  |  | 	testFollows      map[string]*gtsmodel.Follow | 
					
						
							|  |  |  | 	testAttachments  map[string]*gtsmodel.MediaAttachment | 
					
						
							|  |  |  | 	testStatuses     map[string]*gtsmodel.Status | 
					
						
							| 
									
										
										
										
											2024-01-29 15:57:22 +01:00
										 |  |  | 	testEmojis       map[string]*gtsmodel.Emoji | 
					
						
							| 
									
										
										
										
											2023-09-04 15:55:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// module being tested | 
					
						
							|  |  |  | 	adminProcessor *admin.Processor | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *AdminStandardTestSuite) SetupSuite() { | 
					
						
							|  |  |  | 	suite.testTokens = testrig.NewTestTokens() | 
					
						
							|  |  |  | 	suite.testApplications = testrig.NewTestApplications() | 
					
						
							|  |  |  | 	suite.testUsers = testrig.NewTestUsers() | 
					
						
							|  |  |  | 	suite.testAccounts = testrig.NewTestAccounts() | 
					
						
							|  |  |  | 	suite.testFollows = testrig.NewTestFollows() | 
					
						
							|  |  |  | 	suite.testAttachments = testrig.NewTestAttachments() | 
					
						
							|  |  |  | 	suite.testStatuses = testrig.NewTestStatuses() | 
					
						
							| 
									
										
										
										
											2024-01-29 15:57:22 +01:00
										 |  |  | 	suite.testEmojis = testrig.NewTestEmojis() | 
					
						
							| 
									
										
										
										
											2023-09-04 15:55:17 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *AdminStandardTestSuite) SetupTest() { | 
					
						
							|  |  |  | 	suite.state.Caches.Init() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	testrig.InitTestConfig() | 
					
						
							|  |  |  | 	testrig.InitTestLog() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	suite.db = testrig.NewTestDB(&suite.state) | 
					
						
							|  |  |  | 	suite.state.DB = suite.db | 
					
						
							| 
									
										
										
										
											2025-01-08 11:29:40 +01:00
										 |  |  | 	suite.state.AdminActions = adminactions.New(suite.state.DB, &suite.state.Workers) | 
					
						
							| 
									
										
										
										
											2023-09-23 17:44:11 +01:00
										 |  |  | 	suite.tc = typeutils.NewConverter(&suite.state) | 
					
						
							| 
									
										
										
										
											2023-09-04 15:55:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	suite.storage = testrig.NewInMemoryStorage() | 
					
						
							|  |  |  | 	suite.state.Storage = suite.storage | 
					
						
							|  |  |  | 	suite.mediaManager = testrig.NewTestMediaManager(&suite.state) | 
					
						
							| 
									
										
										
										
											2025-03-03 16:03:36 +01:00
										 |  |  | 	suite.oauthServer = testrig.NewTestOauthServer(&suite.state) | 
					
						
							| 
									
										
										
										
											2023-09-04 15:55:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	suite.transportController = testrig.NewTestTransportController(&suite.state, testrig.NewMockHTTPClient(nil, "../../../testrig/media")) | 
					
						
							|  |  |  | 	suite.federator = testrig.NewTestFederator(&suite.state, suite.transportController, suite.mediaManager) | 
					
						
							|  |  |  | 	suite.sentEmails = make(map[string]string) | 
					
						
							|  |  |  | 	suite.emailSender = testrig.NewEmailSender("../../../web/template/", suite.sentEmails) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	suite.processor = processing.NewProcessor( | 
					
						
							| 
									
										
										
										
											2023-10-30 18:35:11 +01:00
										 |  |  | 		cleaner.New(&suite.state), | 
					
						
							| 
									
										
										
										
											2025-01-08 11:29:40 +01:00
										 |  |  | 		subscriptions.New(&suite.state, suite.transportController, suite.tc), | 
					
						
							| 
									
										
										
										
											2023-09-04 15:55:17 +02:00
										 |  |  | 		suite.tc, | 
					
						
							|  |  |  | 		suite.federator, | 
					
						
							|  |  |  | 		suite.oauthServer, | 
					
						
							|  |  |  | 		suite.mediaManager, | 
					
						
							|  |  |  | 		&suite.state, | 
					
						
							|  |  |  | 		suite.emailSender, | 
					
						
							| 
									
										
										
										
											2025-01-23 16:47:30 -08:00
										 |  |  | 		testrig.NewNoopWebPushSender(), | 
					
						
							| 
									
										
										
										
											2024-07-24 13:27:42 +02:00
										 |  |  | 		visibility.NewFilter(&suite.state), | 
					
						
							|  |  |  | 		interaction.NewFilter(&suite.state), | 
					
						
							| 
									
										
										
										
											2023-09-04 15:55:17 +02:00
										 |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-14 15:57:25 +01:00
										 |  |  | 	testrig.StartWorkers(&suite.state, suite.processor.Workers()) | 
					
						
							| 
									
										
										
										
											2023-09-04 15:55:17 +02:00
										 |  |  | 	suite.adminProcessor = suite.processor.Admin() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	testrig.StandardDBSetup(suite.db, nil) | 
					
						
							|  |  |  | 	testrig.StandardStorageSetup(suite.storage, "../../../testrig/media") | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (suite *AdminStandardTestSuite) TearDownTest() { | 
					
						
							|  |  |  | 	testrig.StandardDBTeardown(suite.db) | 
					
						
							|  |  |  | 	testrig.StandardStorageTeardown(suite.storage) | 
					
						
							|  |  |  | 	testrig.StopWorkers(&suite.state) | 
					
						
							|  |  |  | } |