[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 <git@noreply.sourcery.dny.nu>
Co-committed-by: Daenney <git@noreply.sourcery.dny.nu>
This commit is contained in:
Daenney 2025-05-22 12:26:11 +02:00 committed by kim
commit d5c9c4adc1
175 changed files with 857 additions and 1004 deletions

View file

@ -67,7 +67,7 @@ type AccountStandardTestSuite struct {
}
func (suite *AccountStandardTestSuite) getClientMsg(timeout time.Duration) (*messages.FromClientAPI, bool) {
ctx := context.Background()
ctx := suite.T().Context()
ctx, cncl := context.WithTimeout(ctx, timeout)
defer cncl()
return suite.state.Workers.Client.Queue.PopCtx(ctx)

View file

@ -18,7 +18,6 @@
package account_test
import (
"context"
"slices"
"testing"
@ -145,7 +144,7 @@ func (suite *AliasTestSuite) TestAliasAccount() {
},
} {
var (
ctx = context.Background()
ctx = suite.T().Context()
testAcct = new(gtsmodel.Account)
)

View file

@ -18,7 +18,6 @@
package account_test
import (
"context"
"net"
"testing"
"time"
@ -32,7 +31,7 @@ type AccountDeleteTestSuite struct {
}
func (suite *AccountDeleteTestSuite) TestAccountDeleteLocal() {
ctx := context.Background()
ctx := suite.T().Context()
// Keep a reference around to the original account
// and user, before the delete was processed.

View file

@ -18,7 +18,6 @@
package account_test
import (
"context"
"testing"
"time"
@ -33,7 +32,7 @@ type FollowTestSuite struct {
}
func (suite *FollowTestSuite) TestUpdateExistingFollowChangeBoth() {
ctx := context.Background()
ctx := suite.T().Context()
requestingAccount := suite.testAccounts["local_account_1"]
targetAccount := suite.testAccounts["admin_account"]
@ -54,7 +53,7 @@ func (suite *FollowTestSuite) TestUpdateExistingFollowChangeBoth() {
}
func (suite *FollowTestSuite) TestUpdateExistingFollowChangeNotifyIgnoreReblogs() {
ctx := context.Background()
ctx := suite.T().Context()
requestingAccount := suite.testAccounts["local_account_1"]
targetAccount := suite.testAccounts["admin_account"]
@ -74,7 +73,7 @@ func (suite *FollowTestSuite) TestUpdateExistingFollowChangeNotifyIgnoreReblogs(
}
func (suite *FollowTestSuite) TestUpdateExistingFollowChangeNotifySetReblogs() {
ctx := context.Background()
ctx := suite.T().Context()
requestingAccount := suite.testAccounts["local_account_1"]
targetAccount := suite.testAccounts["admin_account"]
@ -95,7 +94,7 @@ func (suite *FollowTestSuite) TestUpdateExistingFollowChangeNotifySetReblogs() {
}
func (suite *FollowTestSuite) TestUpdateExistingFollowChangeNothing() {
ctx := context.Background()
ctx := suite.T().Context()
requestingAccount := suite.testAccounts["local_account_1"]
targetAccount := suite.testAccounts["admin_account"]
@ -115,7 +114,7 @@ func (suite *FollowTestSuite) TestUpdateExistingFollowChangeNothing() {
}
func (suite *FollowTestSuite) TestUpdateExistingFollowSetNothing() {
ctx := context.Background()
ctx := suite.T().Context()
requestingAccount := suite.testAccounts["local_account_1"]
targetAccount := suite.testAccounts["admin_account"]
@ -133,7 +132,7 @@ func (suite *FollowTestSuite) TestUpdateExistingFollowSetNothing() {
}
func (suite *FollowTestSuite) TestFollowRequestLocal() {
ctx := context.Background()
ctx := suite.T().Context()
requestingAccount := suite.testAccounts["admin_account"]
targetAccount := suite.testAccounts["local_account_2"]

View file

@ -18,7 +18,6 @@
package account_test
import (
"context"
"testing"
"time"
@ -34,7 +33,7 @@ type MoveTestSuite struct {
}
func (suite *MoveTestSuite) TestMoveAccountOK() {
ctx := context.Background()
ctx := suite.T().Context()
// Copy zork.
requestingAcct := new(gtsmodel.Account)
@ -106,7 +105,7 @@ func (suite *MoveTestSuite) TestMoveAccountOK() {
}
func (suite *MoveTestSuite) TestMoveAccountNotAliased() {
ctx := context.Background()
ctx := suite.T().Context()
// Copy zork.
requestingAcct := new(gtsmodel.Account)
@ -136,7 +135,7 @@ func (suite *MoveTestSuite) TestMoveAccountNotAliased() {
}
func (suite *MoveTestSuite) TestMoveAccountBadPassword() {
ctx := context.Background()
ctx := suite.T().Context()
// Copy zork.
requestingAcct := new(gtsmodel.Account)

View file

@ -18,7 +18,6 @@
package account_test
import (
"context"
"testing"
"github.com/stretchr/testify/suite"
@ -29,7 +28,7 @@ type GetRSSTestSuite struct {
}
func (suite *GetRSSTestSuite) TestGetAccountRSSAdmin() {
getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(context.Background(), "admin")
getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(suite.T().Context(), "admin")
suite.NoError(err)
suite.EqualValues(1634726497, lastModified.Unix())
@ -68,7 +67,7 @@ func (suite *GetRSSTestSuite) TestGetAccountRSSAdmin() {
}
func (suite *GetRSSTestSuite) TestGetAccountRSSZork() {
getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(context.Background(), "the_mighty_zork")
getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(suite.T().Context(), "the_mighty_zork")
suite.NoError(err)
suite.EqualValues(1730451600, lastModified.Unix())
@ -156,7 +155,7 @@ func (suite *GetRSSTestSuite) TestGetAccountRSSZork() {
}
func (suite *GetRSSTestSuite) TestGetAccountRSSZorkNoPosts() {
ctx := context.Background()
ctx := suite.T().Context()
// Get all of zork's posts.
statuses, err := suite.db.GetAccountStatuses(ctx, suite.testAccounts["local_account_1"].ID, 0, false, false, "", "", false, false)

View file

@ -18,7 +18,6 @@
package account_test
import (
"context"
"testing"
"time"
@ -38,7 +37,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateSimple() {
*testAccount = *suite.testAccounts["local_account_1"]
var (
ctx = context.Background()
ctx = suite.T().Context()
locked = true
displayName = "new display name"
note = "#hello here i am!"
@ -88,7 +87,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMention() {
*testAccount = *suite.testAccounts["local_account_1"]
var (
ctx = context.Background()
ctx = suite.T().Context()
locked = true
displayName = "new display name"
note = "#hello here i am!\n\ngo check out @1happyturtle, they have a cool account!"
@ -144,7 +143,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMarkdownNote() {
testAccount.Settings = settings
var (
ctx = context.Background()
ctx = suite.T().Context()
note = "*hello* ~~here~~ i am!"
noteExpected = `<p><em>hello</em> <del>here</del> i am!</p>`
)
@ -193,7 +192,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithFields() {
*testAccount = *suite.testAccounts["local_account_1"]
var (
ctx = context.Background()
ctx = suite.T().Context()
updateFields = []apimodel.UpdateField{
{
Name: func() *string { s := "favourite emoji"; return &s }(),
@ -287,7 +286,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateNoteNotFields() {
*testAccount = *suite.testAccounts["local_account_2"]
var (
ctx = context.Background()
ctx = suite.T().Context()
fieldsRawBefore = len(testAccount.FieldsRaw)
fieldsBefore = len(testAccount.Fields)
note = "#hello here i am!"
@ -335,7 +334,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateNoteNotFields() {
func (suite *AccountUpdateTestSuite) TestAccountUpdateBotNotBot() {
testAccount := &gtsmodel.Account{}
*testAccount = *suite.testAccounts["local_account_1"]
ctx := context.Background()
ctx := suite.T().Context()
// Call update function to set bot = true.
apiAccount, errWithCode := suite.accountProcessor.Update(

View file

@ -18,7 +18,6 @@
package admin_test
import (
"context"
"testing"
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
@ -33,7 +32,7 @@ type AccountTestSuite struct {
func (suite *AccountTestSuite) TestAccountActionSuspend() {
var (
ctx = context.Background()
ctx = suite.T().Context()
adminAcct = suite.testAccounts["admin_account"]
request = &apimodel.AdminActionRequest{
Category: gtsmodel.AdminActionCategoryAccount.String(),
@ -79,7 +78,7 @@ func (suite *AccountTestSuite) TestAccountActionSuspend() {
func (suite *AccountTestSuite) TestAccountActionUnsupported() {
var (
ctx = context.Background()
ctx = suite.T().Context()
adminAcct = suite.testAccounts["admin_account"]
request = &apimodel.AdminActionRequest{
Category: gtsmodel.AdminActionCategoryAccount.String(),

View file

@ -82,7 +82,7 @@ func (suite *DomainBlockTestSuite) runDomainPermTest(t domainPermTest) {
config.SetInstanceFederationMode(t.instanceFederationMode)
for _, action := range t.actions {
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(suite.T().Context())
defer cancel()
// Run the desired action.
@ -102,7 +102,7 @@ func (suite *DomainBlockTestSuite) runDomainPermTest(t domainPermTest) {
// Check expected results
// against each account.
accounts, err := suite.db.GetInstanceAccounts(
context.Background(),
suite.T().Context(),
action.domain,
"", 0,
)
@ -123,7 +123,7 @@ func (suite *DomainBlockTestSuite) createDomainPerm(
permissionType gtsmodel.DomainPermissionType,
domain string,
) (*apimodel.DomainPermission, string) {
ctx := context.Background()
ctx := suite.T().Context()
apiPerm, actionID, errWithCode := suite.adminProcessor.DomainPermissionCreate(
ctx,
@ -148,7 +148,7 @@ func (suite *DomainBlockTestSuite) deleteDomainPerm(
domain string,
) (*apimodel.DomainPermission, string) {
var (
ctx = context.Background()
ctx = suite.T().Context()
domainPermission gtsmodel.DomainPermission
)
@ -183,7 +183,7 @@ func (suite *DomainBlockTestSuite) deleteDomainPerm(
// waits for given actionID to be completed.
func (suite *DomainBlockTestSuite) awaitAction(actionID string) {
ctx := context.Background()
ctx := suite.T().Context()
if !testrig.WaitFor(func() bool {
return suite.state.AdminActions.TotalRunning() == 0

View file

@ -18,7 +18,6 @@
package admin_test
import (
"context"
"testing"
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
@ -32,7 +31,7 @@ type EmojiTestSuite struct {
}
func (suite *EmojiTestSuite) TestUpdateEmojiCategory() {
ctx := context.Background()
ctx := suite.T().Context()
testEmoji := new(gtsmodel.Emoji)
*testEmoji = *suite.testEmojis["rainbow"]

View file

@ -18,7 +18,6 @@
package admin_test
import (
"context"
"testing"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
@ -32,7 +31,7 @@ type AdminApproveTestSuite struct {
func (suite *AdminApproveTestSuite) TestApprove() {
var (
ctx = context.Background()
ctx = suite.T().Context()
adminAcct = suite.testAccounts["admin_account"]
targetAcct = suite.testAccounts["unconfirmed_account"]
targetUser = new(gtsmodel.User)

View file

@ -18,7 +18,6 @@
package admin_test
import (
"context"
"testing"
"code.superseriousbusiness.org/gotosocial/internal/db"
@ -33,7 +32,7 @@ type AdminRejectTestSuite struct {
func (suite *AdminRejectTestSuite) TestReject() {
var (
ctx = context.Background()
ctx = suite.T().Context()
adminAcct = suite.testAccounts["admin_account"]
targetAcct = suite.testAccounts["unconfirmed_account"]
targetUser = suite.testUsers["unconfirmed_account"]
@ -95,7 +94,7 @@ func (suite *AdminRejectTestSuite) TestReject() {
func (suite *AdminRejectTestSuite) TestRejectRemote() {
var (
ctx = context.Background()
ctx = suite.T().Context()
adminAcct = suite.testAccounts["admin_account"]
targetAcct = suite.testAccounts["remote_account_1"]
privateComment = "It's a no from me chief."
@ -117,7 +116,7 @@ func (suite *AdminRejectTestSuite) TestRejectRemote() {
func (suite *AdminRejectTestSuite) TestRejectApproved() {
var (
ctx = context.Background()
ctx = suite.T().Context()
adminAcct = suite.testAccounts["admin_account"]
targetAcct = suite.testAccounts["local_account_1"]
privateComment = "It's a no from me chief."

View file

@ -94,7 +94,7 @@ type WorkerTaskTestSuite struct {
}
func (suite *WorkerTaskTestSuite) TestFillWorkerQueues() {
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
var tasks []*gtsmodel.WorkerTask
@ -255,7 +255,7 @@ func (suite *WorkerTaskTestSuite) TestFillWorkerQueues() {
}
func (suite *WorkerTaskTestSuite) TestPersistWorkerQueues() {
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// Push all test worker tasks to their respective queues.

View file

@ -75,7 +75,7 @@ type ConversationsTestSuite struct {
}
func (suite *ConversationsTestSuite) getClientMsg(timeout time.Duration) (*messages.FromClientAPI, bool) {
ctx := context.Background()
ctx := suite.T().Context()
ctx, cncl := context.WithTimeout(ctx, timeout)
defer cncl()
return suite.state.Workers.Client.Queue.PopCtx(ctx)
@ -130,8 +130,8 @@ func (suite *ConversationsTestSuite) TearDownTest() {
(*gtsmodel.ConversationToStatus)(nil),
}
for _, model := range conversationModels {
if err := suite.db.DropTable(context.Background(), model); err != nil {
log.Error(context.Background(), err)
if err := suite.db.DropTable(suite.T().Context(), model); err != nil {
log.Error(suite.T().Context(), err)
}
}

View file

@ -17,11 +17,9 @@
package conversations_test
import "context"
func (suite *ConversationsTestSuite) TestDelete() {
conversation := suite.NewTestConversation(suite.testAccount, 0)
err := suite.conversationsProcessor.Delete(context.Background(), suite.testAccount, conversation.ID)
err := suite.conversationsProcessor.Delete(suite.T().Context(), suite.testAccount, conversation.ID)
suite.NoError(err)
}

View file

@ -18,7 +18,6 @@
package conversations_test
import (
"context"
"time"
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
@ -27,7 +26,7 @@ import (
func (suite *ConversationsTestSuite) TestGetAll() {
conversation := suite.NewTestConversation(suite.testAccount, 0)
resp, err := suite.conversationsProcessor.GetAll(context.Background(), suite.testAccount, nil)
resp, err := suite.conversationsProcessor.GetAll(suite.T().Context(), suite.testAccount, nil)
if suite.NoError(err) && suite.Len(resp.Items, 1) && suite.IsType((*apimodel.Conversation)(nil), resp.Items[0]) {
apiConversation := resp.Items[0].(*apimodel.Conversation)
suite.Equal(conversation.ID, apiConversation.ID)
@ -46,11 +45,11 @@ func (suite *ConversationsTestSuite) TestGetAllOrder() {
// Add an even newer status than that to conversation1.
conversation1Status2 := suite.NewTestStatus(suite.testAccount, conversation1.LastStatus.ThreadID, 2*time.Second, conversation1.LastStatus)
conversation1.LastStatusID = conversation1Status2.ID
if err := suite.db.UpsertConversation(context.Background(), conversation1, "last_status_id"); err != nil {
if err := suite.db.UpsertConversation(suite.T().Context(), conversation1, "last_status_id"); err != nil {
suite.FailNow(err.Error())
}
resp, err := suite.conversationsProcessor.GetAll(context.Background(), suite.testAccount, nil)
resp, err := suite.conversationsProcessor.GetAll(suite.T().Context(), suite.testAccount, nil)
if suite.NoError(err) && suite.Len(resp.Items, 2) {
// conversation1 should be the first conversation returned.
apiConversation1 := resp.Items[0].(*apimodel.Conversation)

View file

@ -18,8 +18,6 @@
package conversations_test
import (
"context"
"code.superseriousbusiness.org/gotosocial/internal/db"
"code.superseriousbusiness.org/gotosocial/internal/db/bundb"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
@ -29,7 +27,7 @@ import (
// This test assumes that we're using the standard test fixtures, which contain some conversation-eligible DMs.
func (suite *ConversationsTestSuite) TestMigrateDMsToConversations() {
advancedMigrationID := "20240611190733_add_conversations"
ctx := context.Background()
ctx := suite.T().Context()
rawDB := (suite.db).(*bundb.DBService).DB()
// Precondition: we shouldn't have any conversations yet.

View file

@ -18,8 +18,6 @@
package conversations_test
import (
"context"
"code.superseriousbusiness.org/gotosocial/internal/util"
)
@ -27,7 +25,7 @@ func (suite *ConversationsTestSuite) TestRead() {
conversation := suite.NewTestConversation(suite.testAccount, 0)
suite.False(util.PtrOrValue(conversation.Read, false))
apiConversation, err := suite.conversationsProcessor.Read(context.Background(), suite.testAccount, conversation.ID)
apiConversation, err := suite.conversationsProcessor.Read(suite.T().Context(), suite.testAccount, conversation.ID)
if suite.NoError(err) {
suite.False(apiConversation.Unread)
}

View file

@ -17,13 +17,9 @@
package conversations_test
import (
"context"
)
// Test that we can create conversations when a new status comes in.
func (suite *ConversationsTestSuite) TestUpdateConversationsForStatus() {
ctx := context.Background()
ctx := suite.T().Context()
// Precondition: the test user shouldn't have any conversations yet.
conversations, err := suite.db.GetConversationsByOwnerAccountID(ctx, suite.testAccount.ID, nil)

View file

@ -18,7 +18,6 @@
package processing_test
import (
"context"
"encoding/json"
"fmt"
"io"
@ -53,11 +52,11 @@ func (suite *FollowRequestTestSuite) TestFollowRequestAccept() {
TargetAccountID: requestingAccount.ID,
}
err := suite.db.Put(context.Background(), fr)
err := suite.db.Put(suite.T().Context(), fr)
suite.NoError(err)
relationship, errWithCode := suite.processor.Account().FollowRequestAccept(
context.Background(),
suite.T().Context(),
requestingAccount,
targetAccount.ID,
)
@ -139,11 +138,11 @@ func (suite *FollowRequestTestSuite) TestFollowRequestReject() {
TargetAccountID: requestingAccount.ID,
}
err := suite.db.Put(context.Background(), fr)
err := suite.db.Put(suite.T().Context(), fr)
suite.NoError(err)
relationship, errWithCode := suite.processor.Account().FollowRequestReject(
context.Background(),
suite.T().Context(),
requestingAccount,
targetAccount.ID,
)

View file

@ -18,7 +18,6 @@
package interactionrequests_test
import (
"context"
"testing"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
@ -36,7 +35,7 @@ func (suite *AcceptTestSuite) TestAccept() {
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
state = testStructs.State
acct = suite.testAccounts["local_account_2"]
intReq = suite.testInteractionRequests["admin_account_reply_turtle"]

View file

@ -18,7 +18,6 @@
package interactionrequests_test
import (
"context"
"errors"
"testing"
@ -38,7 +37,7 @@ func (suite *RejectTestSuite) TestReject() {
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
state = testStructs.State
acct = suite.testAccounts["local_account_2"]
intReq = suite.testInteractionRequests["admin_account_reply_turtle"]

View file

@ -18,7 +18,6 @@
package media_test
import (
"context"
"testing"
"github.com/stretchr/testify/suite"
@ -29,7 +28,7 @@ type GetEmojiTestSuite struct {
}
func (suite *GetEmojiTestSuite) TestGetCustomEmojis() {
emojis, err := suite.mediaProcessor.GetCustomEmojis(context.Background())
emojis, err := suite.mediaProcessor.GetCustomEmojis(suite.T().Context())
suite.NoError(err)
suite.Equal(1, len(emojis))

View file

@ -18,7 +18,6 @@
package media_test
import (
"context"
"io"
"path"
"testing"
@ -36,7 +35,7 @@ type GetFileTestSuite struct {
}
func (suite *GetFileTestSuite) TestGetRemoteFileCached() {
ctx := context.Background()
ctx := suite.T().Context()
testAttachment := suite.testAttachments["remote_account_1_status_1_attachment_1"]
fileName := path.Base(testAttachment.File.Path)
@ -64,7 +63,7 @@ func (suite *GetFileTestSuite) TestGetRemoteFileCached() {
}
func (suite *GetFileTestSuite) TestGetRemoteFileUncached() {
ctx := context.Background()
ctx := suite.T().Context()
// uncache the file from local
testAttachment := suite.testAttachments["remote_account_1_status_1_attachment_1"]
@ -116,7 +115,7 @@ func (suite *GetFileTestSuite) TestGetRemoteFileUncached() {
}
func (suite *GetFileTestSuite) TestGetRemoteFileUncachedInterrupted() {
ctx := context.Background()
ctx := suite.T().Context()
// uncache the file from local
testAttachment := suite.testAttachments["remote_account_1_status_1_attachment_1"]
@ -163,7 +162,7 @@ func (suite *GetFileTestSuite) TestGetRemoteFileUncachedInterrupted() {
}
func (suite *GetFileTestSuite) TestGetRemoteFileThumbnailUncached() {
ctx := context.Background()
ctx := suite.T().Context()
testAttachment := suite.testAttachments["remote_account_1_status_1_attachment_1"]
// fetch the existing thumbnail bytes from storage first

View file

@ -18,7 +18,6 @@
package media_test
import (
"context"
"testing"
"github.com/stretchr/testify/suite"
@ -29,7 +28,7 @@ type UnattachTestSuite struct {
}
func (suite *UnattachTestSuite) TestUnattachMedia() {
ctx := context.Background()
ctx := suite.T().Context()
testAttachment := suite.testAttachments["admin_account_status_1_attachment_1"]
testAccount := suite.testAccounts["admin_account"]

View file

@ -18,7 +18,6 @@
package processing_test
import (
"context"
"errors"
"testing"
@ -34,7 +33,7 @@ type ParseMentionTestSuite struct {
func (suite *ParseMentionTestSuite) TestParseMentionFunc() {
var (
ctx = context.Background()
ctx = suite.T().Context()
parseMention = processing.GetParseMentionFunc(&suite.state, suite.federator)
originAcctID = suite.testAccounts["local_account_1"].ID
statusID = id.NewULID()

View file

@ -68,7 +68,7 @@ func (suite *PollTestSuite) TearDownTest() {
func (suite *PollTestSuite) TestPollGet() {
// Create a new context for this test.
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// Perform test for all requester + poll combos.
@ -111,7 +111,7 @@ func (suite *PollTestSuite) testPollGet(ctx context.Context, requester *gtsmodel
func (suite *PollTestSuite) TestPollVote() {
// Create a new context for this test.
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// randomChoices generates random vote choices in poll.

View file

@ -18,7 +18,6 @@
package processing_test
import (
"context"
"testing"
"code.superseriousbusiness.org/gotosocial/internal/api/model"
@ -31,7 +30,7 @@ type PreferencesTestSuite struct {
}
func (suite *PreferencesTestSuite) TestPreferencesGet() {
ctx := context.Background()
ctx := suite.T().Context()
tests := []struct {
act *gtsmodel.Account
prefs *model.Preferences

View file

@ -18,7 +18,6 @@
package status_test
import (
"context"
"testing"
"github.com/stretchr/testify/suite"
@ -29,7 +28,7 @@ type StatusBookmarkTestSuite struct {
}
func (suite *StatusBookmarkTestSuite) TestBookmark() {
ctx := context.Background()
ctx := suite.T().Context()
// bookmark a status
bookmarkingAccount1 := suite.testAccounts["local_account_1"]
@ -43,7 +42,7 @@ func (suite *StatusBookmarkTestSuite) TestBookmark() {
}
func (suite *StatusBookmarkTestSuite) TestUnbookmark() {
ctx := context.Background()
ctx := suite.T().Context()
// bookmark a status
bookmarkingAccount1 := suite.testAccounts["local_account_1"]

View file

@ -18,7 +18,6 @@
package status_test
import (
"context"
"testing"
"github.com/stretchr/testify/suite"
@ -29,7 +28,7 @@ type StatusBoostTestSuite struct {
}
func (suite *StatusBoostTestSuite) TestBoostOfBoost() {
ctx := context.Background()
ctx := suite.T().Context()
// first boost a status, no big deal
boostingAccount1 := suite.testAccounts["local_account_1"]

View file

@ -18,7 +18,6 @@
package status_test
import (
"context"
"testing"
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
@ -34,7 +33,7 @@ type StatusCreateTestSuite struct {
}
func (suite *StatusCreateTestSuite) TestProcessContentWarningWithQuotationMarks() {
ctx := context.Background()
ctx := suite.T().Context()
creatingAccount := suite.testAccounts["local_account_1"]
creatingApplication := suite.testApplications["application_1"]
@ -61,7 +60,7 @@ func (suite *StatusCreateTestSuite) TestProcessContentWarningWithQuotationMarks(
}
func (suite *StatusCreateTestSuite) TestProcessStatusMarkdownWithUnderscoreEmoji() {
ctx := context.Background()
ctx := suite.T().Context()
// update the shortcode of the rainbow emoji to surround it in underscores
if err := suite.db.UpdateWhere(ctx, []db.Where{{Key: "shortcode", Value: "rainbow"}}, "shortcode", "_rainbow_", &gtsmodel.Emoji{}); err != nil {
@ -93,7 +92,7 @@ func (suite *StatusCreateTestSuite) TestProcessStatusMarkdownWithUnderscoreEmoji
}
func (suite *StatusCreateTestSuite) TestProcessStatusMarkdownWithSpoilerTextEmoji() {
ctx := context.Background()
ctx := suite.T().Context()
creatingAccount := suite.testAccounts["local_account_1"]
creatingApplication := suite.testApplications["application_1"]
@ -121,7 +120,7 @@ func (suite *StatusCreateTestSuite) TestProcessStatusMarkdownWithSpoilerTextEmoj
}
func (suite *StatusCreateTestSuite) TestProcessMediaDescriptionTooShort() {
ctx := context.Background()
ctx := suite.T().Context()
config.SetMediaDescriptionMinChars(100)
@ -148,7 +147,7 @@ func (suite *StatusCreateTestSuite) TestProcessMediaDescriptionTooShort() {
}
func (suite *StatusCreateTestSuite) TestProcessLanguageWithScriptPart() {
ctx := context.Background()
ctx := suite.T().Context()
creatingAccount := suite.testAccounts["local_account_1"]
creatingApplication := suite.testApplications["application_1"]
@ -175,7 +174,7 @@ func (suite *StatusCreateTestSuite) TestProcessLanguageWithScriptPart() {
}
func (suite *StatusCreateTestSuite) TestProcessReplyToUnthreadedRemoteStatus() {
ctx := context.Background()
ctx := suite.T().Context()
creatingAccount := suite.testAccounts["local_account_1"]
creatingApplication := suite.testApplications["application_1"]
@ -212,7 +211,7 @@ func (suite *StatusCreateTestSuite) TestProcessReplyToUnthreadedRemoteStatus() {
}
func (suite *StatusCreateTestSuite) TestProcessNoContentTypeUsesDefault() {
ctx := context.Background()
ctx := suite.T().Context()
creatingAccount := suite.testAccounts["local_account_1"]
creatingApplication := suite.testApplications["application_1"]

View file

@ -37,7 +37,7 @@ type StatusEditTestSuite struct {
func (suite *StatusEditTestSuite) TestSimpleEdit() {
// Create cancellable context to use for test.
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// Get a local account to use as test requester.
@ -100,7 +100,7 @@ func (suite *StatusEditTestSuite) TestSimpleEdit() {
func (suite *StatusEditTestSuite) TestEditChangeContentType() {
// Create cancellable context to use for test.
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// Get a local account to use as test requester.
@ -166,7 +166,7 @@ func (suite *StatusEditTestSuite) TestEditChangeContentType() {
func (suite *StatusEditTestSuite) TestEditOnStatusWithNoContentType() {
// Create cancellable context to use for test.
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// Get a local account to use as test requester.
@ -235,7 +235,7 @@ func (suite *StatusEditTestSuite) TestEditOnStatusWithNoContentType() {
func (suite *StatusEditTestSuite) TestEditAddPoll() {
// Create cancellable context to use for test.
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// Get a local account to use as test requester.
@ -313,7 +313,7 @@ func (suite *StatusEditTestSuite) TestEditAddPoll() {
func (suite *StatusEditTestSuite) TestEditAddPollNoExpiry() {
// Create cancellable context to use for test.
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// Get a local account to use as test requester.
@ -391,7 +391,7 @@ func (suite *StatusEditTestSuite) TestEditAddPollNoExpiry() {
func (suite *StatusEditTestSuite) TestEditMediaDescription() {
// Create cancellable context to use for test.
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// Get a local account to use as test requester.
@ -487,7 +487,7 @@ func (suite *StatusEditTestSuite) TestEditMediaDescription() {
func (suite *StatusEditTestSuite) TestEditAddMedia() {
// Create cancellable context to use for test.
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// Get a local account to use as test requester.
@ -562,7 +562,7 @@ func (suite *StatusEditTestSuite) TestEditAddMedia() {
func (suite *StatusEditTestSuite) TestEditRemoveMedia() {
// Create cancellable context to use for test.
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// Get a local account to use as test requester.
@ -628,7 +628,7 @@ func (suite *StatusEditTestSuite) TestEditRemoveMedia() {
func (suite *StatusEditTestSuite) TestEditOthersStatus1() {
// Create cancellable context to use for test.
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// Get a local account to use as test requester.
@ -653,7 +653,7 @@ func (suite *StatusEditTestSuite) TestEditOthersStatus1() {
func (suite *StatusEditTestSuite) TestEditOthersStatus2() {
// Create cancellable context to use for test.
ctx, cncl := context.WithCancel(context.Background())
ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
// Get a local account to use as test requester.

View file

@ -18,7 +18,6 @@
package stream_test
import (
"context"
"testing"
"code.superseriousbusiness.org/gotosocial/internal/db"
@ -30,15 +29,15 @@ type AuthorizeTestSuite struct {
}
func (suite *AuthorizeTestSuite) TestAuthorize() {
account1, err := suite.streamProcessor.Authorize(context.Background(), suite.testTokens["local_account_1"].Access)
account1, err := suite.streamProcessor.Authorize(suite.T().Context(), suite.testTokens["local_account_1"].Access)
suite.NoError(err)
suite.Equal(suite.testAccounts["local_account_1"].ID, account1.ID)
account2, err := suite.streamProcessor.Authorize(context.Background(), suite.testTokens["local_account_2"].Access)
account2, err := suite.streamProcessor.Authorize(suite.T().Context(), suite.testTokens["local_account_2"].Access)
suite.NoError(err)
suite.Equal(suite.testAccounts["local_account_2"].ID, account2.ID)
noAccount, err := suite.streamProcessor.Authorize(context.Background(), "aaaaaaaaaaaaaaaaaaaaa!!")
noAccount, err := suite.streamProcessor.Authorize(suite.T().Context(), "aaaaaaaaaaaaaaaaaaaaa!!")
suite.EqualError(err, "could not load access token: "+db.ErrNoEntries.Error())
suite.Nil(noAccount)
}

View file

@ -19,7 +19,6 @@ package stream_test
import (
"bytes"
"context"
"encoding/json"
"testing"
@ -35,11 +34,11 @@ type NotificationTestSuite struct {
func (suite *NotificationTestSuite) TestStreamNotification() {
account := suite.testAccounts["local_account_1"]
openStream, errWithCode := suite.streamProcessor.Open(context.Background(), account, "user")
openStream, errWithCode := suite.streamProcessor.Open(suite.T().Context(), account, "user")
suite.NoError(errWithCode)
followAccount := suite.testAccounts["remote_account_1"]
followAccountAPIModel, err := typeutils.NewConverter(&suite.state).AccountToAPIAccountPublic(context.Background(), followAccount)
followAccountAPIModel, err := typeutils.NewConverter(&suite.state).AccountToAPIAccountPublic(suite.T().Context(), followAccount)
suite.NoError(err)
notification := &apimodel.Notification{
@ -49,9 +48,9 @@ func (suite *NotificationTestSuite) TestStreamNotification() {
Account: followAccountAPIModel,
}
suite.streamProcessor.Notify(context.Background(), account, notification)
suite.streamProcessor.Notify(suite.T().Context(), account, notification)
msg, ok := openStream.Recv(context.Background())
msg, ok := openStream.Recv(suite.T().Context())
suite.True(ok)
dst := new(bytes.Buffer)

View file

@ -18,7 +18,6 @@
package stream_test
import (
"context"
"testing"
"github.com/stretchr/testify/suite"
@ -31,7 +30,7 @@ type OpenStreamTestSuite struct {
func (suite *OpenStreamTestSuite) TestOpenStream() {
account := suite.testAccounts["local_account_1"]
_, errWithCode := suite.streamProcessor.Open(context.Background(), account, "user")
_, errWithCode := suite.streamProcessor.Open(suite.T().Context(), account, "user")
suite.NoError(errWithCode)
}

View file

@ -19,7 +19,6 @@ package stream_test
import (
"bytes"
"context"
"encoding/json"
"testing"
@ -36,16 +35,16 @@ type StatusUpdateTestSuite struct {
func (suite *StatusUpdateTestSuite) TestStreamNotification() {
account := suite.testAccounts["local_account_1"]
openStream, errWithCode := suite.streamProcessor.Open(context.Background(), account, "user")
openStream, errWithCode := suite.streamProcessor.Open(suite.T().Context(), account, "user")
suite.NoError(errWithCode)
editedStatus := suite.testStatuses["remote_account_1_status_1"]
apiStatus, err := typeutils.NewConverter(&suite.state).StatusToAPIStatus(context.Background(), editedStatus, account, statusfilter.FilterContextNotifications, nil, nil)
apiStatus, err := typeutils.NewConverter(&suite.state).StatusToAPIStatus(suite.T().Context(), editedStatus, account, statusfilter.FilterContextNotifications, nil, nil)
suite.NoError(err)
suite.streamProcessor.StatusUpdate(context.Background(), account, apiStatus, stream.TimelineHome)
suite.streamProcessor.StatusUpdate(suite.T().Context(), account, apiStatus, stream.TimelineHome)
msg, ok := openStream.Recv(context.Background())
msg, ok := openStream.Recv(suite.T().Context())
suite.True(ok)
dst := new(bytes.Buffer)

View file

@ -18,7 +18,6 @@
package timeline_test
import (
"context"
"testing"
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
@ -40,7 +39,7 @@ func (suite *HomeTestSuite) TearDownTest() {
// A timeline containing a status hidden due to filtering should return other statuses with no error.
func (suite *HomeTestSuite) TestHomeTimelineGetHideFiltered() {
var (
ctx = context.Background()
ctx = suite.T().Context()
requester = suite.testAccounts["local_account_1"]
maxID = ""
sinceID = ""

View file

@ -18,7 +18,6 @@
package timeline_test
import (
"context"
"testing"
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
@ -35,7 +34,7 @@ type PublicTestSuite struct {
func (suite *PublicTestSuite) TestPublicTimelineGet() {
var (
ctx = context.Background()
ctx = suite.T().Context()
requester = suite.testAccounts["local_account_1"]
maxID = ""
sinceID = ""
@ -66,7 +65,7 @@ func (suite *PublicTestSuite) TestPublicTimelineGet() {
func (suite *PublicTestSuite) TestPublicTimelineGetNotEmpty() {
var (
ctx = context.Background()
ctx = suite.T().Context()
requester = suite.testAccounts["local_account_1"]
// Select 1 *just above* a status we know should
// not be in the public timeline -- a public
@ -101,7 +100,7 @@ func (suite *PublicTestSuite) TestPublicTimelineGetNotEmpty() {
// A timeline containing a status hidden due to filtering should return other statuses with no error.
func (suite *PublicTestSuite) TestPublicTimelineGetHideFiltered() {
var (
ctx = context.Background()
ctx = suite.T().Context()
requester = suite.testAccounts["local_account_1"]
maxID = ""
sinceID = ""

View file

@ -18,7 +18,6 @@
package user_test
import (
"context"
"net"
"testing"
@ -32,7 +31,7 @@ type CreateTestSuite struct {
func (suite *CreateTestSuite) TestCreateOK() {
var (
ctx = context.Background()
ctx = suite.T().Context()
app = suite.testApps["application_1"]
appToken = suite.testTokens["local_account_1_client_application_token"]
form = &apimodel.AccountCreateRequest{

View file

@ -18,7 +18,6 @@
package user_test
import (
"context"
"testing"
"time"
@ -30,7 +29,7 @@ type EmailConfirmTestSuite struct {
}
func (suite *EmailConfirmTestSuite) TestConfirmEmail() {
ctx := context.Background()
ctx := suite.T().Context()
user := suite.testUsers["local_account_1"]
@ -58,7 +57,7 @@ func (suite *EmailConfirmTestSuite) TestConfirmEmail() {
}
func (suite *EmailConfirmTestSuite) TestConfirmEmailOldToken() {
ctx := context.Background()
ctx := suite.T().Context()
user := suite.testUsers["local_account_1"]

View file

@ -18,7 +18,6 @@
package user_test
import (
"context"
"net/http"
"testing"
@ -35,7 +34,7 @@ type ChangePasswordTestSuite struct {
func (suite *ChangePasswordTestSuite) TestChangePasswordOK() {
user := suite.testUsers["local_account_1"]
errWithCode := suite.user.PasswordChange(context.Background(), user, "password", "verygoodnewpassword")
errWithCode := suite.user.PasswordChange(suite.T().Context(), user, "password", "verygoodnewpassword")
suite.NoError(errWithCode)
err := bcrypt.CompareHashAndPassword(
@ -46,7 +45,7 @@ func (suite *ChangePasswordTestSuite) TestChangePasswordOK() {
// get user from the db again
dbUser := &gtsmodel.User{}
err = suite.db.GetByID(context.Background(), user.ID, dbUser)
err = suite.db.GetByID(suite.T().Context(), user.ID, dbUser)
suite.NoError(err)
// check the password has changed
@ -60,14 +59,14 @@ func (suite *ChangePasswordTestSuite) TestChangePasswordOK() {
func (suite *ChangePasswordTestSuite) TestChangePasswordIncorrectOld() {
user := suite.testUsers["local_account_1"]
errWithCode := suite.user.PasswordChange(context.Background(), user, "ooooopsydoooopsy", "verygoodnewpassword")
errWithCode := suite.user.PasswordChange(suite.T().Context(), user, "ooooopsydoooopsy", "verygoodnewpassword")
suite.EqualError(errWithCode, "PasswordChange: crypto/bcrypt: hashedPassword is not the hash of the given password")
suite.Equal(http.StatusUnauthorized, errWithCode.Code())
suite.Equal("Unauthorized: old password was incorrect", errWithCode.Safe())
// get user from the db again
dbUser := &gtsmodel.User{}
err := suite.db.GetByID(context.Background(), user.ID, dbUser)
err := suite.db.GetByID(suite.T().Context(), user.ID, dbUser)
suite.NoError(err)
// check the password has not changed
@ -81,14 +80,14 @@ func (suite *ChangePasswordTestSuite) TestChangePasswordIncorrectOld() {
func (suite *ChangePasswordTestSuite) TestChangePasswordWeakNew() {
user := suite.testUsers["local_account_1"]
errWithCode := suite.user.PasswordChange(context.Background(), user, "password", "1234")
errWithCode := suite.user.PasswordChange(suite.T().Context(), user, "password", "1234")
suite.EqualError(errWithCode, "password is only 11% strength, try including more special characters, using lowercase letters, using uppercase letters or using a longer password")
suite.Equal(http.StatusBadRequest, errWithCode.Code())
suite.Equal("Bad Request: password is only 11% strength, try including more special characters, using lowercase letters, using uppercase letters or using a longer password", errWithCode.Safe())
// get user from the db again
dbUser := &gtsmodel.User{}
err := suite.db.GetByID(context.Background(), user.ID, dbUser)
err := suite.db.GetByID(suite.T().Context(), user.ID, dbUser)
suite.NoError(err)
// check the password has not changed

View file

@ -158,7 +158,7 @@ func (suite *FromClientAPITestSuite) checkStreamed(
) {
// Set a 5s timeout on context.
ctx := context.Background()
ctx := suite.T().Context()
ctx, cncl := context.WithTimeout(ctx, time.Second*5)
defer cncl()
@ -259,7 +259,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithNotification() {
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"]
testList = suite.testLists["local_account_1_list_1"]
@ -376,7 +376,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateBackfilledStatusWithNotifi
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"]
testList = suite.testLists["local_account_1_list_1"]
@ -475,7 +475,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateBackfilledStatusWithRemote
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["local_account_1"]
receivingAccount = suite.testAccounts["remote_account_1"]
@ -531,7 +531,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReply() {
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"]
testList = suite.testLists["local_account_1_list_1"]
@ -602,7 +602,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyMuted() {
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"]
@ -666,7 +666,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostMuted() {
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"]
@ -734,7 +734,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyLis
*testList = *suite.testLists["local_account_1_list_1"]
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"]
streams = suite.openStreams(ctx, testStructs.Processor, receivingAccount, []string{testList.ID})
@ -813,7 +813,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyLis
*testList = *suite.testLists["local_account_1_list_1"]
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"]
streams = suite.openStreams(ctx, testStructs.Processor, receivingAccount, []string{testList.ID})
@ -898,7 +898,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyListRepliesPoli
*testList = *suite.testLists["local_account_1_list_1"]
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"]
streams = suite.openStreams(ctx, testStructs.Processor, receivingAccount, []string{testList.ID})
@ -973,7 +973,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoost() {
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"]
testList = suite.testLists["local_account_1_list_1"]
@ -1040,7 +1040,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostNoReblogs() {
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_1"]
testList = suite.testLists["local_account_1_list_1"]
@ -1107,7 +1107,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWhichBeginsConversat
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["local_account_2"]
receivingAccount = suite.testAccounts["local_account_1"]
streams = suite.openStreams(ctx,
@ -1196,7 +1196,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWhichShouldNotCreate
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["local_account_2"]
receivingAccount = suite.testAccounts["local_account_1"]
streams = suite.openStreams(ctx,
@ -1269,7 +1269,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithFollowedHashtag(
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_2"]
streams = suite.openStreams(ctx,
@ -1346,7 +1346,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithFollowedHashtagA
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["remote_account_1"]
receivingAccount = suite.testAccounts["local_account_2"]
streams = suite.openStreams(ctx,
@ -1430,7 +1430,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateBoostWithFollowedHashtag()
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["remote_account_2"]
boostingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_2"]
@ -1536,7 +1536,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateBoostWithFollowedHashtagAn
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["remote_account_1"]
boostingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_2"]
@ -1649,7 +1649,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateBoostWithFollowedHashtagAn
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
boostingAccount = suite.testAccounts["remote_account_1"]
receivingAccount = suite.testAccounts["local_account_2"]
@ -1760,7 +1760,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithAuthorOnExclusiv
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["local_account_2"]
receivingAccount = suite.testAccounts["local_account_1"]
testList = suite.testLists["local_account_1_list_1"]
@ -1836,7 +1836,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithAuthorOnExclusiv
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["local_account_2"]
receivingAccount = suite.testAccounts["local_account_1"]
testInclusiveList = suite.testLists["local_account_1_list_1"]
@ -1953,7 +1953,7 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithAuthorOnExclusiv
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["local_account_2"]
receivingAccount = suite.testAccounts["local_account_1"]
testFollow = suite.testFollows["local_account_1_local_account_2"]
@ -2080,7 +2080,7 @@ func (suite *FromClientAPITestSuite) TestProcessUpdateStatusWithFollowedHashtag(
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["admin_account"]
receivingAccount = suite.testAccounts["local_account_2"]
streams = suite.openStreams(ctx,
@ -2156,7 +2156,7 @@ func (suite *FromClientAPITestSuite) TestProcessUpdateStatusInteractedWith() {
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
postingAccount = suite.testAccounts["local_account_1"]
receivingAccount = suite.testAccounts["admin_account"]
streams = suite.openStreams(ctx,
@ -2244,7 +2244,7 @@ func (suite *FromClientAPITestSuite) TestProcessStatusDelete() {
defer testrig.TearDownTestStructs(testStructs)
var (
ctx = context.Background()
ctx = suite.T().Context()
deletingAccount = suite.testAccounts["local_account_1"]
receivingAccount = suite.testAccounts["local_account_2"]
deletedStatus = suite.testStatuses["local_account_1_status_1"]

View file

@ -62,7 +62,7 @@ func (suite *FromFediAPITestSuite) TestProcessFederationAnnounce() {
announceStatus.Account = boostingAccount
announceStatus.Visibility = boostedStatus.Visibility
err := testStructs.Processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{
err := testStructs.Processor.Workers().ProcessFromFediAPI(suite.T().Context(), &messages.FromFediAPI{
APObjectType: ap.ActivityAnnounce,
APActivityType: ap.ActivityCreate,
GTSModel: announceStatus,
@ -81,7 +81,7 @@ func (suite *FromFediAPITestSuite) TestProcessFederationAnnounce() {
}
_, err = testStructs.State.DB.GetStatusByID(
context.Background(),
suite.T().Context(),
announceStatus.ID,
)
return err == nil
@ -97,7 +97,7 @@ func (suite *FromFediAPITestSuite) TestProcessFederationAnnounce() {
},
}
notif := &gtsmodel.Notification{}
err = testStructs.State.DB.GetWhere(context.Background(), where, notif)
err = testStructs.State.DB.GetWhere(suite.T().Context(), where, notif)
suite.NoError(err)
suite.Equal(gtsmodel.NotificationReblog, notif.NotificationType)
suite.Equal(boostedStatus.AccountID, notif.TargetAccountID)
@ -125,7 +125,7 @@ func (suite *FromFediAPITestSuite) TestProcessReplyMention() {
replyingAccount.FetchedAt = time.Now()
replyingAccount.SuspendedAt = time.Time{}
replyingAccount.SuspensionOrigin = ""
err := testStructs.State.DB.UpdateAccount(context.Background(),
err := testStructs.State.DB.UpdateAccount(suite.T().Context(),
replyingAccount,
"fetched_at",
"suspended_at",
@ -139,11 +139,11 @@ func (suite *FromFediAPITestSuite) TestProcessReplyMention() {
ap.AppendInReplyTo(replyingStatusable, testrig.URLMustParse(repliedStatus.URI))
// Open a websocket stream to later test the streamed status reply.
wssStream, errWithCode := testStructs.Processor.Stream().Open(context.Background(), repliedAccount, stream.TimelineHome)
wssStream, errWithCode := testStructs.Processor.Stream().Open(suite.T().Context(), repliedAccount, stream.TimelineHome)
suite.NoError(errWithCode)
// Send the replied status off to the fedi worker to be further processed.
err = testStructs.Processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{
err = testStructs.Processor.Workers().ProcessFromFediAPI(suite.T().Context(), &messages.FromFediAPI{
APObjectType: ap.ObjectNote,
APActivityType: ap.ActivityCreate,
APObject: replyingStatusable,
@ -158,7 +158,7 @@ func (suite *FromFediAPITestSuite) TestProcessReplyMention() {
// 1. status should be in the database
var replyingStatus *gtsmodel.Status
if !testrig.WaitFor(func() bool {
replyingStatus, err = testStructs.State.DB.GetStatusByURI(context.Background(), replyingURI)
replyingStatus, err = testStructs.State.DB.GetStatusByURI(suite.T().Context(), replyingURI)
return err == nil
}) {
suite.FailNow("timed out waiting for replying status to be in the database")
@ -166,7 +166,7 @@ func (suite *FromFediAPITestSuite) TestProcessReplyMention() {
// 2. a notification should exist for the mention
var notif gtsmodel.Notification
err = testStructs.State.DB.GetWhere(context.Background(), []db.Where{
err = testStructs.State.DB.GetWhere(suite.T().Context(), []db.Where{
{Key: "status_id", Value: replyingStatus.ID},
}, &notif)
suite.NoError(err)
@ -176,7 +176,7 @@ func (suite *FromFediAPITestSuite) TestProcessReplyMention() {
suite.Equal(replyingStatus.ID, notif.StatusOrEditID)
suite.False(*notif.Read)
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
ctx, _ := context.WithTimeout(suite.T().Context(), time.Second*5)
msg, ok := wssStream.Recv(ctx)
suite.True(ok)
@ -198,7 +198,7 @@ func (suite *FromFediAPITestSuite) TestProcessFave() {
favedStatus := suite.testStatuses["local_account_1_status_1"]
favingAccount := suite.testAccounts["remote_account_1"]
wssStream, errWithCode := testStructs.Processor.Stream().Open(context.Background(), favedAccount, stream.TimelineNotifications)
wssStream, errWithCode := testStructs.Processor.Stream().Open(suite.T().Context(), favedAccount, stream.TimelineNotifications)
suite.NoError(errWithCode)
fave := &gtsmodel.StatusFave{
@ -214,10 +214,10 @@ func (suite *FromFediAPITestSuite) TestProcessFave() {
URI: favingAccount.URI + "/faves/aaaaaaaaaaaa",
}
err := testStructs.State.DB.Put(context.Background(), fave)
err := testStructs.State.DB.Put(suite.T().Context(), fave)
suite.NoError(err)
err = testStructs.Processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{
err = testStructs.Processor.Workers().ProcessFromFediAPI(suite.T().Context(), &messages.FromFediAPI{
APObjectType: ap.ActivityLike,
APActivityType: ap.ActivityCreate,
GTSModel: fave,
@ -240,7 +240,7 @@ func (suite *FromFediAPITestSuite) TestProcessFave() {
}
notif := &gtsmodel.Notification{}
err = testStructs.State.DB.GetWhere(context.Background(), where, notif)
err = testStructs.State.DB.GetWhere(suite.T().Context(), where, notif)
suite.NoError(err)
suite.Equal(gtsmodel.NotificationFavourite, notif.NotificationType)
suite.Equal(fave.TargetAccountID, notif.TargetAccountID)
@ -248,7 +248,7 @@ func (suite *FromFediAPITestSuite) TestProcessFave() {
suite.Equal(fave.StatusID, notif.StatusOrEditID)
suite.False(*notif.Read)
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
ctx, _ := context.WithTimeout(suite.T().Context(), time.Second*5)
msg, ok := wssStream.Recv(ctx)
suite.True(ok)
@ -271,7 +271,7 @@ func (suite *FromFediAPITestSuite) TestProcessFaveWithDifferentReceivingAccount(
favedStatus := suite.testStatuses["local_account_1_status_1"]
favingAccount := suite.testAccounts["remote_account_1"]
wssStream, errWithCode := testStructs.Processor.Stream().Open(context.Background(), receivingAccount, stream.TimelineHome)
wssStream, errWithCode := testStructs.Processor.Stream().Open(suite.T().Context(), receivingAccount, stream.TimelineHome)
suite.NoError(errWithCode)
fave := &gtsmodel.StatusFave{
@ -287,10 +287,10 @@ func (suite *FromFediAPITestSuite) TestProcessFaveWithDifferentReceivingAccount(
URI: favingAccount.URI + "/faves/aaaaaaaaaaaa",
}
err := testStructs.State.DB.Put(context.Background(), fave)
err := testStructs.State.DB.Put(suite.T().Context(), fave)
suite.NoError(err)
err = testStructs.Processor.Workers().ProcessFromFediAPI(context.Background(), &messages.FromFediAPI{
err = testStructs.Processor.Workers().ProcessFromFediAPI(suite.T().Context(), &messages.FromFediAPI{
APObjectType: ap.ActivityLike,
APActivityType: ap.ActivityCreate,
GTSModel: fave,
@ -313,7 +313,7 @@ func (suite *FromFediAPITestSuite) TestProcessFaveWithDifferentReceivingAccount(
}
notif := &gtsmodel.Notification{}
err = testStructs.State.DB.GetWhere(context.Background(), where, notif)
err = testStructs.State.DB.GetWhere(suite.T().Context(), where, notif)
suite.NoError(err)
suite.Equal(gtsmodel.NotificationFavourite, notif.NotificationType)
suite.Equal(fave.TargetAccountID, notif.TargetAccountID)
@ -322,7 +322,7 @@ func (suite *FromFediAPITestSuite) TestProcessFaveWithDifferentReceivingAccount(
suite.False(*notif.Read)
// 2. no notification should be streamed to the account that received the fave message, because they weren't the target
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
ctx, _ := context.WithTimeout(suite.T().Context(), time.Second*5)
_, ok := wssStream.Recv(ctx)
suite.False(ok)
}
@ -331,7 +331,7 @@ func (suite *FromFediAPITestSuite) TestProcessAccountDelete() {
testStructs := testrig.SetupTestStructs(rMediaPath, rTemplatePath)
defer testrig.TearDownTestStructs(testStructs)
ctx := context.Background()
ctx := suite.T().Context()
deletedAccount := &gtsmodel.Account{}
*deletedAccount = *suite.testAccounts["remote_account_1"]
@ -425,14 +425,14 @@ func (suite *FromFediAPITestSuite) TestProcessFollowRequestLocked() {
testStructs := testrig.SetupTestStructs(rMediaPath, rTemplatePath)
defer testrig.TearDownTestStructs(testStructs)
ctx := context.Background()
ctx := suite.T().Context()
originAccount := suite.testAccounts["remote_account_1"]
// target is a locked account
targetAccount := suite.testAccounts["local_account_2"]
wssStream, errWithCode := testStructs.Processor.Stream().Open(context.Background(), targetAccount, stream.TimelineHome)
wssStream, errWithCode := testStructs.Processor.Stream().Open(suite.T().Context(), targetAccount, stream.TimelineHome)
suite.NoError(errWithCode)
// put the follow request in the database as though it had passed through the federating db already
@ -462,7 +462,7 @@ func (suite *FromFediAPITestSuite) TestProcessFollowRequestLocked() {
suite.NoError(err)
ctx, _ = context.WithTimeout(ctx, time.Second*5)
msg, ok := wssStream.Recv(context.Background())
msg, ok := wssStream.Recv(suite.T().Context())
suite.True(ok)
suite.Equal(stream.EventTypeNotification, msg.Event)
@ -482,14 +482,14 @@ func (suite *FromFediAPITestSuite) TestProcessFollowRequestUnlocked() {
testStructs := testrig.SetupTestStructs(rMediaPath, rTemplatePath)
defer testrig.TearDownTestStructs(testStructs)
ctx := context.Background()
ctx := suite.T().Context()
originAccount := suite.testAccounts["remote_account_1"]
// target is an unlocked account
targetAccount := suite.testAccounts["local_account_1"]
wssStream, errWithCode := testStructs.Processor.Stream().Open(context.Background(), targetAccount, stream.TimelineHome)
wssStream, errWithCode := testStructs.Processor.Stream().Open(suite.T().Context(), targetAccount, stream.TimelineHome)
suite.NoError(errWithCode)
// put the follow request in the database as though it had passed through the federating db already
@ -565,7 +565,7 @@ func (suite *FromFediAPITestSuite) TestProcessFollowRequestUnlocked() {
suite.Equal("Accept", accept.Type)
ctx, _ = context.WithTimeout(ctx, time.Second*5)
msg, ok := wssStream.Recv(context.Background())
msg, ok := wssStream.Recv(suite.T().Context())
suite.True(ok)
suite.Equal(stream.EventTypeNotification, msg.Event)
@ -583,7 +583,7 @@ func (suite *FromFediAPITestSuite) TestCreateStatusFromIRI() {
testStructs := testrig.SetupTestStructs(rMediaPath, rTemplatePath)
defer testrig.TearDownTestStructs(testStructs)
ctx := context.Background()
ctx := suite.T().Context()
receivingAccount := suite.testAccounts["local_account_1"]
statusCreator := suite.testAccounts["remote_account_2"]
@ -599,7 +599,7 @@ func (suite *FromFediAPITestSuite) TestCreateStatusFromIRI() {
suite.NoError(err)
// status should now be in the database, attributed to remote_account_2
s, err := testStructs.State.DB.GetStatusByURI(context.Background(), "http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1")
s, err := testStructs.State.DB.GetStatusByURI(suite.T().Context(), "http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1")
suite.NoError(err)
suite.Equal(statusCreator.URI, s.AccountURI)
}
@ -609,7 +609,7 @@ func (suite *FromFediAPITestSuite) TestMoveAccount() {
defer testrig.TearDownTestStructs(testStructs)
// We're gonna migrate foss_satan to our local admin account.
ctx := context.Background()
ctx := suite.T().Context()
receivingAcct := suite.testAccounts["local_account_1"]
// Copy requesting and target accounts
@ -683,7 +683,7 @@ func (suite *FromFediAPITestSuite) TestMoveAccount() {
func (suite *FromFediAPITestSuite) TestUndoAnnounce() {
var (
ctx = context.Background()
ctx = suite.T().Context()
testStructs = testrig.SetupTestStructs(rMediaPath, rTemplatePath)
requestingAcct = suite.testAccounts["remote_account_1"]
receivingAcct = suite.testAccounts["local_account_1"]
@ -737,7 +737,7 @@ func (suite *FromFediAPITestSuite) TestUndoAnnounce() {
func (suite *FromFediAPITestSuite) TestUpdateNote() {
var (
ctx = context.Background()
ctx = suite.T().Context()
testStructs = testrig.SetupTestStructs(rMediaPath, rTemplatePath)
requestingAcct = suite.testAccounts["remote_account_2"]
receivingAcct = suite.testAccounts["local_account_1"]

View file

@ -18,7 +18,6 @@
package workers_test
import (
"context"
"sync"
"testing"
"time"
@ -50,7 +49,7 @@ func (suite *SurfaceNotifyTestSuite) TestSpamNotifs() {
}
var (
ctx = context.Background()
ctx = suite.T().Context()
notificationType = gtsmodel.NotificationFollow
targetAccount = suite.testAccounts["local_account_1"]
originAccount = suite.testAccounts["local_account_2"]