diff options
Diffstat (limited to 'internal/federation')
| -rw-r--r-- | internal/federation/dereferencing/account_test.go | 38 | ||||
| -rw-r--r-- | internal/federation/dereferencing/emoji_test.go | 3 | ||||
| -rw-r--r-- | internal/federation/dereferencing/instance_test.go | 3 | ||||
| -rw-r--r-- | internal/federation/dereferencing/status_test.go | 34 | ||||
| -rw-r--r-- | internal/federation/federatingactor_test.go | 5 | ||||
| -rw-r--r-- | internal/federation/federatingdb/announce_test.go | 6 | ||||
| -rw-r--r-- | internal/federation/federatingdb/create_test.go | 11 | ||||
| -rw-r--r-- | internal/federation/federatingdb/federatingdb_test.go | 8 | ||||
| -rw-r--r-- | internal/federation/federatingdb/followers_test.go | 3 | ||||
| -rw-r--r-- | internal/federation/federatingdb/following_test.go | 3 | ||||
| -rw-r--r-- | internal/federation/federatingdb/inbox_test.go | 7 | ||||
| -rw-r--r-- | internal/federation/federatingdb/move_test.go | 2 | ||||
| -rw-r--r-- | internal/federation/federatingdb/reject_test.go | 2 | ||||
| -rw-r--r-- | internal/federation/federatingdb/update_test.go | 3 | ||||
| -rw-r--r-- | internal/federation/federatingprotocol_test.go | 34 | ||||
| -rw-r--r-- | internal/federation/federator_test.go | 4 |
16 files changed, 78 insertions, 88 deletions
diff --git a/internal/federation/dereferencing/account_test.go b/internal/federation/dereferencing/account_test.go index 24ee16f82..518f3e89f 100644 --- a/internal/federation/dereferencing/account_test.go +++ b/internal/federation/dereferencing/account_test.go @@ -51,7 +51,7 @@ func (suite *AccountTestSuite) TestDereferenceGroup() { groupURL := testrig.URLMustParse("https://unknown-instance.com/groups/some_group") group, _, err := suite.dereferencer.GetAccountByURI( - context.Background(), + suite.T().Context(), fetchingAccount.Username, groupURL, false, @@ -65,7 +65,7 @@ func (suite *AccountTestSuite) TestDereferenceGroup() { suite.WithinDuration(time.Now(), group.FetchedAt, 5*time.Second) // group should be in the database - dbGroup, err := suite.db.GetAccountByURI(context.Background(), group.URI) + dbGroup, err := suite.db.GetAccountByURI(suite.T().Context(), group.URI) suite.NoError(err) suite.Equal(group.ID, dbGroup.ID) suite.Equal(ap.ActorGroup, dbGroup.ActorType.String()) @@ -76,7 +76,7 @@ func (suite *AccountTestSuite) TestDereferenceService() { serviceURL := testrig.URLMustParse("https://owncast.example.org/federation/user/rgh") service, _, err := suite.dereferencer.GetAccountByURI( - context.Background(), + suite.T().Context(), fetchingAccount.Username, serviceURL, false, @@ -90,7 +90,7 @@ func (suite *AccountTestSuite) TestDereferenceService() { suite.WithinDuration(time.Now(), service.FetchedAt, 5*time.Second) // service should be in the database - dbService, err := suite.db.GetAccountByURI(context.Background(), service.URI) + dbService, err := suite.db.GetAccountByURI(suite.T().Context(), service.URI) suite.NoError(err) suite.Equal(service.ID, dbService.ID) suite.Equal(ap.ActorService, dbService.ActorType.String()) @@ -109,7 +109,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountAsRemoteURL() { targetAccount := suite.testAccounts["local_account_2"] fetchedAccount, _, err := suite.dereferencer.GetAccountByURI( - context.Background(), + suite.T().Context(), fetchingAccount.Username, testrig.URLMustParse(targetAccount.URI), false, @@ -124,12 +124,12 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountAsRemoteURLNoSharedInb targetAccount := suite.testAccounts["local_account_2"] targetAccount.SharedInboxURI = nil - if err := suite.db.UpdateAccount(context.Background(), targetAccount); err != nil { + if err := suite.db.UpdateAccount(suite.T().Context(), targetAccount); err != nil { suite.FailNow(err.Error()) } fetchedAccount, _, err := suite.dereferencer.GetAccountByURI( - context.Background(), + suite.T().Context(), fetchingAccount.Username, testrig.URLMustParse(targetAccount.URI), false, @@ -144,7 +144,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountAsUsername() { targetAccount := suite.testAccounts["local_account_2"] fetchedAccount, _, err := suite.dereferencer.GetAccountByURI( - context.Background(), + suite.T().Context(), fetchingAccount.Username, testrig.URLMustParse(targetAccount.URI), false, @@ -159,7 +159,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountAsUsernameDomain() { targetAccount := suite.testAccounts["local_account_2"] fetchedAccount, _, err := suite.dereferencer.GetAccountByURI( - context.Background(), + suite.T().Context(), fetchingAccount.Username, testrig.URLMustParse(targetAccount.URI), false, @@ -174,7 +174,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountAsUsernameDomainAndURL targetAccount := suite.testAccounts["local_account_2"] fetchedAccount, _, err := suite.dereferencer.GetAccountByUsernameDomain( - context.Background(), + suite.T().Context(), fetchingAccount.Username, targetAccount.Username, config.GetHost(), @@ -188,7 +188,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountWithUnknownUsername() fetchingAccount := suite.testAccounts["local_account_1"] fetchedAccount, _, err := suite.dereferencer.GetAccountByUsernameDomain( - context.Background(), + suite.T().Context(), fetchingAccount.Username, "thisaccountdoesnotexist", config.GetHost(), @@ -202,7 +202,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountWithUnknownUsernameDom fetchingAccount := suite.testAccounts["local_account_1"] fetchedAccount, _, err := suite.dereferencer.GetAccountByUsernameDomain( - context.Background(), + suite.T().Context(), fetchingAccount.Username, "thisaccountdoesnotexist", "localhost:8080", @@ -216,7 +216,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountWithUnknownUserURI() { fetchingAccount := suite.testAccounts["local_account_1"] fetchedAccount, _, err := suite.dereferencer.GetAccountByURI( - context.Background(), + suite.T().Context(), fetchingAccount.Username, testrig.URLMustParse("http://localhost:8080/users/thisaccountdoesnotexist"), false, @@ -227,7 +227,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountWithUnknownUserURI() { } func (suite *AccountTestSuite) TestDereferenceLocalAccountByRedirect() { - ctx, cncl := context.WithCancel(context.Background()) + ctx, cncl := context.WithCancel(suite.T().Context()) defer cncl() fetchingAccount := suite.testAccounts["local_account_1"] @@ -280,7 +280,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountByRedirect() { } func (suite *AccountTestSuite) TestDereferenceMasqueradingLocalAccount() { - ctx, cncl := context.WithCancel(context.Background()) + ctx, cncl := context.WithCancel(suite.T().Context()) defer cncl() fetchingAccount := suite.testAccounts["local_account_1"] @@ -345,7 +345,7 @@ func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithNonMatchingURI() // Attempt to fetch account at alternative URI, it should fail! fetchedAccount, _, err := suite.dereferencer.GetAccountByURI( - context.Background(), + suite.T().Context(), fetchingAccount.Username, testrig.URLMustParse(remoteAltURI), false, @@ -355,7 +355,7 @@ func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithNonMatchingURI() } func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithUnexpectedKeyChange() { - ctx, cncl := context.WithCancel(context.Background()) + ctx, cncl := context.WithCancel(suite.T().Context()) defer cncl() fetchingAcc := suite.testAccounts["local_account_1"] @@ -394,7 +394,7 @@ func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithUnexpectedKeyChan } func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithExpectedKeyChange() { - ctx, cncl := context.WithCancel(context.Background()) + ctx, cncl := context.WithCancel(suite.T().Context()) defer cncl() fetchingAcc := suite.testAccounts["local_account_1"] @@ -436,7 +436,7 @@ func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithExpectedKeyChange } func (suite *AccountTestSuite) TestRefreshFederatedRemoteAccountWithKeyChange() { - ctx, cncl := context.WithCancel(context.Background()) + ctx, cncl := context.WithCancel(suite.T().Context()) defer cncl() fetchingAcc := suite.testAccounts["local_account_1"] diff --git a/internal/federation/dereferencing/emoji_test.go b/internal/federation/dereferencing/emoji_test.go index 3c77d5108..c8c905781 100644 --- a/internal/federation/dereferencing/emoji_test.go +++ b/internal/federation/dereferencing/emoji_test.go @@ -18,7 +18,6 @@ package dereferencing_test import ( - "context" "fmt" "testing" "time" @@ -32,7 +31,7 @@ type EmojiTestSuite struct { } func (suite *EmojiTestSuite) TestDereferenceEmojiBlocking() { - ctx := context.Background() + ctx := suite.T().Context() emojiImageRemoteURL := "http://example.org/media/emojis/1781772.gif" emojiImageStaticRemoteURL := "http://example.org/media/emojis/1781772.gif" emojiURI := "http://example.org/emojis/1781772" diff --git a/internal/federation/dereferencing/instance_test.go b/internal/federation/dereferencing/instance_test.go index 614e49035..53d5d9fdf 100644 --- a/internal/federation/dereferencing/instance_test.go +++ b/internal/federation/dereferencing/instance_test.go @@ -18,7 +18,6 @@ package dereferencing_test import ( - "context" "net/url" "testing" @@ -77,7 +76,7 @@ func (suite *InstanceTestSuite) TestDerefInstance() { }, } { instance, err := suite.dereferencer.GetRemoteInstance( - gtscontext.SetFastFail(context.Background()), + gtscontext.SetFastFail(suite.T().Context()), suite.testAccounts["admin_account"].Username, tc.instanceIRI, ) diff --git a/internal/federation/dereferencing/status_test.go b/internal/federation/dereferencing/status_test.go index 6f9ee9359..e44babbfc 100644 --- a/internal/federation/dereferencing/status_test.go +++ b/internal/federation/dereferencing/status_test.go @@ -44,7 +44,7 @@ func (suite *StatusTestSuite) TestDereferenceSimpleStatus() { fetchingAccount := suite.testAccounts["local_account_1"] statusURL := testrig.URLMustParse("https://unknown-instance.com/users/brand_new_person/statuses/01FE4NTHKWW7THT67EF10EB839") - status, _, err := suite.dereferencer.GetStatusByURI(context.Background(), fetchingAccount.Username, statusURL) + status, _, err := suite.dereferencer.GetStatusByURI(suite.T().Context(), fetchingAccount.Username, statusURL) suite.NoError(err) suite.NotNil(status) @@ -59,13 +59,13 @@ func (suite *StatusTestSuite) TestDereferenceSimpleStatus() { suite.Equal(ap.ObjectNote, status.ActivityStreamsType) // status should be in the database - dbStatus, err := suite.db.GetStatusByURI(context.Background(), status.URI) + dbStatus, err := suite.db.GetStatusByURI(suite.T().Context(), status.URI) suite.NoError(err) suite.Equal(status.ID, dbStatus.ID) suite.True(*dbStatus.Federated) // account should be in the database now too - account, err := suite.db.GetAccountByURI(context.Background(), status.AccountURI) + account, err := suite.db.GetAccountByURI(suite.T().Context(), status.AccountURI) suite.NoError(err) suite.NotNil(account) suite.True(*account.Discoverable) @@ -81,7 +81,7 @@ func (suite *StatusTestSuite) TestDereferenceStatusWithMention() { fetchingAccount := suite.testAccounts["local_account_1"] statusURL := testrig.URLMustParse("https://unknown-instance.com/users/brand_new_person/statuses/01FE5Y30E3W4P7TRE0R98KAYQV") - status, _, err := suite.dereferencer.GetStatusByURI(context.Background(), fetchingAccount.Username, statusURL) + status, _, err := suite.dereferencer.GetStatusByURI(suite.T().Context(), fetchingAccount.Username, statusURL) suite.NoError(err) suite.NotNil(status) @@ -96,13 +96,13 @@ func (suite *StatusTestSuite) TestDereferenceStatusWithMention() { suite.Equal(ap.ObjectNote, status.ActivityStreamsType) // status should be in the database - dbStatus, err := suite.db.GetStatusByURI(context.Background(), status.URI) + dbStatus, err := suite.db.GetStatusByURI(suite.T().Context(), status.URI) suite.NoError(err) suite.Equal(status.ID, dbStatus.ID) suite.True(*dbStatus.Federated) // account should be in the database now too - account, err := suite.db.GetAccountByURI(context.Background(), status.AccountURI) + account, err := suite.db.GetAccountByURI(suite.T().Context(), status.AccountURI) suite.NoError(err) suite.NotNil(account) suite.True(*account.Discoverable) @@ -115,7 +115,7 @@ func (suite *StatusTestSuite) TestDereferenceStatusWithMention() { // we should have a mention in the database m := >smodel.Mention{} - err = suite.db.GetWhere(context.Background(), []db.Where{{Key: "status_id", Value: status.ID}}, m) + err = suite.db.GetWhere(suite.T().Context(), []db.Where{{Key: "status_id", Value: status.ID}}, m) suite.NoError(err) suite.NotNil(m) suite.Equal(status.ID, m.StatusID) @@ -129,7 +129,7 @@ func (suite *StatusTestSuite) TestDereferenceStatusWithTag() { fetchingAccount := suite.testAccounts["local_account_1"] statusURL := testrig.URLMustParse("https://unknown-instance.com/users/brand_new_person/statuses/01H641QSRS3TCXSVC10X4GPKW7") - status, _, err := suite.dereferencer.GetStatusByURI(context.Background(), fetchingAccount.Username, statusURL) + status, _, err := suite.dereferencer.GetStatusByURI(suite.T().Context(), fetchingAccount.Username, statusURL) suite.NoError(err) suite.NotNil(status) @@ -148,13 +148,13 @@ func (suite *StatusTestSuite) TestDereferenceStatusWithTag() { suite.Len(status.TagIDs, 1) // status should be in the database - dbStatus, err := suite.db.GetStatusByURI(context.Background(), status.URI) + dbStatus, err := suite.db.GetStatusByURI(suite.T().Context(), status.URI) suite.NoError(err) suite.Equal(status.ID, dbStatus.ID) suite.True(*dbStatus.Federated) // account should be in the database now too - account, err := suite.db.GetAccountByURI(context.Background(), status.AccountURI) + account, err := suite.db.GetAccountByURI(suite.T().Context(), status.AccountURI) suite.NoError(err) suite.NotNil(account) suite.True(*account.Discoverable) @@ -167,7 +167,7 @@ func (suite *StatusTestSuite) TestDereferenceStatusWithTag() { // we should have a tag in the database t := >smodel.Tag{} - err = suite.db.GetWhere(context.Background(), []db.Where{{Key: "name", Value: "piss"}}, t) + err = suite.db.GetWhere(suite.T().Context(), []db.Where{{Key: "name", Value: "piss"}}, t) suite.NoError(err) suite.NotNil(t) } @@ -176,7 +176,7 @@ func (suite *StatusTestSuite) TestDereferenceStatusWithImageAndNoContent() { fetchingAccount := suite.testAccounts["local_account_1"] statusURL := testrig.URLMustParse("https://turnip.farm/users/turniplover6969/statuses/70c53e54-3146-42d5-a630-83c8b6c7c042") - status, _, err := suite.dereferencer.GetStatusByURI(context.Background(), fetchingAccount.Username, statusURL) + status, _, err := suite.dereferencer.GetStatusByURI(suite.T().Context(), fetchingAccount.Username, statusURL) suite.NoError(err) suite.NotNil(status) @@ -191,13 +191,13 @@ func (suite *StatusTestSuite) TestDereferenceStatusWithImageAndNoContent() { suite.Equal(ap.ObjectNote, status.ActivityStreamsType) // status should be in the database - dbStatus, err := suite.db.GetStatusByURI(context.Background(), status.URI) + dbStatus, err := suite.db.GetStatusByURI(suite.T().Context(), status.URI) suite.NoError(err) suite.Equal(status.ID, dbStatus.ID) suite.True(*dbStatus.Federated) // account should be in the database now too - account, err := suite.db.GetAccountByURI(context.Background(), status.AccountURI) + account, err := suite.db.GetAccountByURI(suite.T().Context(), status.AccountURI) suite.NoError(err) suite.NotNil(account) suite.True(*account.Discoverable) @@ -210,7 +210,7 @@ func (suite *StatusTestSuite) TestDereferenceStatusWithImageAndNoContent() { // we should have an attachment in the database a := >smodel.MediaAttachment{} - err = suite.db.GetWhere(context.Background(), []db.Where{{Key: "status_id", Value: status.ID}}, a) + err = suite.db.GetWhere(suite.T().Context(), []db.Where{{Key: "status_id", Value: status.ID}}, a) suite.NoError(err) } @@ -228,7 +228,7 @@ func (suite *StatusTestSuite) TestDereferenceStatusWithNonMatchingURI() { // Attempt to fetch account at alternative URI, it should fail! fetchedStatus, _, err := suite.dereferencer.GetStatusByURI( - context.Background(), + suite.T().Context(), fetchingAccount.Username, testrig.URLMustParse(remoteAltURI), ) @@ -238,7 +238,7 @@ func (suite *StatusTestSuite) TestDereferenceStatusWithNonMatchingURI() { func (suite *StatusTestSuite) TestDereferencerRefreshStatusUpdated() { // Create a new context for this test. - ctx, cncl := context.WithCancel(context.Background()) + ctx, cncl := context.WithCancel(suite.T().Context()) defer cncl() // The local account we will be fetching statuses as. diff --git a/internal/federation/federatingactor_test.go b/internal/federation/federatingactor_test.go index c08ddcbcf..51ead5f31 100644 --- a/internal/federation/federatingactor_test.go +++ b/internal/federation/federatingactor_test.go @@ -19,7 +19,6 @@ package federation_test import ( "bytes" - "context" "encoding/json" "io" "net/url" @@ -40,7 +39,7 @@ type FederatingActorTestSuite struct { } func (suite *FederatingActorTestSuite) TestSendNoRemoteFollowers() { - ctx := context.Background() + ctx := suite.T().Context() testAccount := suite.testAccounts["local_account_1"] testNote := testrig.NewAPNote( testrig.URLMustParse("http://localhost:8080/users/the_mighty_zork/statuses/01G1TR6BADACCZWQMNF9X21TV5"), @@ -82,7 +81,7 @@ func (suite *FederatingActorTestSuite) TestSendNoRemoteFollowers() { } func (suite *FederatingActorTestSuite) TestSendRemoteFollower() { - ctx := context.Background() + ctx := suite.T().Context() testAccount := suite.testAccounts["local_account_1"] testRemoteAccount := suite.testAccounts["remote_account_1"] diff --git a/internal/federation/federatingdb/announce_test.go b/internal/federation/federatingdb/announce_test.go index efb8c2381..309b2beee 100644 --- a/internal/federation/federatingdb/announce_test.go +++ b/internal/federation/federatingdb/announce_test.go @@ -36,7 +36,7 @@ func (suite *AnnounceTestSuite) TestNewAnnounce() { receivingAccount1 := suite.testAccounts["local_account_1"] announcingAccount := suite.testAccounts["remote_account_1"] - ctx := createTestContext(receivingAccount1, announcingAccount) + ctx := createTestContext(suite.T(), receivingAccount1, announcingAccount) announce1 := suite.testActivities["announce_forwarded_1_zork"] err := suite.federatingDB.Announce(ctx, announce1.Activity.(vocab.ActivityStreamsAnnounce)) @@ -63,7 +63,7 @@ func (suite *AnnounceTestSuite) TestAnnounceTwice() { announcingAccount := suite.testAccounts["remote_account_1"] - ctx1 := createTestContext(receivingAccount1, announcingAccount) + ctx1 := createTestContext(suite.T(), receivingAccount1, announcingAccount) announce1 := suite.testActivities["announce_forwarded_1_zork"] err := suite.federatingDB.Announce(ctx1, announce1.Activity.(vocab.ActivityStreamsAnnounce)) @@ -87,7 +87,7 @@ func (suite *AnnounceTestSuite) TestAnnounceTwice() { suite.Nil(boost.BoostOf) suite.Equal("http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1", boost.BoostOfURI) - ctx2 := createTestContext(receivingAccount2, announcingAccount) + ctx2 := createTestContext(suite.T(), receivingAccount2, announcingAccount) announce2 := suite.testActivities["announce_forwarded_1_turtle"] err = suite.federatingDB.Announce(ctx2, announce2.Activity.(vocab.ActivityStreamsAnnounce)) diff --git a/internal/federation/federatingdb/create_test.go b/internal/federation/federatingdb/create_test.go index 2061c6be1..5a2b51a76 100644 --- a/internal/federation/federatingdb/create_test.go +++ b/internal/federation/federatingdb/create_test.go @@ -18,7 +18,6 @@ package federatingdb_test import ( - "context" "encoding/json" "testing" "time" @@ -40,7 +39,7 @@ func (suite *CreateTestSuite) TestCreateNote() { receivingAccount := suite.testAccounts["local_account_1"] requestingAccount := suite.testAccounts["remote_account_1"] - ctx := createTestContext(receivingAccount, requestingAccount) + ctx := createTestContext(suite.T(), receivingAccount, requestingAccount) create := suite.testActivities["dm_for_zork"].Activity objProp := create.GetActivityStreamsObject() @@ -60,7 +59,7 @@ func (suite *CreateTestSuite) TestCreateNoteForward() { receivingAccount := suite.testAccounts["local_account_1"] requestingAccount := suite.testAccounts["remote_account_1"] - ctx := createTestContext(receivingAccount, requestingAccount) + ctx := createTestContext(suite.T(), receivingAccount, requestingAccount) create := suite.testActivities["forwarded_message"].Activity @@ -111,14 +110,14 @@ func (suite *CreateTestSuite) TestCreateFlag1() { suite.FailNow(err.Error()) } - t, err := streams.ToType(context.Background(), m) + t, err := streams.ToType(suite.T().Context(), m) if err != nil { suite.FailNow(err.Error()) } flag := t.(vocab.ActivityStreamsFlag) - ctx := createTestContext(reportedAccount, reportingAccount) + ctx := createTestContext(suite.T(), reportedAccount, reportingAccount) if err := suite.federatingDB.Flag(ctx, flag); err != nil { suite.FailNow(err.Error()) } @@ -133,7 +132,7 @@ func (suite *CreateTestSuite) TestCreateFlag1() { report := msg.GTSModel.(*gtsmodel.Report) // report should be in the database - if _, err := suite.db.GetReportByID(context.Background(), report.ID); err != nil { + if _, err := suite.db.GetReportByID(suite.T().Context(), report.ID); err != nil { suite.FailNow(err.Error()) } } diff --git a/internal/federation/federatingdb/federatingdb_test.go b/internal/federation/federatingdb/federatingdb_test.go index 1203cf6b8..ee898e293 100644 --- a/internal/federation/federatingdb/federatingdb_test.go +++ b/internal/federation/federatingdb/federatingdb_test.go @@ -19,6 +19,7 @@ package federatingdb_test import ( "context" + "testing" "time" "code.superseriousbusiness.org/gotosocial/internal/admin" @@ -51,7 +52,7 @@ type FederatingDBTestSuite struct { } func (suite *FederatingDBTestSuite) getFederatorMsg(timeout time.Duration) (*messages.FromFediAPI, bool) { - ctx := context.Background() + ctx := suite.T().Context() ctx, cncl := context.WithTimeout(ctx, timeout) defer cncl() return suite.state.Workers.Federator.Queue.PopCtx(ctx) @@ -91,9 +92,8 @@ func (suite *FederatingDBTestSuite) TearDownTest() { testrig.StopWorkers(&suite.state) } -func createTestContext(receivingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account) context.Context { - ctx := context.Background() - ctx = gtscontext.SetReceivingAccount(ctx, receivingAccount) +func createTestContext(t *testing.T, receivingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account) context.Context { + ctx := gtscontext.SetReceivingAccount(t.Context(), receivingAccount) ctx = gtscontext.SetRequestingAccount(ctx, requestingAccount) return ctx } diff --git a/internal/federation/federatingdb/followers_test.go b/internal/federation/federatingdb/followers_test.go index 2c40c0a8c..e37e59d04 100644 --- a/internal/federation/federatingdb/followers_test.go +++ b/internal/federation/federatingdb/followers_test.go @@ -18,7 +18,6 @@ package federatingdb_test import ( - "context" "encoding/json" "testing" @@ -34,7 +33,7 @@ type FollowersTestSuite struct { func (suite *FollowersTestSuite) TestGetFollowers() { testAccount := suite.testAccounts["local_account_2"] - f, err := suite.federatingDB.Followers(context.Background(), testrig.URLMustParse(testAccount.URI)) + f, err := suite.federatingDB.Followers(suite.T().Context(), testrig.URLMustParse(testAccount.URI)) suite.NoError(err) fi, err := ap.Serialize(f) diff --git a/internal/federation/federatingdb/following_test.go b/internal/federation/federatingdb/following_test.go index ff8c11160..d139201d8 100644 --- a/internal/federation/federatingdb/following_test.go +++ b/internal/federation/federatingdb/following_test.go @@ -18,7 +18,6 @@ package federatingdb_test import ( - "context" "encoding/json" "testing" @@ -34,7 +33,7 @@ type FollowingTestSuite struct { func (suite *FollowingTestSuite) TestGetFollowing() { testAccount := suite.testAccounts["local_account_1"] - f, err := suite.federatingDB.Following(context.Background(), testrig.URLMustParse(testAccount.URI)) + f, err := suite.federatingDB.Following(suite.T().Context(), testrig.URLMustParse(testAccount.URI)) suite.NoError(err) fi, err := ap.Serialize(f) diff --git a/internal/federation/federatingdb/inbox_test.go b/internal/federation/federatingdb/inbox_test.go index d8c308a10..b26950962 100644 --- a/internal/federation/federatingdb/inbox_test.go +++ b/internal/federation/federatingdb/inbox_test.go @@ -18,7 +18,6 @@ package federatingdb_test import ( - "context" "testing" "code.superseriousbusiness.org/gotosocial/testrig" @@ -30,7 +29,7 @@ type InboxTestSuite struct { } func (suite *InboxTestSuite) TestInboxesForFollowersIRI() { - ctx := context.Background() + ctx := suite.T().Context() testAccount := suite.testAccounts["local_account_1"] inboxIRIs, err := suite.federatingDB.InboxesForIRI(ctx, testrig.URLMustParse(testAccount.FollowersURI)) @@ -47,7 +46,7 @@ func (suite *InboxTestSuite) TestInboxesForFollowersIRI() { } func (suite *InboxTestSuite) TestInboxesForAccountIRI() { - ctx := context.Background() + ctx := suite.T().Context() testAccount := suite.testAccounts["local_account_1"] inboxIRIs, err := suite.federatingDB.InboxesForIRI(ctx, testrig.URLMustParse(testAccount.URI)) @@ -63,7 +62,7 @@ func (suite *InboxTestSuite) TestInboxesForAccountIRI() { } func (suite *InboxTestSuite) TestInboxesForAccountIRIWithSharedInbox() { - ctx := context.Background() + ctx := suite.T().Context() testAccount := suite.testAccounts["local_account_1"] sharedInbox := "http://some-inbox-iri/weeeeeeeeeeeee" testAccount.SharedInboxURI = &sharedInbox diff --git a/internal/federation/federatingdb/move_test.go b/internal/federation/federatingdb/move_test.go index 38a869f15..d5026b778 100644 --- a/internal/federation/federatingdb/move_test.go +++ b/internal/federation/federatingdb/move_test.go @@ -38,7 +38,7 @@ func (suite *MoveTestSuite) move( requestingAcct *gtsmodel.Account, moveStr string, ) error { - ctx := createTestContext(receivingAcct, requestingAcct) + ctx := createTestContext(suite.T(), receivingAcct, requestingAcct) rawMove := make(map[string]interface{}) if err := json.Unmarshal([]byte(moveStr), &rawMove); err != nil { diff --git a/internal/federation/federatingdb/reject_test.go b/internal/federation/federatingdb/reject_test.go index 28a46eaad..142db7842 100644 --- a/internal/federation/federatingdb/reject_test.go +++ b/internal/federation/federatingdb/reject_test.go @@ -39,7 +39,7 @@ func (suite *RejectTestSuite) TestRejectFollowRequest() { // remote_account_2 rejects the follow request followingAccount := suite.testAccounts["local_account_1"] followedAccount := suite.testAccounts["remote_account_2"] - ctx := createTestContext(followingAccount, followedAccount) + ctx := createTestContext(suite.T(), followingAccount, followedAccount) // put the follow request in the database fr := >smodel.FollowRequest{ diff --git a/internal/federation/federatingdb/update_test.go b/internal/federation/federatingdb/update_test.go index 3c2d54fc7..5df9974b6 100644 --- a/internal/federation/federatingdb/update_test.go +++ b/internal/federation/federatingdb/update_test.go @@ -18,7 +18,6 @@ package federatingdb_test import ( - "context" "encoding/json" "testing" "time" @@ -34,7 +33,7 @@ type UpdateTestSuite struct { func (suite *UpdateTestSuite) TestUpdateNewMention() { var ( - ctx = context.Background() + ctx = suite.T().Context() update = suite.testActivities["remote_account_2_status_1_update"] receivingAcct = suite.testAccounts["local_account_1"] requestingAcct = suite.testAccounts["remote_account_2"] diff --git a/internal/federation/federatingprotocol_test.go b/internal/federation/federatingprotocol_test.go index fa4950d82..ed0895ca8 100644 --- a/internal/federation/federatingprotocol_test.go +++ b/internal/federation/federatingprotocol_test.go @@ -130,7 +130,7 @@ func (suite *FederatingProtocolTestSuite) TestPostInboxRequestBodyHookDM() { ) ctx := suite.postInboxRequestBodyHook( - context.Background(), + suite.T().Context(), receivingAccount, activity, ) @@ -155,7 +155,7 @@ func (suite *FederatingProtocolTestSuite) TestPostInboxRequestBodyHookReply() { ) ctx := suite.postInboxRequestBodyHook( - context.Background(), + suite.T().Context(), receivingAccount, activity, ) @@ -180,7 +180,7 @@ func (suite *FederatingProtocolTestSuite) TestPostInboxRequestBodyHookReplyToRep ) ctx := suite.postInboxRequestBodyHook( - context.Background(), + suite.T().Context(), receivingAccount, activity, ) @@ -205,7 +205,7 @@ func (suite *FederatingProtocolTestSuite) TestPostInboxRequestBodyHookAnnounceFo ) ctx := suite.postInboxRequestBodyHook( - context.Background(), + suite.T().Context(), receivingAccount, activity, ) @@ -230,7 +230,7 @@ func (suite *FederatingProtocolTestSuite) TestPostInboxRequestBodyHookAnnounceFo ) ctx := suite.postInboxRequestBodyHook( - context.Background(), + suite.T().Context(), receivingAccount, activity, ) @@ -255,7 +255,7 @@ func (suite *FederatingProtocolTestSuite) TestAuthenticatePostInbox() { ) ctx, authed, resp, code := suite.authenticatePostInbox( - context.Background(), + suite.T().Context(), receivingAccount, activity, ) @@ -268,7 +268,7 @@ func (suite *FederatingProtocolTestSuite) TestAuthenticatePostInbox() { func (suite *FederatingProtocolTestSuite) TestAuthenticatePostInboxKeyExpired() { var ( - ctx = context.Background() + ctx = suite.T().Context() activity = suite.testActivities["dm_for_zork"] receivingAccount = suite.testAccounts["local_account_1"] ) @@ -300,7 +300,7 @@ func (suite *FederatingProtocolTestSuite) TestAuthenticatePostGoneWithTombstone( ) ctx, authed, resp, code := suite.authenticatePostInbox( - context.Background(), + suite.T().Context(), receivingAccount, activity, ) @@ -320,12 +320,12 @@ func (suite *FederatingProtocolTestSuite) TestAuthenticatePostGoneNoTombstone() ) // Delete the tombstone; it'll have to be created again. - if err := suite.state.DB.DeleteTombstone(context.Background(), testTombstone.ID); err != nil { + if err := suite.state.DB.DeleteTombstone(suite.T().Context(), testTombstone.ID); err != nil { suite.FailNow(err.Error()) } ctx, authed, resp, code := suite.authenticatePostInbox( - context.Background(), + suite.T().Context(), receivingAccount, activity, ) @@ -337,7 +337,7 @@ func (suite *FederatingProtocolTestSuite) TestAuthenticatePostGoneNoTombstone() // Tombstone should be back, baby! exists, err := suite.state.DB.TombstoneExistsWithURI( - context.Background(), + suite.T().Context(), "https://somewhere.mysterious/users/rest_in_piss#main-key", ) suite.NoError(err) @@ -368,7 +368,7 @@ func (suite *FederatingProtocolTestSuite) TestBlockedNoProblem() { ) blocked, err := suite.blocked( - context.Background(), + suite.T().Context(), receivingAccount, requestingAccount, otherIRIs, @@ -390,7 +390,7 @@ func (suite *FederatingProtocolTestSuite) TestBlockedReceiverBlocksRequester() { ) // Insert a block from receivingAccount targeting requestingAccount. - if err := suite.state.DB.PutBlock(context.Background(), >smodel.Block{ + if err := suite.state.DB.PutBlock(suite.T().Context(), >smodel.Block{ ID: "01G3KBEMJD4VQ2D615MPV7KTRD", URI: "whatever", AccountID: receivingAccount.ID, @@ -400,7 +400,7 @@ func (suite *FederatingProtocolTestSuite) TestBlockedReceiverBlocksRequester() { } blocked, err := suite.blocked( - context.Background(), + suite.T().Context(), receivingAccount, requestingAccount, otherIRIs, @@ -425,7 +425,7 @@ func (suite *FederatingProtocolTestSuite) TestBlockedCCd() { ) // Insert a block from receivingAccount targeting ccedAccount. - if err := suite.state.DB.PutBlock(context.Background(), >smodel.Block{ + if err := suite.state.DB.PutBlock(suite.T().Context(), >smodel.Block{ ID: "01G3KBEMJD4VQ2D615MPV7KTRD", URI: "whatever", AccountID: receivingAccount.ID, @@ -435,7 +435,7 @@ func (suite *FederatingProtocolTestSuite) TestBlockedCCd() { } blocked, err := suite.blocked( - context.Background(), + suite.T().Context(), receivingAccount, requestingAccount, otherIRIs, @@ -462,7 +462,7 @@ func (suite *FederatingProtocolTestSuite) TestBlockedRepliedStatus() { ) blocked, err := suite.blocked( - context.Background(), + suite.T().Context(), receivingAccount, requestingAccount, otherIRIs, diff --git a/internal/federation/federator_test.go b/internal/federation/federator_test.go index 5c07cfa85..755c9233b 100644 --- a/internal/federation/federator_test.go +++ b/internal/federation/federator_test.go @@ -18,8 +18,6 @@ package federation_test import ( - "context" - "github.com/stretchr/testify/suite" "code.superseriousbusiness.org/gotosocial/internal/federation" @@ -68,7 +66,7 @@ func (suite *FederatorStandardTestSuite) SetupTest() { // Ensure it's possible to deref // main key of foss satan. - fossSatanAS, err := suite.typeconverter.AccountToAS(context.Background(), suite.testAccounts["remote_account_1"]) + fossSatanAS, err := suite.typeconverter.AccountToAS(suite.T().Context(), suite.testAccounts["remote_account_1"]) if err != nil { suite.FailNow(err.Error()) } |
