From d5c9c4adc167cdb05e73f5105702cf340293e61c Mon Sep 17 00:00:00 2001 From: Daenney Date: Thu, 22 May 2025 12:26:11 +0200 Subject: [chore] Upgrade to Go 1.24 (#4187) * Set `go.mod` to 1.24 now that it's been out for 3 months. * Update all the test to use `testing.T.Context()`. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4187 Co-authored-by: Daenney Co-committed-by: Daenney --- internal/api/activitypub/users/inboxpost_test.go | 15 +++++++-------- internal/api/activitypub/users/outboxget_test.go | 7 +++---- internal/api/activitypub/users/repliesget_test.go | 7 +++---- internal/api/activitypub/users/statusget_test.go | 9 ++++----- internal/api/activitypub/users/userget_test.go | 13 ++++++------- internal/api/auth/authorize_test.go | 5 ++--- internal/api/auth/revoke_test.go | 7 +++---- internal/api/auth/token_test.go | 5 ++--- internal/api/client/accounts/accountupdate_test.go | 11 +++++------ internal/api/client/accounts/follow_test.go | 11 +++++------ .../admin/domainpermissionsubscriptiontest_test.go | 5 ++--- internal/api/client/admin/emojicreate_test.go | 7 +++---- internal/api/client/admin/emojidelete_test.go | 5 ++--- internal/api/client/admin/emojiupdate_test.go | 9 ++++----- internal/api/client/admin/mediacleanup_test.go | 7 +++---- internal/api/client/bookmarks/bookmarks_test.go | 9 ++++----- internal/api/client/filters/v1/filter_test.go | 4 ++-- internal/api/client/filters/v2/filter_test.go | 4 ++-- internal/api/client/followedtags/get_test.go | 3 +-- internal/api/client/followrequests/authorize_test.go | 3 +-- internal/api/client/followrequests/get_test.go | 11 +++++------ internal/api/client/followrequests/reject_test.go | 3 +-- internal/api/client/import/import_test.go | 5 ++--- internal/api/client/instance/instancepatch_test.go | 5 ++--- internal/api/client/instance/instancepeersget_test.go | 5 ++--- internal/api/client/lists/listaccountsadd_test.go | 3 +-- internal/api/client/mutes/mutesget_test.go | 7 +++---- .../api/client/notifications/notificationsget_test.go | 3 +-- internal/api/client/search/searchget_test.go | 11 +++++------ internal/api/client/statuses/statusboost_test.go | 7 +++---- internal/api/client/statuses/statuscreate_test.go | 3 +-- internal/api/client/statuses/statusfave_test.go | 3 +-- internal/api/client/statuses/statuspin_test.go | 5 ++--- internal/api/client/tags/follow_test.go | 3 +-- internal/api/client/tags/get_test.go | 3 +-- internal/api/client/tags/unfollow_test.go | 3 +-- internal/api/client/tokens/tokeninvalidate_test.go | 3 +-- internal/api/client/user/passwordchange_test.go | 3 +-- internal/api/fileserver/servefile_test.go | 19 +++++++++---------- internal/api/wellknown/webfinger/webfingerget_test.go | 5 ++--- 40 files changed, 109 insertions(+), 147 deletions(-) (limited to 'internal/api') diff --git a/internal/api/activitypub/users/inboxpost_test.go b/internal/api/activitypub/users/inboxpost_test.go index e00a705a0..81b21eafc 100644 --- a/internal/api/activitypub/users/inboxpost_test.go +++ b/internal/api/activitypub/users/inboxpost_test.go @@ -19,7 +19,6 @@ package users_test import ( "bytes" - "context" "encoding/json" "errors" "io" @@ -232,7 +231,7 @@ func (suite *InboxPostTestSuite) TestPostBlock() { ) if !testrig.WaitFor(func() bool { - dbBlock, err = suite.db.GetBlock(context.Background(), requestingAccount.ID, targetAccount.ID) + dbBlock, err = suite.db.GetBlock(suite.T().Context(), requestingAccount.ID, targetAccount.ID) return err == nil && dbBlock != nil }) { suite.FailNow("timed out waiting for block to be created") @@ -243,7 +242,7 @@ func (suite *InboxPostTestSuite) TestPostBlock() { // one of our instance users should be able to undo that block. func (suite *InboxPostTestSuite) TestPostUnblock() { var ( - ctx = context.Background() + ctx = suite.T().Context() requestingAccount = suite.testAccounts["remote_account_1"] targetAccount = suite.testAccounts["local_account_1"] blockID = "http://fossbros-anonymous.io/blocks/01H1462TPRTVG2RTQCTSQ7N6Q0" @@ -315,7 +314,7 @@ func (suite *InboxPostTestSuite) TestPostUpdate() { requestingAccount.Emojis = []*gtsmodel.Emoji{testEmoji} // Create an update from the account. - accountable, err := suite.tc.AccountToAS(context.Background(), requestingAccount) + accountable, err := suite.tc.AccountToAS(suite.T().Context(), requestingAccount) if err != nil { suite.FailNow(err.Error()) } @@ -344,7 +343,7 @@ func (suite *InboxPostTestSuite) TestPostUpdate() { if !testrig.WaitFor(func() bool { // displayName should be updated - dbUpdatedAccount, _ = suite.db.GetAccountByID(context.Background(), requestingAccount.ID) + dbUpdatedAccount, _ = suite.db.GetAccountByID(suite.T().Context(), requestingAccount.ID) return dbUpdatedAccount.DisplayName == updatedDisplayName }) { suite.FailNow("timed out waiting for account update") @@ -399,7 +398,7 @@ func (suite *InboxPostTestSuite) TestPostUpdate() { func (suite *InboxPostTestSuite) TestPostDelete() { var ( - ctx = context.Background() + ctx = suite.T().Context() requestingAccount = suite.testAccounts["remote_account_1"] targetAccount = suite.testAccounts["local_account_1"] activityID = requestingAccount.URI + "/some-new-activity/01FG9C441MCTW3R2W117V2PQK3" @@ -517,7 +516,7 @@ func (suite *InboxPostTestSuite) TestPostFromBlockedAccount() { ) // Create an update from the account. - accountable, err := suite.tc.AccountToAS(context.Background(), requestingAccount) + accountable, err := suite.tc.AccountToAS(suite.T().Context(), requestingAccount) if err != nil { suite.FailNow(err.Error()) } @@ -559,7 +558,7 @@ func (suite *InboxPostTestSuite) TestPostFromBlockedAccountToOtherAccount() { suite.signatureCheck, ) - _, err := suite.state.DB.GetStatusByURI(context.Background(), statusURI) + _, err := suite.state.DB.GetStatusByURI(suite.T().Context(), statusURI) suite.ErrorIs(err, db.ErrNoEntries) } diff --git a/internal/api/activitypub/users/outboxget_test.go b/internal/api/activitypub/users/outboxget_test.go index dc9c621a6..1290830b2 100644 --- a/internal/api/activitypub/users/outboxget_test.go +++ b/internal/api/activitypub/users/outboxget_test.go @@ -19,7 +19,6 @@ package users_test import ( "bytes" - "context" "encoding/json" "io/ioutil" "net/http" @@ -90,7 +89,7 @@ func (suite *OutboxGetTestSuite) TestGetOutbox() { err = json.Unmarshal(b, &m) suite.NoError(err) - t, err := streams.ToType(context.Background(), m) + t, err := streams.ToType(suite.T().Context(), m) suite.NoError(err) _, ok := t.(vocab.ActivityStreamsOrderedCollection) @@ -177,7 +176,7 @@ func (suite *OutboxGetTestSuite) TestGetOutboxFirstPage() { err = json.Unmarshal(b, &m) suite.NoError(err) - t, err := streams.ToType(context.Background(), m) + t, err := streams.ToType(suite.T().Context(), m) suite.NoError(err) _, ok := t.(vocab.ActivityStreamsOrderedCollectionPage) @@ -240,7 +239,7 @@ func (suite *OutboxGetTestSuite) TestGetOutboxNextPage() { err = json.Unmarshal(b, &m) suite.NoError(err) - t, err := streams.ToType(context.Background(), m) + t, err := streams.ToType(suite.T().Context(), m) suite.NoError(err) _, ok := t.(vocab.ActivityStreamsOrderedCollectionPage) diff --git a/internal/api/activitypub/users/repliesget_test.go b/internal/api/activitypub/users/repliesget_test.go index 9d2141811..5d3754a8c 100644 --- a/internal/api/activitypub/users/repliesget_test.go +++ b/internal/api/activitypub/users/repliesget_test.go @@ -19,7 +19,6 @@ package users_test import ( "bytes" - "context" "encoding/json" "io" "net/http" @@ -101,7 +100,7 @@ func (suite *RepliesGetTestSuite) TestGetReplies() { err = json.Unmarshal(b, &m) assert.NoError(suite.T(), err) - t, err := streams.ToType(context.Background(), m) + t, err := streams.ToType(suite.T().Context(), m) assert.NoError(suite.T(), err) _, ok := t.(vocab.ActivityStreamsOrderedCollection) @@ -172,7 +171,7 @@ func (suite *RepliesGetTestSuite) TestGetRepliesNext() { err = json.Unmarshal(b, &m) assert.NoError(suite.T(), err) - t, err := streams.ToType(context.Background(), m) + t, err := streams.ToType(suite.T().Context(), m) assert.NoError(suite.T(), err) page, ok := t.(vocab.ActivityStreamsOrderedCollectionPage) @@ -243,7 +242,7 @@ func (suite *RepliesGetTestSuite) TestGetRepliesLast() { err = json.Unmarshal(b, &m) assert.NoError(suite.T(), err) - t, err := streams.ToType(context.Background(), m) + t, err := streams.ToType(suite.T().Context(), m) assert.NoError(suite.T(), err) page, ok := t.(vocab.ActivityStreamsOrderedCollectionPage) diff --git a/internal/api/activitypub/users/statusget_test.go b/internal/api/activitypub/users/statusget_test.go index dc3aef5a7..275acdc02 100644 --- a/internal/api/activitypub/users/statusget_test.go +++ b/internal/api/activitypub/users/statusget_test.go @@ -18,7 +18,6 @@ package users_test import ( - "context" "encoding/json" "io/ioutil" "net/http" @@ -85,14 +84,14 @@ func (suite *StatusGetTestSuite) TestGetStatus() { err = json.Unmarshal(b, &m) suite.NoError(err) - t, err := streams.ToType(context.Background(), m) + t, err := streams.ToType(suite.T().Context(), m) suite.NoError(err) note, ok := t.(vocab.ActivityStreamsNote) suite.True(ok) // convert note to status - a, err := suite.tc.ASStatusToStatus(context.Background(), note) + a, err := suite.tc.ASStatusToStatus(suite.T().Context(), note) suite.NoError(err) suite.EqualValues(targetStatus.Content, a.Content) } @@ -144,14 +143,14 @@ func (suite *StatusGetTestSuite) TestGetStatusLowercase() { err = json.Unmarshal(b, &m) suite.NoError(err) - t, err := streams.ToType(context.Background(), m) + t, err := streams.ToType(suite.T().Context(), m) suite.NoError(err) note, ok := t.(vocab.ActivityStreamsNote) suite.True(ok) // convert note to status - a, err := suite.tc.ASStatusToStatus(context.Background(), note) + a, err := suite.tc.ASStatusToStatus(suite.T().Context(), note) suite.NoError(err) suite.EqualValues(targetStatus.Content, a.Content) } diff --git a/internal/api/activitypub/users/userget_test.go b/internal/api/activitypub/users/userget_test.go index 06bc46452..a9cba468f 100644 --- a/internal/api/activitypub/users/userget_test.go +++ b/internal/api/activitypub/users/userget_test.go @@ -18,7 +18,6 @@ package users_test import ( - "context" "encoding/json" "io/ioutil" "net/http" @@ -79,14 +78,14 @@ func (suite *UserGetTestSuite) TestGetUser() { err = json.Unmarshal(b, &m) suite.NoError(err) - t, err := streams.ToType(context.Background(), m) + t, err := streams.ToType(suite.T().Context(), m) suite.NoError(err) person, ok := t.(vocab.ActivityStreamsPerson) suite.True(ok) // convert person to account - a, err := suite.tc.ASRepresentationToAccount(context.Background(), person, "", "") + a, err := suite.tc.ASRepresentationToAccount(suite.T().Context(), person, "", "") suite.NoError(err) suite.EqualValues(targetAccount.Username, a.Username) } @@ -97,11 +96,11 @@ func (suite *UserGetTestSuite) TestGetUserPublicKeyDeleted() { userModule := users.New(suite.processor) targetAccount := suite.testAccounts["local_account_1"] - suite.processor.User().DeleteSelf(context.Background(), suite.testAccounts["local_account_1"]) + suite.processor.User().DeleteSelf(suite.T().Context(), suite.testAccounts["local_account_1"]) // wait for the account delete to be processed if !testrig.WaitFor(func() bool { - a, _ := suite.db.GetAccountByID(context.Background(), targetAccount.ID) + a, _ := suite.db.GetAccountByID(suite.T().Context(), targetAccount.ID) return !a.SuspendedAt.IsZero() }) { suite.FailNow("delete of account timed out") @@ -147,14 +146,14 @@ func (suite *UserGetTestSuite) TestGetUserPublicKeyDeleted() { err = json.Unmarshal(b, &m) suite.NoError(err) - t, err := streams.ToType(context.Background(), m) + t, err := streams.ToType(suite.T().Context(), m) suite.NoError(err) person, ok := t.(vocab.ActivityStreamsPerson) suite.True(ok) // convert person to account - a, err := suite.tc.ASRepresentationToAccount(context.Background(), person, "", "") + a, err := suite.tc.ASRepresentationToAccount(suite.T().Context(), person, "", "") suite.NoError(err) suite.EqualValues(targetAccount.Username, a.Username) } diff --git a/internal/api/auth/authorize_test.go b/internal/api/auth/authorize_test.go index b73f5e0e1..56a05416b 100644 --- a/internal/api/auth/authorize_test.go +++ b/internal/api/auth/authorize_test.go @@ -1,7 +1,6 @@ package auth_test import ( - "context" "fmt" "net/http" "testing" @@ -93,9 +92,9 @@ func (suite *AuthAuthorizeTestSuite) TestAccountAuthorizeHandler() { testCase.description = fmt.Sprintf("%s, %t, %s", user.Email, *user.Disabled, account.SuspendedAt) - err := suite.db.UpdateUser(context.Background(), user, columns...) + err := suite.db.UpdateUser(suite.T().Context(), user, columns...) suite.NoError(err) - err = suite.db.UpdateAccount(context.Background(), account) + err = suite.db.UpdateAccount(suite.T().Context(), account) suite.NoError(err) // call the handler diff --git a/internal/api/auth/revoke_test.go b/internal/api/auth/revoke_test.go index e482c8aac..3af573411 100644 --- a/internal/api/auth/revoke_test.go +++ b/internal/api/auth/revoke_test.go @@ -19,7 +19,6 @@ package auth_test import ( "bytes" - "context" "encoding/json" "io" "net/http" @@ -71,7 +70,7 @@ func (suite *RevokeTestSuite) TestRevokeOK() { // Ensure token now gone. _, err = suite.state.DB.GetTokenByAccess( - context.Background(), + suite.T().Context(), token.Access, ) suite.ErrorIs(err, db.ErrNoEntries) @@ -130,7 +129,7 @@ func (suite *RevokeTestSuite) TestRevokeWrongSecret() { // Ensure token still there. _, err = suite.state.DB.GetTokenByAccess( - context.Background(), + suite.T().Context(), token.Access, ) suite.NoError(err) @@ -188,7 +187,7 @@ func (suite *RevokeTestSuite) TestRevokeNoClientID() { // Ensure token still there. _, err = suite.state.DB.GetTokenByAccess( - context.Background(), + suite.T().Context(), token.Access, ) suite.NoError(err) diff --git a/internal/api/auth/token_test.go b/internal/api/auth/token_test.go index e333a8867..5d1aa4df5 100644 --- a/internal/api/auth/token_test.go +++ b/internal/api/auth/token_test.go @@ -18,7 +18,6 @@ package auth_test import ( - "context" "encoding/json" "io" "net/http" @@ -93,7 +92,7 @@ func (suite *TokenTestSuite) TestRetrieveClientCredentialsOK() { // there should be a token in the database now too dbToken := >smodel.Token{} - err = suite.db.GetWhere(context.Background(), []db.Where{{Key: "access", Value: t.AccessToken}}, dbToken) + err = suite.db.GetWhere(suite.T().Context(), []db.Where{{Key: "access", Value: t.AccessToken}}, dbToken) suite.NoError(err) suite.NotNil(dbToken) } @@ -204,7 +203,7 @@ func (suite *TokenTestSuite) TestRetrieveAuthorizationCodeOK() { suite.WithinDuration(time.Now(), time.Unix(t.CreatedAt, 0), 1*time.Minute) dbToken := >smodel.Token{} - err = suite.db.GetWhere(context.Background(), []db.Where{{Key: "access", Value: t.AccessToken}}, dbToken) + err = suite.db.GetWhere(suite.T().Context(), []db.Where{{Key: "access", Value: t.AccessToken}}, dbToken) suite.NoError(err) suite.NotNil(dbToken) } diff --git a/internal/api/client/accounts/accountupdate_test.go b/internal/api/client/accounts/accountupdate_test.go index 1ab9f1fce..b234617a7 100644 --- a/internal/api/client/accounts/accountupdate_test.go +++ b/internal/api/client/accounts/accountupdate_test.go @@ -18,7 +18,6 @@ package accounts_test import ( - "context" "encoding/json" "fmt" "io" @@ -289,7 +288,7 @@ func (suite *AccountUpdateTestSuite) TestUpdateAccountCache() { // Get the account first to make sure it's in the database // cache. When the account is updated via the PATCH handler, // it should invalidate the cache and return the new version. - if _, err := suite.db.GetAccountByID(context.Background(), suite.testAccounts["local_account_1"].ID); err != nil { + if _, err := suite.db.GetAccountByID(suite.T().Context(), suite.testAccounts["local_account_1"].ID); err != nil { suite.FailNow(err.Error()) } @@ -318,7 +317,7 @@ func (suite *AccountUpdateTestSuite) TestUpdateAccountDiscoverableForm() { suite.False(apimodelAccount.Discoverable) // Check the account in the database too. - dbZork, err := suite.db.GetAccountByID(context.Background(), apimodelAccount.ID) + dbZork, err := suite.db.GetAccountByID(suite.T().Context(), apimodelAccount.ID) suite.NoError(err) suite.False(*dbZork.Discoverable) } @@ -336,7 +335,7 @@ func (suite *AccountUpdateTestSuite) TestUpdateAccountDiscoverableFormData() { suite.False(apimodelAccount.Discoverable) // Check the account in the database too. - dbZork, err := suite.db.GetAccountByID(context.Background(), apimodelAccount.ID) + dbZork, err := suite.db.GetAccountByID(suite.T().Context(), apimodelAccount.ID) suite.NoError(err) suite.False(*dbZork.Discoverable) } @@ -355,7 +354,7 @@ func (suite *AccountUpdateTestSuite) TestUpdateAccountDiscoverableJSON() { suite.False(apimodelAccount.Discoverable) // Check the account in the database too. - dbZork, err := suite.db.GetAccountByID(context.Background(), apimodelAccount.ID) + dbZork, err := suite.db.GetAccountByID(suite.T().Context(), apimodelAccount.ID) suite.NoError(err) suite.False(*dbZork.Discoverable) } @@ -477,7 +476,7 @@ func (suite *AccountUpdateTestSuite) TestUpdateAccountSourceBadContentTypeFormDa suite.Equal(data["source[status_content_type]"][0], apimodelAccount.Source.StatusContentType) // Check the account in the database too. - dbAccount, err := suite.db.GetAccountByID(context.Background(), suite.testAccounts["local_account_1"].ID) + dbAccount, err := suite.db.GetAccountByID(suite.T().Context(), suite.testAccounts["local_account_1"].ID) if err != nil { suite.FailNow(err.Error()) } diff --git a/internal/api/client/accounts/follow_test.go b/internal/api/client/accounts/follow_test.go index d87b8c9b9..1d470f126 100644 --- a/internal/api/client/accounts/follow_test.go +++ b/internal/api/client/accounts/follow_test.go @@ -18,7 +18,6 @@ package accounts_test import ( - "context" "encoding/json" "fmt" "io" @@ -102,7 +101,7 @@ func (suite *FollowTestSuite) TestGetFollowersPageOldestToNewestLimit6() { } func (suite *FollowTestSuite) testGetFollowersPage(limit int, direction string) { - ctx := context.Background() + ctx := suite.T().Context() // The authed local account we are going to use for HTTP requests requestingAccount := suite.testAccounts["local_account_1"] @@ -304,7 +303,7 @@ func (suite *FollowTestSuite) TestGetFollowingPageOldestToNewestLimit6() { } func (suite *FollowTestSuite) testGetFollowingPage(limit int, direction string) { - ctx := context.Background() + ctx := suite.T().Context() // The authed local account we are going to use for HTTP requests requestingAccount := suite.testAccounts["local_account_1"] @@ -483,19 +482,19 @@ func (suite *FollowTestSuite) testGetFollowingPage(limit int, direction string) func (suite *FollowTestSuite) clearAccountRelations(id string) { // Esnure no account blocks exist between accounts. _ = suite.db.DeleteAccountBlocks( - context.Background(), + suite.T().Context(), id, ) // Ensure no account follows exist between accounts. _ = suite.db.DeleteAccountFollows( - context.Background(), + suite.T().Context(), id, ) // Ensure no account follow_requests exist between accounts. _ = suite.db.DeleteAccountFollowRequests( - context.Background(), + suite.T().Context(), id, ) } diff --git a/internal/api/client/admin/domainpermissionsubscriptiontest_test.go b/internal/api/client/admin/domainpermissionsubscriptiontest_test.go index 6d3356f0e..49ab3c330 100644 --- a/internal/api/client/admin/domainpermissionsubscriptiontest_test.go +++ b/internal/api/client/admin/domainpermissionsubscriptiontest_test.go @@ -19,7 +19,6 @@ package admin_test import ( "bytes" - "context" "encoding/json" "io" "net/http" @@ -41,7 +40,7 @@ type DomainPermissionSubscriptionTestTestSuite struct { func (suite *DomainPermissionSubscriptionTestTestSuite) TestDomainPermissionSubscriptionTestCSV() { var ( - ctx = context.Background() + ctx = suite.T().Context() testAccount = suite.testAccounts["admin_account"] permSub = >smodel.DomainPermissionSubscription{ ID: "01JGE681TQSBPAV59GZXPKE62H", @@ -129,7 +128,7 @@ func (suite *DomainPermissionSubscriptionTestTestSuite) TestDomainPermissionSubs func (suite *DomainPermissionSubscriptionTestTestSuite) TestDomainPermissionSubscriptionTestText() { var ( - ctx = context.Background() + ctx = suite.T().Context() testAccount = suite.testAccounts["admin_account"] permSub = >smodel.DomainPermissionSubscription{ ID: "01JGE681TQSBPAV59GZXPKE62H", diff --git a/internal/api/client/admin/emojicreate_test.go b/internal/api/client/admin/emojicreate_test.go index 1a6983c21..3970ced09 100644 --- a/internal/api/client/admin/emojicreate_test.go +++ b/internal/api/client/admin/emojicreate_test.go @@ -18,7 +18,6 @@ package admin_test import ( - "context" "encoding/json" "io/ioutil" "net/http" @@ -77,7 +76,7 @@ func (suite *EmojiCreateTestSuite) TestEmojiCreateNewCategory() { suite.True(apiEmoji.VisibleInPicker) // emoji should be in the db - dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(context.Background(), apiEmoji.Shortcode, "") + dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(suite.T().Context(), apiEmoji.Shortcode, "") suite.NoError(err) // check fields on the emoji @@ -150,7 +149,7 @@ func (suite *EmojiCreateTestSuite) TestEmojiCreateExistingCategory() { suite.True(apiEmoji.VisibleInPicker) // emoji should be in the db - dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(context.Background(), apiEmoji.Shortcode, "") + dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(suite.T().Context(), apiEmoji.Shortcode, "") suite.NoError(err) // check fields on the emoji @@ -223,7 +222,7 @@ func (suite *EmojiCreateTestSuite) TestEmojiCreateNoCategory() { suite.True(apiEmoji.VisibleInPicker) // emoji should be in the db - dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(context.Background(), apiEmoji.Shortcode, "") + dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(suite.T().Context(), apiEmoji.Shortcode, "") suite.NoError(err) // check fields on the emoji diff --git a/internal/api/client/admin/emojidelete_test.go b/internal/api/client/admin/emojidelete_test.go index c327bed94..1672a4e71 100644 --- a/internal/api/client/admin/emojidelete_test.go +++ b/internal/api/client/admin/emojidelete_test.go @@ -19,7 +19,6 @@ package admin_test import ( "bytes" - "context" "encoding/json" "io" "net/http" @@ -68,7 +67,7 @@ func (suite *EmojiDeleteTestSuite) TestEmojiDelete1() { }`, dst.String()) // emoji should no longer be in the db - dbEmoji, err := suite.db.GetEmojiByID(context.Background(), testEmoji.ID) + dbEmoji, err := suite.db.GetEmojiByID(suite.T().Context(), testEmoji.ID) suite.Nil(dbEmoji) suite.ErrorIs(err, db.ErrNoEntries) } @@ -91,7 +90,7 @@ func (suite *EmojiDeleteTestSuite) TestEmojiDelete2() { suite.Equal(`{"error":"Bad Request: emoji with id 01GD5KP5CQEE1R3X43Y1EHS2CW was not a local emoji, will not delete"}`, string(b)) // emoji should still be in the db - dbEmoji, err := suite.db.GetEmojiByID(context.Background(), testEmoji.ID) + dbEmoji, err := suite.db.GetEmojiByID(suite.T().Context(), testEmoji.ID) suite.NoError(err) suite.NotNil(dbEmoji) } diff --git a/internal/api/client/admin/emojiupdate_test.go b/internal/api/client/admin/emojiupdate_test.go index 91a9ec8f4..6fc8d826e 100644 --- a/internal/api/client/admin/emojiupdate_test.go +++ b/internal/api/client/admin/emojiupdate_test.go @@ -18,7 +18,6 @@ package admin_test import ( - "context" "encoding/json" "io" "net/http" @@ -84,7 +83,7 @@ func (suite *EmojiUpdateTestSuite) TestEmojiUpdateNewCategory() { suite.True(adminEmoji.VisibleInPicker) // emoji should be in the db - dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(context.Background(), adminEmoji.Shortcode, "") + dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(suite.T().Context(), adminEmoji.Shortcode, "") suite.NoError(err) // check fields on the emoji @@ -161,7 +160,7 @@ func (suite *EmojiUpdateTestSuite) TestEmojiUpdateSwitchCategory() { suite.True(adminEmoji.VisibleInPicker) // emoji should be in the db - dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(context.Background(), adminEmoji.Shortcode, "") + dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(suite.T().Context(), adminEmoji.Shortcode, "") suite.NoError(err) // check fields on the emoji @@ -239,7 +238,7 @@ func (suite *EmojiUpdateTestSuite) TestEmojiUpdateCopyRemoteToLocal() { suite.True(adminEmoji.VisibleInPicker) // emoji should be in the db - dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(context.Background(), adminEmoji.Shortcode, "") + dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(suite.T().Context(), adminEmoji.Shortcode, "") suite.NoError(err) // check fields on the emoji @@ -387,7 +386,7 @@ func (suite *EmojiUpdateTestSuite) TestEmojiUpdateModify() { suite.True(adminEmoji.VisibleInPicker) // emoji should be in the db - dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(context.Background(), adminEmoji.Shortcode, "") + dbEmoji, err := suite.db.GetEmojiByShortcodeDomain(suite.T().Context(), adminEmoji.Shortcode, "") suite.NoError(err) // check fields on the emoji diff --git a/internal/api/client/admin/mediacleanup_test.go b/internal/api/client/admin/mediacleanup_test.go index 8224b875f..8efef54c4 100644 --- a/internal/api/client/admin/mediacleanup_test.go +++ b/internal/api/client/admin/mediacleanup_test.go @@ -18,7 +18,6 @@ package admin_test import ( - "context" "net/http" "net/http/httptest" "testing" @@ -49,7 +48,7 @@ func (suite *MediaCleanupTestSuite) TestMediaCleanup() { // the attachment should be updated in the database if !testrig.WaitFor(func() bool { - if prunedAttachment, _ := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID); prunedAttachment != nil { + if prunedAttachment, _ := suite.db.GetAttachmentByID(suite.T().Context(), testAttachment.ID); prunedAttachment != nil { return !*prunedAttachment.Cached } return false @@ -74,7 +73,7 @@ func (suite *MediaCleanupTestSuite) TestMediaCleanupNoArg() { suite.Equal(http.StatusOK, recorder.Code) if !testrig.WaitFor(func() bool { - if prunedAttachment, _ := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID); prunedAttachment != nil { + if prunedAttachment, _ := suite.db.GetAttachmentByID(suite.T().Context(), testAttachment.ID); prunedAttachment != nil { return !*prunedAttachment.Cached } return false @@ -101,7 +100,7 @@ func (suite *MediaCleanupTestSuite) TestMediaCleanupNotOldEnough() { time.Sleep(1 * time.Second) // Get media we pruned - prunedAttachment, err := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID) + prunedAttachment, err := suite.db.GetAttachmentByID(suite.T().Context(), testAttachment.ID) suite.NoError(err) // the media should still be cached diff --git a/internal/api/client/bookmarks/bookmarks_test.go b/internal/api/client/bookmarks/bookmarks_test.go index 9210d6f1c..f056a05b5 100644 --- a/internal/api/client/bookmarks/bookmarks_test.go +++ b/internal/api/client/bookmarks/bookmarks_test.go @@ -18,7 +18,6 @@ package bookmarks_test import ( - "context" "encoding/json" "fmt" "io/ioutil" @@ -198,7 +197,7 @@ func (suite *BookmarkTestSuite) TestGetBookmarksMultiple() { testUser := suite.testUsers["local_account_1"] // Add a few extra bookmarks for this account. - ctx := context.Background() + ctx := suite.T().Context() for _, b := range []*gtsmodel.StatusBookmark{ { ID: "01GSZPDQYE9WZ26T501KMM876V", // oldest @@ -239,7 +238,7 @@ func (suite *BookmarkTestSuite) TestGetBookmarksMultiplePaging() { testUser := suite.testUsers["local_account_1"] // Add a few extra bookmarks for this account. - ctx := context.Background() + ctx := suite.T().Context() for _, b := range []*gtsmodel.StatusBookmark{ { ID: "01GSZPDQYE9WZ26T501KMM876V", // oldest @@ -280,7 +279,7 @@ func (suite *BookmarkTestSuite) TestGetBookmarksNone() { testUser := suite.testUsers["local_account_1"] // Remove all bookmarks for this account. - if err := suite.db.DeleteStatusBookmarks(context.Background(), "", testAccount.ID); err != nil { + if err := suite.db.DeleteStatusBookmarks(suite.T().Context(), "", testAccount.ID); err != nil { suite.FailNow(err.Error()) } @@ -299,7 +298,7 @@ func (suite *BookmarkTestSuite) TestGetBookmarksNonexistentStatus() { testUser := suite.testUsers["local_account_1"] // Add a few extra bookmarks for this account. - ctx := context.Background() + ctx := suite.T().Context() for _, b := range []*gtsmodel.StatusBookmark{ { ID: "01GSZPDQYE9WZ26T501KMM876V", // oldest diff --git a/internal/api/client/filters/v1/filter_test.go b/internal/api/client/filters/v1/filter_test.go index df182493e..7beb9313a 100644 --- a/internal/api/client/filters/v1/filter_test.go +++ b/internal/api/client/filters/v1/filter_test.go @@ -115,7 +115,7 @@ func (suite *FiltersTestSuite) TearDownTest() { } func (suite *FiltersTestSuite) openHomeStream(account *gtsmodel.Account) *stream.Stream { - stream, err := suite.processor.Stream().Open(context.Background(), account, stream.TimelineHome) + stream, err := suite.processor.Stream().Open(suite.T().Context(), account, stream.TimelineHome) if err != nil { suite.FailNow(err.Error()) } @@ -129,7 +129,7 @@ func (suite *FiltersTestSuite) checkStreamed( expectEventType string, ) { // Set a 5s timeout on context. - ctx := context.Background() + ctx := suite.T().Context() ctx, cncl := context.WithTimeout(ctx, time.Second*5) defer cncl() diff --git a/internal/api/client/filters/v2/filter_test.go b/internal/api/client/filters/v2/filter_test.go index 038205460..6e9e4ef07 100644 --- a/internal/api/client/filters/v2/filter_test.go +++ b/internal/api/client/filters/v2/filter_test.go @@ -114,7 +114,7 @@ func (suite *FiltersTestSuite) TearDownTest() { } func (suite *FiltersTestSuite) openHomeStream(account *gtsmodel.Account) *stream.Stream { - stream, err := suite.processor.Stream().Open(context.Background(), account, stream.TimelineHome) + stream, err := suite.processor.Stream().Open(suite.T().Context(), account, stream.TimelineHome) if err != nil { suite.FailNow(err.Error()) } @@ -128,7 +128,7 @@ func (suite *FiltersTestSuite) checkStreamed( expectEventType string, ) { // Set a 5s timeout on context. - ctx := context.Background() + ctx := suite.T().Context() ctx, cncl := context.WithTimeout(ctx, time.Second*5) defer cncl() diff --git a/internal/api/client/followedtags/get_test.go b/internal/api/client/followedtags/get_test.go index 41a8b43d8..1f4f21cff 100644 --- a/internal/api/client/followedtags/get_test.go +++ b/internal/api/client/followedtags/get_test.go @@ -18,7 +18,6 @@ package followedtags_test import ( - "context" "encoding/json" "io" "net/http" @@ -94,7 +93,7 @@ func (suite *FollowedTagsTestSuite) TestGet() { testTag := suite.testTags["welcome"] // Follow an existing tag. - if err := suite.db.PutFollowedTag(context.Background(), testAccount.ID, testTag.ID); err != nil { + if err := suite.db.PutFollowedTag(suite.T().Context(), testAccount.ID, testTag.ID); err != nil { suite.FailNow(err.Error()) } diff --git a/internal/api/client/followrequests/authorize_test.go b/internal/api/client/followrequests/authorize_test.go index 712263e86..0f938434e 100644 --- a/internal/api/client/followrequests/authorize_test.go +++ b/internal/api/client/followrequests/authorize_test.go @@ -19,7 +19,6 @@ package followrequests_test import ( "bytes" - "context" "encoding/json" "fmt" "io/ioutil" @@ -52,7 +51,7 @@ func (suite *AuthorizeTestSuite) TestAuthorize() { TargetAccountID: targetAccount.ID, } - err := suite.db.Put(context.Background(), fr) + err := suite.db.Put(suite.T().Context(), fr) suite.NoError(err) recorder := httptest.NewRecorder() diff --git a/internal/api/client/followrequests/get_test.go b/internal/api/client/followrequests/get_test.go index ad0fc839d..2589aba36 100644 --- a/internal/api/client/followrequests/get_test.go +++ b/internal/api/client/followrequests/get_test.go @@ -19,7 +19,6 @@ package followrequests_test import ( "bytes" - "context" "encoding/json" "fmt" "io" @@ -59,7 +58,7 @@ func (suite *GetTestSuite) TestGet() { TargetAccountID: targetAccount.ID, } - err := suite.db.Put(context.Background(), fr) + err := suite.db.Put(suite.T().Context(), fr) suite.NoError(err) recorder := httptest.NewRecorder() @@ -134,7 +133,7 @@ func (suite *GetTestSuite) TestGetPageOldestToNewestLimit6() { } func (suite *GetTestSuite) testGetPage(limit int, direction string) { - ctx := context.Background() + ctx := suite.T().Context() // The authed local account we are going to use for HTTP requests requestingAccount := suite.testAccounts["local_account_1"] @@ -312,19 +311,19 @@ func (suite *GetTestSuite) testGetPage(limit int, direction string) { func (suite *GetTestSuite) clearAccountRelations(id string) { // Esnure no account blocks exist between accounts. _ = suite.db.DeleteAccountBlocks( - context.Background(), + suite.T().Context(), id, ) // Ensure no account follows exist between accounts. _ = suite.db.DeleteAccountFollows( - context.Background(), + suite.T().Context(), id, ) // Ensure no account follow_requests exist between accounts. _ = suite.db.DeleteAccountFollowRequests( - context.Background(), + suite.T().Context(), id, ) } diff --git a/internal/api/client/followrequests/reject_test.go b/internal/api/client/followrequests/reject_test.go index 3d5f93286..9ef6dd34a 100644 --- a/internal/api/client/followrequests/reject_test.go +++ b/internal/api/client/followrequests/reject_test.go @@ -19,7 +19,6 @@ package followrequests_test import ( "bytes" - "context" "encoding/json" "fmt" "io/ioutil" @@ -52,7 +51,7 @@ func (suite *RejectTestSuite) TestReject() { TargetAccountID: targetAccount.ID, } - err := suite.db.Put(context.Background(), fr) + err := suite.db.Put(suite.T().Context(), fr) suite.NoError(err) recorder := httptest.NewRecorder() diff --git a/internal/api/client/import/import_test.go b/internal/api/client/import/import_test.go index d6abcf242..ed4b07e39 100644 --- a/internal/api/client/import/import_test.go +++ b/internal/api/client/import/import_test.go @@ -19,7 +19,6 @@ package importdata_test import ( "bytes" - "context" "io" "net/http" "net/http/httptest" @@ -144,7 +143,7 @@ func (suite *ImportTestSuite) TearDownTest() { func (suite *ImportTestSuite) TestImportFollows() { var ( - ctx = context.Background() + ctx = suite.T().Context() testAccount = suite.testAccounts["local_account_1"] ) @@ -199,7 +198,7 @@ admin@localhost:8080,true func (suite *ImportTestSuite) TestImportMutes() { var ( - ctx = context.Background() + ctx = suite.T().Context() testAccount = suite.testAccounts["local_account_1"] ) diff --git a/internal/api/client/instance/instancepatch_test.go b/internal/api/client/instance/instancepatch_test.go index 1139ac6d2..dc3eb84b1 100644 --- a/internal/api/client/instance/instancepatch_test.go +++ b/internal/api/client/instance/instancepatch_test.go @@ -19,7 +19,6 @@ package instance_test import ( "bytes" - "context" "encoding/json" "io" "net/http" @@ -721,7 +720,7 @@ func (suite *InstancePatchTestSuite) TestInstancePatch8() { suite.FailNow(err.Error()) } - instanceAccount, err := suite.db.GetInstanceAccount(context.Background(), "") + instanceAccount, err := suite.db.GetInstanceAccount(suite.T().Context(), "") if err != nil { suite.FailNow(err.Error()) } @@ -859,7 +858,7 @@ func (suite *InstancePatchTestSuite) TestInstancePatch8() { }`, dst.String()) // extra bonus: check the v2 model thumbnail after the patch - instanceV2, err := suite.processor.InstanceGetV2(context.Background()) + instanceV2, err := suite.processor.InstanceGetV2(suite.T().Context()) if err != nil { suite.FailNow(err.Error()) } diff --git a/internal/api/client/instance/instancepeersget_test.go b/internal/api/client/instance/instancepeersget_test.go index 3c7f1f665..18d4761ac 100644 --- a/internal/api/client/instance/instancepeersget_test.go +++ b/internal/api/client/instance/instancepeersget_test.go @@ -19,7 +19,6 @@ package instance_test import ( "bytes" - "context" "encoding/json" "fmt" "io" @@ -249,7 +248,7 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllowed() { } func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllWithObfuscated() { - err := suite.db.Put(context.Background(), >smodel.DomainBlock{ + err := suite.db.Put(suite.T().Context(), >smodel.DomainBlock{ ID: "01G633XTNK51GBADQZFZQDP6WR", CreatedAt: testrig.TimeMustParse("2021-06-09T12:34:55+02:00"), UpdatedAt: testrig.TimeMustParse("2021-06-09T12:34:55+02:00"), @@ -300,7 +299,7 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllWithObfuscated() } func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllWithObfuscatedFlat() { - err := suite.db.Put(context.Background(), >smodel.DomainBlock{ + err := suite.db.Put(suite.T().Context(), >smodel.DomainBlock{ ID: "01G633XTNK51GBADQZFZQDP6WR", CreatedAt: testrig.TimeMustParse("2021-06-09T12:34:55+02:00"), UpdatedAt: testrig.TimeMustParse("2021-06-09T12:34:55+02:00"), diff --git a/internal/api/client/lists/listaccountsadd_test.go b/internal/api/client/lists/listaccountsadd_test.go index 354019f46..036a81d4c 100644 --- a/internal/api/client/lists/listaccountsadd_test.go +++ b/internal/api/client/lists/listaccountsadd_test.go @@ -19,7 +19,6 @@ package lists_test import ( "bytes" - "context" "fmt" "io" "net/http" @@ -106,7 +105,7 @@ func (suite *ListAccountsAddTestSuite) TestPostListAccountOK() { // Remove turtle from the list. if err := suite.db.DeleteListEntry( - context.Background(), + suite.T().Context(), entry.ListID, entry.FollowID, ); err != nil { diff --git a/internal/api/client/mutes/mutesget_test.go b/internal/api/client/mutes/mutesget_test.go index 978c1a845..e53ab364a 100644 --- a/internal/api/client/mutes/mutesget_test.go +++ b/internal/api/client/mutes/mutesget_test.go @@ -18,7 +18,6 @@ package mutes_test import ( - "context" "encoding/json" "io" "net/http" @@ -96,7 +95,7 @@ func (suite *MutesTestSuite) TestGetMutedAccounts() { AccountID: suite.testAccounts["local_account_1"].ID, TargetAccountID: suite.testAccounts["local_account_2"].ID, } - err := suite.db.PutMute(context.Background(), mute1) + err := suite.db.PutMute(suite.T().Context(), mute1) if err != nil { suite.FailNow(err.Error()) } @@ -107,7 +106,7 @@ func (suite *MutesTestSuite) TestGetMutedAccounts() { AccountID: suite.testAccounts["local_account_1"].ID, TargetAccountID: suite.testAccounts["remote_account_1"].ID, } - err = suite.db.PutMute(context.Background(), mute2) + err = suite.db.PutMute(suite.T().Context(), mute2) if err != nil { suite.FailNow(err.Error()) } @@ -141,7 +140,7 @@ func (suite *MutesTestSuite) TestIndefinitelyMutedAccountSerializesMuteExpiratio AccountID: suite.testAccounts["local_account_1"].ID, TargetAccountID: suite.testAccounts["remote_account_1"].ID, } - err := suite.db.PutMute(context.Background(), mute) + err := suite.db.PutMute(suite.T().Context(), mute) if err != nil { suite.FailNow(err.Error()) } diff --git a/internal/api/client/notifications/notificationsget_test.go b/internal/api/client/notifications/notificationsget_test.go index 78e746f79..9032d6322 100644 --- a/internal/api/client/notifications/notificationsget_test.go +++ b/internal/api/client/notifications/notificationsget_test.go @@ -18,7 +18,6 @@ package notifications_test import ( - "context" "encoding/json" "io" "net/http" @@ -164,7 +163,7 @@ func (suite *NotificationsTestSuite) addMoreNotifications(testAccount *gtsmodel. OriginAccountID: suite.testAccounts["remote_account_2"].ID, }, } { - if err := suite.db.Put(context.Background(), b); err != nil { + if err := suite.db.Put(suite.T().Context(), b); err != nil { suite.FailNow(err.Error()) } } diff --git a/internal/api/client/search/searchget_test.go b/internal/api/client/search/searchget_test.go index b978c0d3f..651d5301d 100644 --- a/internal/api/client/search/searchget_test.go +++ b/internal/api/client/search/searchget_test.go @@ -18,7 +18,6 @@ package search_test import ( - "context" "crypto/rand" "crypto/rsa" "encoding/json" @@ -160,7 +159,7 @@ func (suite *SearchGetTestSuite) bodgeLocalInstance(domain string) { // Set username of instance account to given domain. instanceAccount.Username = domain - if err := suite.db.UpdateAccount(context.Background(), instanceAccount, "username"); err != nil { + if err := suite.db.UpdateAccount(suite.T().Context(), instanceAccount, "username"); err != nil { suite.FailNow(err.Error()) } } @@ -1389,7 +1388,7 @@ func (suite *SearchGetTestSuite) TestSearchRemoteInstanceAccountPartial() { suite.FailNow(err.Error()) } - if err := suite.db.PutAccount(context.Background(), >smodel.Account{ + if err := suite.db.PutAccount(suite.T().Context(), >smodel.Account{ ID: "01H6RWPG8T6DNW6VNXPBCJBH5S", Username: theirDomain, Domain: theirDomain, @@ -1724,7 +1723,7 @@ func (suite *SearchGetTestSuite) TestSearchBlockedAccountFullNamestring() { // Block the account // we're about to search. if err := suite.db.PutBlock( - context.Background(), + suite.T().Context(), >smodel.Block{ ID: id.NewULID(), URI: "https://example.org/nooooooo", @@ -1788,7 +1787,7 @@ func (suite *SearchGetTestSuite) TestSearchBlockedAccountPartialNamestring() { // Block the account // we're about to search. if err := suite.db.PutBlock( - context.Background(), + suite.T().Context(), >smodel.Block{ ID: id.NewULID(), URI: "https://example.org/nooooooo", @@ -1849,7 +1848,7 @@ func (suite *SearchGetTestSuite) TestSearchBlockedAccountURI() { // Block the account // we're about to search. if err := suite.db.PutBlock( - context.Background(), + suite.T().Context(), >smodel.Block{ ID: id.NewULID(), URI: "https://example.org/nooooooo", diff --git a/internal/api/client/statuses/statusboost_test.go b/internal/api/client/statuses/statusboost_test.go index abbe4857b..a108c436c 100644 --- a/internal/api/client/statuses/statusboost_test.go +++ b/internal/api/client/statuses/statusboost_test.go @@ -16,7 +16,6 @@ package statuses_test import ( - "context" "net/http" "net/http/httptest" "strings" @@ -499,7 +498,7 @@ func (suite *StatusBoostTestSuite) TestPostUnboostable() { func (suite *StatusBoostTestSuite) TestPostNotVisible() { // Stop local_account_2 following zork. err := suite.db.DeleteFollowByID( - context.Background(), + suite.T().Context(), suite.testFollows["local_account_2_local_account_1"].ID, ) if err != nil { @@ -714,7 +713,7 @@ func (suite *StatusBoostTestSuite) TestPostBoostImplicitAccept() { // Target status should no // longer be pending approval. dbStatus, err := suite.state.DB.GetStatusByID( - context.Background(), + suite.T().Context(), targetStatus.ID, ) if err != nil { @@ -725,7 +724,7 @@ func (suite *StatusBoostTestSuite) TestPostBoostImplicitAccept() { // There should be an Accept // stored for the target status. intReq, err := suite.state.DB.GetInteractionRequestByInteractionURI( - context.Background(), targetStatus.URI, + suite.T().Context(), targetStatus.URI, ) if err != nil { suite.FailNow(err.Error()) diff --git a/internal/api/client/statuses/statuscreate_test.go b/internal/api/client/statuses/statuscreate_test.go index 60069d362..548eced29 100644 --- a/internal/api/client/statuses/statuscreate_test.go +++ b/internal/api/client/statuses/statuscreate_test.go @@ -19,7 +19,6 @@ package statuses_test import ( "bytes" - "context" "encoding/json" "fmt" "io" @@ -671,7 +670,7 @@ func (suite *StatusCreateTestSuite) TestMentionUnknownAccount() { // so it gets looked up again when we mention it. remoteAccount := suite.testAccounts["remote_account_1"] if err := suite.db.DeleteAccount( - context.Background(), + suite.T().Context(), remoteAccount.ID, ); err != nil { suite.FailNow(err.Error()) diff --git a/internal/api/client/statuses/statusfave_test.go b/internal/api/client/statuses/statusfave_test.go index 11c03cc5b..515b66a3c 100644 --- a/internal/api/client/statuses/statusfave_test.go +++ b/internal/api/client/statuses/statusfave_test.go @@ -18,7 +18,6 @@ package statuses_test import ( - "context" "net/http" "net/http/httptest" "strings" @@ -203,7 +202,7 @@ func (suite *StatusFaveTestSuite) TestPostUnfaveable() { // Fave a status that's pending approval by us. func (suite *StatusFaveTestSuite) TestPostFaveImplicitAccept() { var ( - ctx = context.Background() + ctx = suite.T().Context() targetStatus = suite.testStatuses["admin_account_status_5"] app = suite.testApplications["application_1"] token = suite.testTokens["local_account_2"] diff --git a/internal/api/client/statuses/statuspin_test.go b/internal/api/client/statuses/statuspin_test.go index 87650dd43..cbefb3977 100644 --- a/internal/api/client/statuses/statuspin_test.go +++ b/internal/api/client/statuses/statuspin_test.go @@ -18,7 +18,6 @@ package statuses_test import ( - "context" "encoding/json" "io/ioutil" "net/http" @@ -135,7 +134,7 @@ func (suite *StatusPinTestSuite) TestPinStatusTwiceError() { testAccount := new(gtsmodel.Account) *testAccount = *suite.testAccounts["local_account_1"] - if err := suite.db.UpdateStatus(context.Background(), targetStatus, "pinned_at"); err != nil { + if err := suite.db.UpdateStatus(suite.T().Context(), targetStatus, "pinned_at"); err != nil { suite.FailNow(err.Error()) } @@ -171,7 +170,7 @@ func (suite *StatusPinTestSuite) TestPinStatusTooManyPins() { *testAccount = *suite.testAccounts["local_account_1"] // Spam 10 pinned statuses into the database. - ctx := context.Background() + ctx := suite.T().Context() for i := range make([]interface{}, 10) { status := >smodel.Status{ ID: id.NewULID(), diff --git a/internal/api/client/tags/follow_test.go b/internal/api/client/tags/follow_test.go index 87f903452..ad58c4daa 100644 --- a/internal/api/client/tags/follow_test.go +++ b/internal/api/client/tags/follow_test.go @@ -18,7 +18,6 @@ package tags_test import ( - "context" "net/http" "code.superseriousbusiness.org/gotosocial/internal/api/client/tags" @@ -65,7 +64,7 @@ func (suite *TagsTestSuite) TestFollowIdempotent() { testTag := suite.testTags["welcome"] // Setup: follow an existing tag. - if err := suite.db.PutFollowedTag(context.Background(), testAccount.ID, testTag.ID); err != nil { + if err := suite.db.PutFollowedTag(suite.T().Context(), testAccount.ID, testTag.ID); err != nil { suite.FailNow(err.Error()) } diff --git a/internal/api/client/tags/get_test.go b/internal/api/client/tags/get_test.go index d8052822e..3b068c5de 100644 --- a/internal/api/client/tags/get_test.go +++ b/internal/api/client/tags/get_test.go @@ -18,7 +18,6 @@ package tags_test import ( - "context" "net/http" "code.superseriousbusiness.org/gotosocial/internal/api/client/tags" @@ -50,7 +49,7 @@ func (suite *TagsTestSuite) TestGetFollowed() { testTag := suite.testTags["welcome"] // Setup: follow an existing tag. - if err := suite.db.PutFollowedTag(context.Background(), testAccount.ID, testTag.ID); err != nil { + if err := suite.db.PutFollowedTag(suite.T().Context(), testAccount.ID, testTag.ID); err != nil { suite.FailNow(err.Error()) } diff --git a/internal/api/client/tags/unfollow_test.go b/internal/api/client/tags/unfollow_test.go index 5b748a8aa..188840773 100644 --- a/internal/api/client/tags/unfollow_test.go +++ b/internal/api/client/tags/unfollow_test.go @@ -18,7 +18,6 @@ package tags_test import ( - "context" "net/http" "code.superseriousbusiness.org/gotosocial/internal/api/client/tags" @@ -49,7 +48,7 @@ func (suite *TagsTestSuite) TestUnfollow() { testTag := suite.testTags["welcome"] // Setup: follow an existing tag. - if err := suite.db.PutFollowedTag(context.Background(), testAccount.ID, testTag.ID); err != nil { + if err := suite.db.PutFollowedTag(suite.T().Context(), testAccount.ID, testTag.ID); err != nil { suite.FailNow(err.Error()) } diff --git a/internal/api/client/tokens/tokeninvalidate_test.go b/internal/api/client/tokens/tokeninvalidate_test.go index 2e726bd50..6a8867cf5 100644 --- a/internal/api/client/tokens/tokeninvalidate_test.go +++ b/internal/api/client/tokens/tokeninvalidate_test.go @@ -18,7 +18,6 @@ package tokens_test import ( - "context" "net/http" "testing" @@ -58,7 +57,7 @@ func (suite *TokenInvalidateTestSuite) TestTokenInvalidate() { // Check database for token we // just invalidated, should be gone. _, err := suite.testStructs.State.DB.GetTokenByID( - context.Background(), testToken.ID, + suite.T().Context(), testToken.ID, ) suite.ErrorIs(err, db.ErrNoEntries) } diff --git a/internal/api/client/user/passwordchange_test.go b/internal/api/client/user/passwordchange_test.go index 8fee821c0..4cf746400 100644 --- a/internal/api/client/user/passwordchange_test.go +++ b/internal/api/client/user/passwordchange_test.go @@ -18,7 +18,6 @@ package user_test import ( - "context" "io" "net/http" "testing" @@ -45,7 +44,7 @@ func (suite *PasswordChangeTestSuite) TestPasswordChangePOST() { suite.EqualValues(http.StatusOK, code) dbUser := >smodel.User{} - err := suite.db.GetByID(context.Background(), suite.testUsers["local_account_1"].ID, dbUser) + err := suite.db.GetByID(suite.T().Context(), suite.testUsers["local_account_1"].ID, dbUser) if err != nil { suite.FailNow(err.Error()) } diff --git a/internal/api/fileserver/servefile_test.go b/internal/api/fileserver/servefile_test.go index cfaa73515..e07c204eb 100644 --- a/internal/api/fileserver/servefile_test.go +++ b/internal/api/fileserver/servefile_test.go @@ -18,7 +18,6 @@ package fileserver_test import ( - "context" "io" "net/http" "net/http/httptest" @@ -74,7 +73,7 @@ func (suite *ServeFileTestSuite) GetFile( // UncacheAttachment is a convenience function that uncaches the targetAttachment by // removing its associated files from storage, and updating the database. func (suite *ServeFileTestSuite) UncacheAttachment(targetAttachment *gtsmodel.MediaAttachment) { - ctx := context.Background() + ctx := suite.T().Context() cached := false targetAttachment.Cached = &cached @@ -93,7 +92,7 @@ func (suite *ServeFileTestSuite) UncacheAttachment(targetAttachment *gtsmodel.Me func (suite *ServeFileTestSuite) TestServeOriginalLocalFileOK() { targetAttachment := >smodel.MediaAttachment{} *targetAttachment = *suite.testAttachments["admin_account_status_1_attachment_1"] - fileInStorage, err := suite.storage.Get(context.Background(), targetAttachment.File.Path) + fileInStorage, err := suite.storage.Get(suite.T().Context(), targetAttachment.File.Path) if err != nil { suite.FailNow(err.Error()) } @@ -113,7 +112,7 @@ func (suite *ServeFileTestSuite) TestServeOriginalLocalFileOK() { func (suite *ServeFileTestSuite) TestServeSmallLocalFileOK() { targetAttachment := >smodel.MediaAttachment{} *targetAttachment = *suite.testAttachments["admin_account_status_1_attachment_1"] - fileInStorage, err := suite.storage.Get(context.Background(), targetAttachment.Thumbnail.Path) + fileInStorage, err := suite.storage.Get(suite.T().Context(), targetAttachment.Thumbnail.Path) if err != nil { suite.FailNow(err.Error()) } @@ -133,7 +132,7 @@ func (suite *ServeFileTestSuite) TestServeSmallLocalFileOK() { func (suite *ServeFileTestSuite) TestServeOriginalRemoteFileOK() { targetAttachment := >smodel.MediaAttachment{} *targetAttachment = *suite.testAttachments["remote_account_1_status_1_attachment_1"] - fileInStorage, err := suite.storage.Get(context.Background(), targetAttachment.File.Path) + fileInStorage, err := suite.storage.Get(suite.T().Context(), targetAttachment.File.Path) if err != nil { suite.FailNow(err.Error()) } @@ -153,7 +152,7 @@ func (suite *ServeFileTestSuite) TestServeOriginalRemoteFileOK() { func (suite *ServeFileTestSuite) TestServeSmallRemoteFileOK() { targetAttachment := >smodel.MediaAttachment{} *targetAttachment = *suite.testAttachments["remote_account_1_status_1_attachment_1"] - fileInStorage, err := suite.storage.Get(context.Background(), targetAttachment.Thumbnail.Path) + fileInStorage, err := suite.storage.Get(suite.T().Context(), targetAttachment.Thumbnail.Path) if err != nil { suite.FailNow(err.Error()) } @@ -173,7 +172,7 @@ func (suite *ServeFileTestSuite) TestServeSmallRemoteFileOK() { func (suite *ServeFileTestSuite) TestServeOriginalRemoteFileRecache() { targetAttachment := >smodel.MediaAttachment{} *targetAttachment = *suite.testAttachments["remote_account_1_status_1_attachment_1"] - fileInStorage, err := suite.storage.Get(context.Background(), targetAttachment.File.Path) + fileInStorage, err := suite.storage.Get(suite.T().Context(), targetAttachment.File.Path) if err != nil { suite.FailNow(err.Error()) } @@ -196,7 +195,7 @@ func (suite *ServeFileTestSuite) TestServeOriginalRemoteFileRecache() { func (suite *ServeFileTestSuite) TestServeSmallRemoteFileRecache() { targetAttachment := >smodel.MediaAttachment{} *targetAttachment = *suite.testAttachments["remote_account_1_status_1_attachment_1"] - fileInStorage, err := suite.storage.Get(context.Background(), targetAttachment.Thumbnail.Path) + fileInStorage, err := suite.storage.Get(suite.T().Context(), targetAttachment.Thumbnail.Path) if err != nil { suite.FailNow(err.Error()) } @@ -223,7 +222,7 @@ func (suite *ServeFileTestSuite) TestServeOriginalRemoteFileRecacheNotFound() { // uncache the attachment *and* set the remote URL to something that will return a 404 suite.UncacheAttachment(targetAttachment) targetAttachment.RemoteURL = "http://nothing.at.this.url/weeeeeeeee" - if err := suite.db.UpdateByID(context.Background(), targetAttachment, targetAttachment.ID, "remote_url"); err != nil { + if err := suite.db.UpdateByID(suite.T().Context(), targetAttachment, targetAttachment.ID, "remote_url"); err != nil { suite.FailNow(err.Error()) } @@ -244,7 +243,7 @@ func (suite *ServeFileTestSuite) TestServeSmallRemoteFileRecacheNotFound() { // uncache the attachment *and* set the remote URL to something that will return a 404 suite.UncacheAttachment(targetAttachment) targetAttachment.RemoteURL = "http://nothing.at.this.url/weeeeeeeee" - if err := suite.db.UpdateByID(context.Background(), targetAttachment, targetAttachment.ID, "remote_url"); err != nil { + if err := suite.db.UpdateByID(suite.T().Context(), targetAttachment, targetAttachment.ID, "remote_url"); err != nil { suite.FailNow(err.Error()) } diff --git a/internal/api/wellknown/webfinger/webfingerget_test.go b/internal/api/wellknown/webfinger/webfingerget_test.go index a0a8aa22f..0ad35d4d9 100644 --- a/internal/api/wellknown/webfinger/webfingerget_test.go +++ b/internal/api/wellknown/webfinger/webfingerget_test.go @@ -19,7 +19,6 @@ package webfinger_test import ( "bytes" - "context" "crypto/rand" "crypto/rsa" "encoding/json" @@ -129,11 +128,11 @@ func (suite *WebfingerGetTestSuite) funkifyAccountDomain(host string, accountDom PublicKeyURI: "http://" + host + "/users/new_account_domain_user/main-key", } - if err := suite.db.PutAccount(context.Background(), targetAccount); err != nil { + if err := suite.db.PutAccount(suite.T().Context(), targetAccount); err != nil { suite.FailNow(err.Error()) } - if err := suite.db.PutAccountSettings(context.Background(), >smodel.AccountSettings{AccountID: targetAccount.ID}); err != nil { + if err := suite.db.PutAccountSettings(suite.T().Context(), >smodel.AccountSettings{AccountID: targetAccount.ID}); err != nil { suite.FailNow(err.Error()) } -- cgit v1.2.3