summaryrefslogtreecommitdiff
path: root/internal/typeutils
diff options
context:
space:
mode:
Diffstat (limited to 'internal/typeutils')
-rw-r--r--internal/typeutils/astointernal_test.go48
-rw-r--r--internal/typeutils/internaltoas_test.go53
-rw-r--r--internal/typeutils/internaltofrontend_test.go84
-rw-r--r--internal/typeutils/internaltorss_test.go7
-rw-r--r--internal/typeutils/util_test.go4
-rw-r--r--internal/typeutils/wrap_test.go7
6 files changed, 99 insertions, 104 deletions
diff --git a/internal/typeutils/astointernal_test.go b/internal/typeutils/astointernal_test.go
index fb453c89e..7e18ceefb 100644
--- a/internal/typeutils/astointernal_test.go
+++ b/internal/typeutils/astointernal_test.go
@@ -37,7 +37,7 @@ type ASToInternalTestSuite struct {
}
func (suite *ASToInternalTestSuite) jsonToType(in string) vocab.Type {
- ctx := context.Background()
+ ctx := suite.T().Context()
b := []byte(in)
if accountable, err := ap.ResolveAccountable(ctx, io.NopCloser(bytes.NewReader(b))); err == nil {
@@ -53,7 +53,7 @@ func (suite *ASToInternalTestSuite) jsonToType(in string) vocab.Type {
suite.FailNow(err.Error())
}
- t, err := streams.ToType(context.Background(), m)
+ t, err := streams.ToType(suite.T().Context(), m)
if err != nil {
suite.FailNow(err.Error())
}
@@ -64,7 +64,7 @@ func (suite *ASToInternalTestSuite) jsonToType(in string) vocab.Type {
func (suite *ASToInternalTestSuite) TestParsePerson() {
testPerson := suite.testPeople["https://unknown-instance.com/users/brand_new_person"]
- acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), testPerson, "", "")
+ acct, err := suite.typeconverter.ASRepresentationToAccount(suite.T().Context(), testPerson, "", "")
suite.NoError(err)
suite.Equal("https://unknown-instance.com/users/brand_new_person", acct.URI)
@@ -86,7 +86,7 @@ func (suite *ASToInternalTestSuite) TestParsePerson() {
func (suite *ASToInternalTestSuite) TestParsePersonWithSharedInbox() {
testPerson := suite.testPeople["https://turnip.farm/users/turniplover6969"]
- acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), testPerson, "", "")
+ acct, err := suite.typeconverter.ASRepresentationToAccount(suite.T().Context(), testPerson, "", "")
suite.NoError(err)
suite.Equal("https://turnip.farm/users/turniplover6969", acct.URI)
@@ -112,7 +112,7 @@ func (suite *ASToInternalTestSuite) TestParsePublicStatus() {
suite.FailNow("type not coercible")
}
- status, err := suite.typeconverter.ASStatusToStatus(context.Background(), rep)
+ status, err := suite.typeconverter.ASStatusToStatus(suite.T().Context(), rep)
suite.NoError(err)
suite.Equal("reading: Punishment and Reward in the Corporate University", status.ContentWarning)
@@ -127,7 +127,7 @@ func (suite *ASToInternalTestSuite) TestParsePublicStatusNoURL() {
suite.FailNow("type not coercible")
}
- status, err := suite.typeconverter.ASStatusToStatus(context.Background(), rep)
+ status, err := suite.typeconverter.ASStatusToStatus(suite.T().Context(), rep)
suite.NoError(err)
suite.Equal("reading: Punishment and Reward in the Corporate University", status.ContentWarning)
@@ -144,7 +144,7 @@ func (suite *ASToInternalTestSuite) TestParseGargron() {
suite.FailNow("type not coercible")
}
- acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, "", "")
+ acct, err := suite.typeconverter.ASRepresentationToAccount(suite.T().Context(), rep, "", "")
suite.NoError(err)
suite.Equal("https://mastodon.social/inbox", *acct.SharedInboxURI)
suite.Equal([]string{"https://tooting.ai/users/Gargron"}, acct.AlsoKnownAsURIs)
@@ -162,7 +162,7 @@ func (suite *ASToInternalTestSuite) TestParseReplyWithMention() {
var status *gtsmodel.Status
for i := object.Begin(); i != nil; i = i.Next() {
statusable := i.GetActivityStreamsNote()
- s, err := suite.typeconverter.ASStatusToStatus(context.Background(), statusable)
+ s, err := suite.typeconverter.ASStatusToStatus(suite.T().Context(), statusable)
suite.NoError(err)
status = s
break
@@ -195,7 +195,7 @@ func (suite *ASToInternalTestSuite) TestParseOwncastService() {
suite.FailNow("type not coercible")
}
- acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, "", "")
+ acct, err := suite.typeconverter.ASRepresentationToAccount(suite.T().Context(), rep, "", "")
suite.NoError(err)
suite.Equal("rgh", acct.Username)
@@ -216,7 +216,7 @@ func (suite *ASToInternalTestSuite) TestParseOwncastService() {
acct.ID = "01G42D57DTCJQE8XT9KD4K88RK"
- apiAcct, err := suite.typeconverter.AccountToAPIAccountPublic(context.Background(), acct)
+ apiAcct, err := suite.typeconverter.AccountToAPIAccountPublic(suite.T().Context(), acct)
suite.NoError(err)
suite.NotNil(apiAcct)
@@ -270,7 +270,7 @@ func (suite *ASToInternalTestSuite) TestParseBookwyrmStatus() {
suite.FailNow("type not coercible")
}
- status, err := suite.typeconverter.ASStatusToStatus(context.Background(), asArticle)
+ status, err := suite.typeconverter.ASStatusToStatus(suite.T().Context(), asArticle)
if err != nil {
suite.FailNow(err.Error())
}
@@ -330,7 +330,7 @@ func (suite *ASToInternalTestSuite) TestParseBandwagonAlbum() {
suite.FailNow("type not coercible")
}
- s, err := suite.typeconverter.ASStatusToStatus(context.Background(), asArticle)
+ s, err := suite.typeconverter.ASStatusToStatus(suite.T().Context(), asArticle)
if err != nil {
suite.FailNow(err.Error())
}
@@ -358,7 +358,7 @@ func (suite *ASToInternalTestSuite) TestParseFlag1() {
suite.FailNow("type not coercible")
}
- report, err := suite.typeconverter.ASFlagToReport(context.Background(), asFlag)
+ report, err := suite.typeconverter.ASFlagToReport(suite.T().Context(), asFlag)
if err != nil {
suite.FailNow(err.Error())
}
@@ -392,7 +392,7 @@ func (suite *ASToInternalTestSuite) TestParseFlag2() {
suite.FailNow("type not coercible")
}
- report, err := suite.typeconverter.ASFlagToReport(context.Background(), asFlag)
+ report, err := suite.typeconverter.ASFlagToReport(suite.T().Context(), asFlag)
if err != nil {
suite.FailNow(err.Error())
}
@@ -426,7 +426,7 @@ func (suite *ASToInternalTestSuite) TestParseFlag3() {
suite.FailNow("type not coercible")
}
- report, err := suite.typeconverter.ASFlagToReport(context.Background(), asFlag)
+ report, err := suite.typeconverter.ASFlagToReport(suite.T().Context(), asFlag)
suite.Nil(report)
suite.EqualError(err, "ASFlagToReport: error getting target account http://localhost:8080/users/mr_e_man from database: sql: no rows in result set")
}
@@ -451,7 +451,7 @@ func (suite *ASToInternalTestSuite) TestParseFlag4() {
suite.FailNow("type not coercible")
}
- report, err := suite.typeconverter.ASFlagToReport(context.Background(), asFlag)
+ report, err := suite.typeconverter.ASFlagToReport(suite.T().Context(), asFlag)
suite.Nil(report)
suite.EqualError(err, "ASFlagToReport: missing target account uri for http://fossbros-anonymous.io/db22128d-884e-4358-9935-6a7c3940535d")
}
@@ -479,7 +479,7 @@ func (suite *ASToInternalTestSuite) TestParseFlag5() {
suite.FailNow("type not coercible")
}
- report, err := suite.typeconverter.ASFlagToReport(context.Background(), asFlag)
+ report, err := suite.typeconverter.ASFlagToReport(suite.T().Context(), asFlag)
if err != nil {
suite.FailNow(err.Error())
}
@@ -516,7 +516,7 @@ func (suite *ASToInternalTestSuite) TestParseFlag6() {
suite.FailNow("type not coercible")
}
- report, err := suite.typeconverter.ASFlagToReport(context.Background(), asFlag)
+ report, err := suite.typeconverter.ASFlagToReport(suite.T().Context(), asFlag)
if err != nil {
suite.FailNow(err.Error())
}
@@ -549,7 +549,7 @@ func (suite *ASToInternalTestSuite) TestParseAnnounce() {
suite.FailNow("type not coercible")
}
- boost, isNew, err := suite.typeconverter.ASAnnounceToStatus(context.Background(), asAnnounce)
+ boost, isNew, err := suite.typeconverter.ASAnnounceToStatus(suite.T().Context(), asAnnounce)
if err != nil {
suite.FailNow(err.Error())
}
@@ -603,7 +603,7 @@ func (suite *ASToInternalTestSuite) TestParseHonkAccount() {
suite.FailNow("type not coercible")
}
- acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, "", "")
+ acct, err := suite.typeconverter.ASRepresentationToAccount(suite.T().Context(), rep, "", "")
suite.NoError(err)
suite.Equal("https://honk.example.org/u/honk_user/followers", acct.FollowersURI)
suite.Equal("https://honk.example.org/u/honk_user/following", acct.FollowingURI)
@@ -618,7 +618,7 @@ func (suite *ASToInternalTestSuite) TestParseHonkAccount() {
// Store the account representation.
acct.ID = "01HMGRMAVQMYQC3DDQ29TPQKJ3" // <- needs an ID
- ctx := context.Background()
+ ctx := suite.T().Context()
if err := suite.db.PutAccount(ctx, acct); err != nil {
suite.FailNow(err.Error())
}
@@ -708,7 +708,7 @@ func (suite *ASToInternalTestSuite) TestParseHonkAccount() {
}
func (suite *ASToInternalTestSuite) TestParseAccountableWithoutPreferredUsername() {
- ctx, cncl := context.WithCancel(context.Background())
+ ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
testPerson := suite.testPeople["https://unknown-instance.com/users/brand_new_person"]
@@ -726,7 +726,7 @@ func (suite *ASToInternalTestSuite) TestParseAccountableWithoutPreferredUsername
}
func (suite *ASToInternalTestSuite) TestParseAccountableWithoutAnyUsername() {
- ctx, cncl := context.WithCancel(context.Background())
+ ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
testPerson := suite.testPeople["https://unknown-instance.com/users/brand_new_person"]
@@ -744,7 +744,7 @@ func (suite *ASToInternalTestSuite) TestParseAccountableWithoutAnyUsername() {
}
func (suite *ASToInternalTestSuite) TestParseAccountableWithPreferredUsername() {
- ctx, cncl := context.WithCancel(context.Background())
+ ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
testPerson := suite.testPeople["https://unknown-instance.com/users/brand_new_person"]
diff --git a/internal/typeutils/internaltoas_test.go b/internal/typeutils/internaltoas_test.go
index 5ba23a77e..ab81095fd 100644
--- a/internal/typeutils/internaltoas_test.go
+++ b/internal/typeutils/internaltoas_test.go
@@ -18,7 +18,6 @@
package typeutils_test
import (
- "context"
"encoding/json"
"errors"
"testing"
@@ -38,7 +37,7 @@ func (suite *InternalToASTestSuite) TestAccountToAS() {
testAccount := &gtsmodel.Account{}
*testAccount = *suite.testAccounts["local_account_1"] // take zork for this test
- accountable, err := suite.typeconverter.AccountToAS(context.Background(), testAccount)
+ accountable, err := suite.typeconverter.AccountToAS(suite.T().Context(), testAccount)
suite.NoError(err)
ser, err := ap.Serialize(accountable)
@@ -100,11 +99,11 @@ func (suite *InternalToASTestSuite) TestAccountToASBot() {
// Update zork to be a bot.
testAccount.ActorType = gtsmodel.AccountActorTypeApplication
- if err := suite.state.DB.UpdateAccount(context.Background(), testAccount); err != nil {
+ if err := suite.state.DB.UpdateAccount(suite.T().Context(), testAccount); err != nil {
suite.FailNow(err.Error())
}
- accountable, err := suite.typeconverter.AccountToAS(context.Background(), testAccount)
+ accountable, err := suite.typeconverter.AccountToAS(suite.T().Context(), testAccount)
suite.NoError(err)
ser, err := ap.Serialize(accountable)
@@ -164,7 +163,7 @@ func (suite *InternalToASTestSuite) TestAccountToASWithFields() {
testAccount := &gtsmodel.Account{}
*testAccount = *suite.testAccounts["local_account_2"]
- accountable, err := suite.typeconverter.AccountToAS(context.Background(), testAccount)
+ accountable, err := suite.typeconverter.AccountToAS(suite.T().Context(), testAccount)
suite.NoError(err)
ser, err := ap.Serialize(accountable)
@@ -229,7 +228,7 @@ func (suite *InternalToASTestSuite) TestAccountToASAliasedAndMoved() {
testAccount := &gtsmodel.Account{}
*testAccount = *suite.testAccounts["local_account_1"] // take zork for this test
- ctx := context.Background()
+ ctx := suite.T().Context()
// Suppose zork has moved account to turtle.
testAccount.AlsoKnownAsURIs = []string{"http://localhost:8080/users/1happyturtle"}
@@ -242,7 +241,7 @@ func (suite *InternalToASTestSuite) TestAccountToASAliasedAndMoved() {
suite.FailNow(err.Error())
}
- accountable, err := suite.typeconverter.AccountToAS(context.Background(), testAccount)
+ accountable, err := suite.typeconverter.AccountToAS(suite.T().Context(), testAccount)
suite.NoError(err)
ser, err := ap.Serialize(accountable)
@@ -312,7 +311,7 @@ func (suite *InternalToASTestSuite) TestAccountToASWithOneField() {
*testAccount = *suite.testAccounts["local_account_2"]
testAccount.Fields = testAccount.Fields[0:1] // Take only one field.
- accountable, err := suite.typeconverter.AccountToAS(context.Background(), testAccount)
+ accountable, err := suite.typeconverter.AccountToAS(suite.T().Context(), testAccount)
suite.NoError(err)
ser, err := ap.Serialize(accountable)
@@ -374,7 +373,7 @@ func (suite *InternalToASTestSuite) TestAccountToASWithEmoji() {
*testAccount = *suite.testAccounts["local_account_1"] // take zork for this test
testAccount.Emojis = []*gtsmodel.Emoji{suite.testEmojis["rainbow"]}
- accountable, err := suite.typeconverter.AccountToAS(context.Background(), testAccount)
+ accountable, err := suite.typeconverter.AccountToAS(suite.T().Context(), testAccount)
suite.NoError(err)
ser, err := ap.Serialize(accountable)
@@ -447,7 +446,7 @@ func (suite *InternalToASTestSuite) TestAccountToASWithSharedInbox() {
sharedInbox := "http://localhost:8080/sharedInbox"
testAccount.SharedInboxURI = &sharedInbox
- accountable, err := suite.typeconverter.AccountToAS(context.Background(), testAccount)
+ accountable, err := suite.typeconverter.AccountToAS(suite.T().Context(), testAccount)
suite.NoError(err)
ser, err := ap.Serialize(accountable)
@@ -508,7 +507,7 @@ func (suite *InternalToASTestSuite) TestAccountToASWithSharedInbox() {
func (suite *InternalToASTestSuite) TestStatusToAS() {
testStatus := suite.testStatuses["local_account_1_status_1"]
- ctx := context.Background()
+ ctx := suite.T().Context()
asStatus, err := suite.typeconverter.StatusToAS(ctx, testStatus)
suite.NoError(err)
@@ -590,7 +589,7 @@ func (suite *InternalToASTestSuite) TestStatusToAS() {
func (suite *InternalToASTestSuite) TestStatusWithTagsToASWithIDs() {
// use the status with just IDs of attachments and emojis pinned on it
testStatus := suite.testStatuses["admin_account_status_1"]
- ctx := context.Background()
+ ctx := suite.T().Context()
asStatus, err := suite.typeconverter.StatusToAS(ctx, testStatus)
suite.NoError(err)
@@ -707,7 +706,7 @@ func (suite *InternalToASTestSuite) TestStatusWithTagsToASWithIDs() {
}
func (suite *InternalToASTestSuite) TestStatusWithTagsToASFromDB() {
- ctx := context.Background()
+ ctx := suite.T().Context()
// get the entire status with all tags
testStatus, err := suite.db.GetStatusByID(ctx, suite.testStatuses["admin_account_status_1"].ID)
suite.NoError(err)
@@ -828,7 +827,7 @@ func (suite *InternalToASTestSuite) TestStatusWithTagsToASFromDB() {
func (suite *InternalToASTestSuite) TestStatusToASWithMentions() {
testStatusID := suite.testStatuses["admin_account_status_3"].ID
- ctx := context.Background()
+ ctx := suite.T().Context()
testStatus, err := suite.db.GetStatusByID(ctx, testStatusID)
suite.NoError(err)
@@ -920,7 +919,7 @@ func (suite *InternalToASTestSuite) TestStatusToASWithMentions() {
func (suite *InternalToASTestSuite) TestStatusToASDeletePublicReply() {
testStatus := suite.testStatuses["admin_account_status_3"]
- ctx := context.Background()
+ ctx := suite.T().Context()
asDelete, err := suite.typeconverter.StatusToASDelete(ctx, testStatus)
suite.NoError(err)
@@ -946,7 +945,7 @@ func (suite *InternalToASTestSuite) TestStatusToASDeletePublicReply() {
func (suite *InternalToASTestSuite) TestStatusToASDeletePublicReplyOriginalDeleted() {
testStatus := suite.testStatuses["admin_account_status_3"]
- ctx := context.Background()
+ ctx := suite.T().Context()
// Delete the status this replies to.
if err := suite.db.DeleteStatusByID(ctx, testStatus.ID); err != nil {
@@ -984,7 +983,7 @@ func (suite *InternalToASTestSuite) TestStatusToASDeletePublicReplyOriginalDelet
func (suite *InternalToASTestSuite) TestStatusToASDeletePublic() {
testStatus := suite.testStatuses["admin_account_status_1"]
- ctx := context.Background()
+ ctx := suite.T().Context()
asDelete, err := suite.typeconverter.StatusToASDelete(ctx, testStatus)
suite.NoError(err)
@@ -1007,7 +1006,7 @@ func (suite *InternalToASTestSuite) TestStatusToASDeletePublic() {
func (suite *InternalToASTestSuite) TestStatusToASDeleteDirectMessage() {
testStatus := suite.testStatuses["local_account_2_status_6"]
- ctx := context.Background()
+ ctx := suite.T().Context()
asDelete, err := suite.typeconverter.StatusToASDelete(ctx, testStatus)
suite.NoError(err)
@@ -1030,7 +1029,7 @@ func (suite *InternalToASTestSuite) TestStatusToASDeleteDirectMessage() {
func (suite *InternalToASTestSuite) TestStatusesToASOutboxPage() {
testAccount := suite.testAccounts["admin_account"]
- ctx := context.Background()
+ ctx := suite.T().Context()
// get public statuses from testaccount
statuses, err := suite.db.GetAccountStatuses(ctx, testAccount.ID, 30, true, true, "", "", false, true)
@@ -1076,7 +1075,7 @@ func (suite *InternalToASTestSuite) TestStatusesToASOutboxPage() {
}
func (suite *InternalToASTestSuite) TestSelfBoostFollowersOnlyToAS() {
- ctx := context.Background()
+ ctx := suite.T().Context()
testStatus := suite.testStatuses["local_account_1_status_5"]
testAccount := suite.testAccounts["local_account_1"]
@@ -1112,7 +1111,7 @@ func (suite *InternalToASTestSuite) TestSelfBoostFollowersOnlyToAS() {
}
func (suite *InternalToASTestSuite) TestReportToAS() {
- ctx := context.Background()
+ ctx := suite.T().Context()
testReport := suite.testReports["local_account_2_report_remote_account_1"]
account := suite.testAccounts["local_account_2"]
@@ -1146,7 +1145,7 @@ func (suite *InternalToASTestSuite) TestReportToAS() {
}
func (suite *InternalToASTestSuite) TestPinnedStatusesToASSomeItems() {
- ctx := context.Background()
+ ctx := suite.T().Context()
testAccount := suite.testAccounts["admin_account"]
statuses, err := suite.db.GetAccountPinnedStatuses(ctx, testAccount.ID)
@@ -1178,7 +1177,7 @@ func (suite *InternalToASTestSuite) TestPinnedStatusesToASSomeItems() {
}
func (suite *InternalToASTestSuite) TestPinnedStatusesToASNoItems() {
- ctx := context.Background()
+ ctx := suite.T().Context()
testAccount := suite.testAccounts["local_account_1"]
statuses, err := suite.db.GetAccountPinnedStatuses(ctx, testAccount.ID)
@@ -1207,7 +1206,7 @@ func (suite *InternalToASTestSuite) TestPinnedStatusesToASNoItems() {
}
func (suite *InternalToASTestSuite) TestPinnedStatusesToASOneItem() {
- ctx := context.Background()
+ ctx := suite.T().Context()
testAccount := suite.testAccounts["local_account_2"]
statuses, err := suite.db.GetAccountPinnedStatuses(ctx, testAccount.ID)
@@ -1240,7 +1239,7 @@ func (suite *InternalToASTestSuite) TestPinnedStatusesToASOneItem() {
func (suite *InternalToASTestSuite) TestPollVoteToASCreate() {
vote := suite.testPollVotes["remote_account_1_status_2_poll_vote_local_account_1"]
- creates, err := suite.typeconverter.PollVoteToASCreates(context.Background(), vote)
+ creates, err := suite.typeconverter.PollVoteToASCreates(suite.T().Context(), vote)
suite.NoError(err)
suite.Len(creates, 2)
@@ -1311,7 +1310,7 @@ func (suite *InternalToASTestSuite) TestInteractionReqToASAcceptAnnounce() {
}
accept, err := suite.typeconverter.InteractionReqToASAccept(
- context.Background(),
+ suite.T().Context(),
req,
)
if err != nil {
@@ -1363,7 +1362,7 @@ func (suite *InternalToASTestSuite) TestInteractionReqToASAcceptLike() {
}
accept, err := suite.typeconverter.InteractionReqToASAccept(
- context.Background(),
+ suite.T().Context(),
req,
)
if err != nil {
diff --git a/internal/typeutils/internaltofrontend_test.go b/internal/typeutils/internaltofrontend_test.go
index 74250769b..c1b29ad21 100644
--- a/internal/typeutils/internaltofrontend_test.go
+++ b/internal/typeutils/internaltofrontend_test.go
@@ -41,7 +41,7 @@ type InternalToFrontendTestSuite struct {
func (suite *InternalToFrontendTestSuite) TestAccountToFrontend() {
testAccount := suite.testAccounts["local_account_1"] // take zork for this test
- apiAccount, err := suite.typeconverter.AccountToAPIAccountPublic(context.Background(), testAccount)
+ apiAccount, err := suite.typeconverter.AccountToAPIAccountPublic(suite.T().Context(), testAccount)
suite.NoError(err)
suite.NotNil(apiAccount)
@@ -88,11 +88,11 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendAliasedAndMoved()
testAccount.MovedToURI = movedTo.URI
testAccount.AlsoKnownAsURIs = []string{movedTo.URI}
- if err := suite.state.DB.UpdateAccount(context.Background(), testAccount, "moved_to_uri"); err != nil {
+ if err := suite.state.DB.UpdateAccount(suite.T().Context(), testAccount, "moved_to_uri"); err != nil {
suite.FailNow(err.Error())
}
- apiAccount, err := suite.typeconverter.AccountToAPIAccountSensitive(context.Background(), testAccount)
+ apiAccount, err := suite.typeconverter.AccountToAPIAccountSensitive(suite.T().Context(), testAccount)
suite.NoError(err)
suite.NotNil(apiAccount)
@@ -195,7 +195,7 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendWithEmojiStruct()
testAccount.Emojis = []*gtsmodel.Emoji{testEmoji}
testAccount.EmojiIDs = []string{testEmoji.ID}
- apiAccount, err := suite.typeconverter.AccountToAPIAccountPublic(context.Background(), testAccount)
+ apiAccount, err := suite.typeconverter.AccountToAPIAccountPublic(suite.T().Context(), testAccount)
suite.NoError(err)
suite.NotNil(apiAccount)
@@ -245,7 +245,7 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendWithEmojiIDs() {
testAccount.EmojiIDs = []string{testEmoji.ID}
- apiAccount, err := suite.typeconverter.AccountToAPIAccountPublic(context.Background(), testAccount)
+ apiAccount, err := suite.typeconverter.AccountToAPIAccountPublic(suite.T().Context(), testAccount)
suite.NoError(err)
suite.NotNil(apiAccount)
@@ -291,7 +291,7 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendWithEmojiIDs() {
func (suite *InternalToFrontendTestSuite) TestAccountToFrontendSensitive() {
testAccount := suite.testAccounts["local_account_1"] // take zork for this test
- apiAccount, err := suite.typeconverter.AccountToAPIAccountSensitive(context.Background(), testAccount)
+ apiAccount, err := suite.typeconverter.AccountToAPIAccountSensitive(suite.T().Context(), testAccount)
suite.NoError(err)
suite.NotNil(apiAccount)
@@ -347,7 +347,7 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendSensitive() {
func (suite *InternalToFrontendTestSuite) TestAccountToFrontendPublicPunycode() {
testAccount := suite.testAccounts["remote_account_4"]
- apiAccount, err := suite.typeconverter.AccountToAPIAccountPublic(context.Background(), testAccount)
+ apiAccount, err := suite.typeconverter.AccountToAPIAccountPublic(suite.T().Context(), testAccount)
suite.NoError(err)
suite.NotNil(apiAccount)
@@ -384,7 +384,7 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendPublicPunycode()
}
func (suite *InternalToFrontendTestSuite) TestLocalInstanceAccountToFrontendPublic() {
- ctx := context.Background()
+ ctx := suite.T().Context()
testAccount, err := suite.db.GetInstanceAccount(ctx, "")
if err != nil {
suite.FailNow(err.Error())
@@ -424,7 +424,7 @@ func (suite *InternalToFrontendTestSuite) TestLocalInstanceAccountToFrontendPubl
}
func (suite *InternalToFrontendTestSuite) TestLocalInstanceAccountToFrontendBlocked() {
- ctx := context.Background()
+ ctx := suite.T().Context()
testAccount, err := suite.db.GetInstanceAccount(ctx, "")
if err != nil {
suite.FailNow(err.Error())
@@ -466,7 +466,7 @@ func (suite *InternalToFrontendTestSuite) TestLocalInstanceAccountToFrontendBloc
func (suite *InternalToFrontendTestSuite) TestStatusToFrontend() {
testStatus := suite.testStatuses["admin_account_status_1"]
requestingAccount := suite.testAccounts["local_account_1"]
- apiStatus, err := suite.typeconverter.StatusToAPIStatus(context.Background(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
+ apiStatus, err := suite.typeconverter.StatusToAPIStatus(suite.T().Context(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
suite.NoError(err)
b, err := json.MarshalIndent(apiStatus, "", " ")
@@ -629,7 +629,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendHTMLContentWarning
testStatus.ContentWarning = `<p>First paragraph of content warning</p><h4>Here's the title!</h4><p></p><p>Big boobs<br>Tee hee!<br><br>Some more text<br>And a bunch more<br><br>Hasta la victoria siempre!</p>`
requestingAccount := suite.testAccounts["local_account_1"]
- apiStatus, err := suite.typeconverter.StatusToAPIStatus(context.Background(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
+ apiStatus, err := suite.typeconverter.StatusToAPIStatus(suite.T().Context(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
suite.NoError(err)
b, err := json.MarshalIndent(apiStatus, "", " ")
@@ -786,7 +786,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendHTMLContentWarning
}
func (suite *InternalToFrontendTestSuite) TestStatusToFrontendApplicationDeleted() {
- ctx := context.Background()
+ ctx := suite.T().Context()
testStatus := suite.testStatuses["admin_account_status_1"]
// Delete the application this status was created with.
@@ -979,7 +979,7 @@ func (suite *InternalToFrontendTestSuite) filteredStatusToFrontend(action gtsmod
requestingAccountFilters := []*gtsmodel.Filter{expectedMatchingFilter}
return suite.typeconverter.StatusToAPIStatus(
- context.Background(),
+ suite.T().Context(),
testStatus,
requestingAccount,
statusfilter.FilterContextHome,
@@ -1500,7 +1500,7 @@ func (suite *InternalToFrontendTestSuite) testHashtagFilteredStatusToFrontend(wh
if boost {
boost, err := suite.typeconverter.StatusToBoost(
- context.Background(),
+ suite.T().Context(),
testStatus,
suite.testAccounts["admin_account"],
"",
@@ -1533,7 +1533,7 @@ func (suite *InternalToFrontendTestSuite) testHashtagFilteredStatusToFrontend(wh
}
apiStatus, err := suite.typeconverter.StatusToAPIStatus(
- context.Background(),
+ suite.T().Context(),
testStatus,
requestingAccount,
statusfilter.FilterContextHome,
@@ -1577,7 +1577,7 @@ func (suite *InternalToFrontendTestSuite) TestMutedStatusToFrontend() {
})
_, err := suite.typeconverter.StatusToAPIStatus(
- context.Background(),
+ suite.T().Context(),
testStatus,
requestingAccount,
statusfilter.FilterContextHome,
@@ -1604,14 +1604,14 @@ func (suite *InternalToFrontendTestSuite) TestMutedReplyStatusToFrontend() {
})
// Populate status so the converter has the account objects it needs for muting.
- err := suite.db.PopulateStatus(context.Background(), testStatus)
+ err := suite.db.PopulateStatus(suite.T().Context(), testStatus)
if err != nil {
suite.FailNow(err.Error())
}
// Convert the status to API format, which should fail.
_, err = suite.typeconverter.StatusToAPIStatus(
- context.Background(),
+ suite.T().Context(),
testStatus,
requestingAccount,
statusfilter.FilterContextHome,
@@ -1637,14 +1637,14 @@ func (suite *InternalToFrontendTestSuite) TestMutedBoostStatusToFrontend() {
})
// Populate status so the converter has the account objects it needs for muting.
- err := suite.db.PopulateStatus(context.Background(), testStatus)
+ err := suite.db.PopulateStatus(suite.T().Context(), testStatus)
if err != nil {
suite.FailNow(err.Error())
}
// Convert the status to API format, which should fail.
_, err = suite.typeconverter.StatusToAPIStatus(
- context.Background(),
+ suite.T().Context(),
testStatus,
requestingAccount,
statusfilter.FilterContextHome,
@@ -1658,7 +1658,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendUnknownAttachments
testStatus := suite.testStatuses["remote_account_2_status_1"]
requestingAccount := suite.testAccounts["admin_account"]
- apiStatus, err := suite.typeconverter.StatusToAPIStatus(context.Background(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
+ apiStatus, err := suite.typeconverter.StatusToAPIStatus(suite.T().Context(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
suite.NoError(err)
b, err := json.MarshalIndent(apiStatus, "", " ")
@@ -1797,7 +1797,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendUnknownAttachments
func (suite *InternalToFrontendTestSuite) TestStatusToWebStatus() {
testStatus := suite.testStatuses["remote_account_2_status_1"]
- apiStatus, err := suite.typeconverter.StatusToWebStatus(context.Background(), testStatus)
+ apiStatus, err := suite.typeconverter.StatusToWebStatus(suite.T().Context(), testStatus)
suite.NoError(err)
// MediaAttachments should inherit
@@ -1985,7 +1985,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendUnknownLanguage()
*testStatus = *suite.testStatuses["admin_account_status_1"]
testStatus.Language = ""
requestingAccount := suite.testAccounts["local_account_1"]
- apiStatus, err := suite.typeconverter.StatusToAPIStatus(context.Background(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
+ apiStatus, err := suite.typeconverter.StatusToAPIStatus(suite.T().Context(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
suite.NoError(err)
b, err := json.MarshalIndent(apiStatus, "", " ")
@@ -2146,7 +2146,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendPartialInteraction
*testStatus = *suite.testStatuses["local_account_1_status_3"]
testStatus.Language = ""
requestingAccount := suite.testAccounts["admin_account"]
- apiStatus, err := suite.typeconverter.StatusToAPIStatus(context.Background(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
+ apiStatus, err := suite.typeconverter.StatusToAPIStatus(suite.T().Context(), testStatus, requestingAccount, statusfilter.FilterContextNone, nil, nil)
suite.NoError(err)
b, err := json.MarshalIndent(apiStatus, "", " ")
@@ -2256,7 +2256,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToAPIStatusPendingApproval()
)
apiStatus, err := suite.typeconverter.StatusToAPIStatus(
- context.Background(),
+ suite.T().Context(),
testStatus,
requestingAccount,
statusfilter.FilterContextNone,
@@ -2394,7 +2394,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToAPIStatusPendingApproval()
func (suite *InternalToFrontendTestSuite) TestVideoAttachmentToFrontend() {
testAttachment := suite.testAttachments["local_account_1_status_4_attachment_2"]
- apiAttachment, err := suite.typeconverter.AttachmentToAPIAttachment(context.Background(), testAttachment)
+ apiAttachment, err := suite.typeconverter.AttachmentToAPIAttachment(suite.T().Context(), testAttachment)
suite.NoError(err)
b, err := json.MarshalIndent(apiAttachment, "", " ")
@@ -2435,7 +2435,7 @@ func (suite *InternalToFrontendTestSuite) TestVideoAttachmentToFrontend() {
}
func (suite *InternalToFrontendTestSuite) TestInstanceV1ToFrontend() {
- ctx := context.Background()
+ ctx := suite.T().Context()
i := &gtsmodel.Instance{}
if err := suite.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: config.GetHost()}}, i); err != nil {
@@ -2572,7 +2572,7 @@ func (suite *InternalToFrontendTestSuite) TestInstanceV1ToFrontend() {
}
func (suite *InternalToFrontendTestSuite) TestInstanceV2ToFrontend() {
- ctx := context.Background()
+ ctx := suite.T().Context()
i := &gtsmodel.Instance{}
if err := suite.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: config.GetHost()}}, i); err != nil {
@@ -2726,7 +2726,7 @@ func (suite *InternalToFrontendTestSuite) TestInstanceV2ToFrontend() {
}
func (suite *InternalToFrontendTestSuite) TestEmojiToFrontend() {
- emoji, err := suite.typeconverter.EmojiToAPIEmoji(context.Background(), suite.testEmojis["rainbow"])
+ emoji, err := suite.typeconverter.EmojiToAPIEmoji(suite.T().Context(), suite.testEmojis["rainbow"])
suite.NoError(err)
b, err := json.MarshalIndent(emoji, "", " ")
@@ -2742,7 +2742,7 @@ func (suite *InternalToFrontendTestSuite) TestEmojiToFrontend() {
}
func (suite *InternalToFrontendTestSuite) TestEmojiToFrontendAdmin1() {
- emoji, err := suite.typeconverter.EmojiToAdminAPIEmoji(context.Background(), suite.testEmojis["rainbow"])
+ emoji, err := suite.typeconverter.EmojiToAdminAPIEmoji(suite.T().Context(), suite.testEmojis["rainbow"])
suite.NoError(err)
b, err := json.MarshalIndent(emoji, "", " ")
@@ -2764,7 +2764,7 @@ func (suite *InternalToFrontendTestSuite) TestEmojiToFrontendAdmin1() {
}
func (suite *InternalToFrontendTestSuite) TestEmojiToFrontendAdmin2() {
- emoji, err := suite.typeconverter.EmojiToAdminAPIEmoji(context.Background(), suite.testEmojis["yell"])
+ emoji, err := suite.typeconverter.EmojiToAdminAPIEmoji(suite.T().Context(), suite.testEmojis["yell"])
suite.NoError(err)
b, err := json.MarshalIndent(emoji, "", " ")
@@ -2786,7 +2786,7 @@ func (suite *InternalToFrontendTestSuite) TestEmojiToFrontendAdmin2() {
}
func (suite *InternalToFrontendTestSuite) TestReportToFrontend1() {
- report, err := suite.typeconverter.ReportToAPIReport(context.Background(), suite.testReports["local_account_2_report_remote_account_1"])
+ report, err := suite.typeconverter.ReportToAPIReport(suite.T().Context(), suite.testReports["local_account_2_report_remote_account_1"])
suite.NoError(err)
b, err := json.MarshalIndent(report, "", " ")
@@ -2836,7 +2836,7 @@ func (suite *InternalToFrontendTestSuite) TestReportToFrontend1() {
}
func (suite *InternalToFrontendTestSuite) TestReportToFrontend2() {
- report, err := suite.typeconverter.ReportToAPIReport(context.Background(), suite.testReports["remote_account_1_report_local_account_2"])
+ report, err := suite.typeconverter.ReportToAPIReport(suite.T().Context(), suite.testReports["remote_account_1_report_local_account_2"])
suite.NoError(err)
b, err := json.MarshalIndent(report, "", " ")
@@ -2894,7 +2894,7 @@ func (suite *InternalToFrontendTestSuite) TestReportToFrontend2() {
func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend1() {
requestingAccount := suite.testAccounts["admin_account"]
- adminReport, err := suite.typeconverter.ReportToAdminAPIReport(context.Background(), suite.testReports["remote_account_1_report_local_account_2"], requestingAccount)
+ adminReport, err := suite.typeconverter.ReportToAdminAPIReport(suite.T().Context(), suite.testReports["remote_account_1_report_local_account_2"], requestingAccount)
suite.NoError(err)
b, err := json.MarshalIndent(adminReport, "", " ")
@@ -3136,7 +3136,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend1() {
func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend2() {
requestingAccount := suite.testAccounts["admin_account"]
- adminReport, err := suite.typeconverter.ReportToAdminAPIReport(context.Background(), suite.testReports["local_account_2_report_remote_account_1"], requestingAccount)
+ adminReport, err := suite.typeconverter.ReportToAdminAPIReport(suite.T().Context(), suite.testReports["local_account_2_report_remote_account_1"], requestingAccount)
suite.NoError(err)
b, err := json.MarshalIndent(adminReport, "", " ")
@@ -3398,7 +3398,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend2() {
}
func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontendSuspendedLocalAccount() {
- ctx := context.Background()
+ ctx := suite.T().Context()
requestingAccount := suite.testAccounts["admin_account"]
reportedAccount := &gtsmodel.Account{}
*reportedAccount = *suite.testAccounts["local_account_2"]
@@ -3421,7 +3421,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontendSuspendedLoca
suite.FailNow("timed out waiting for account delete")
}
- adminReport, err := suite.typeconverter.ReportToAdminAPIReport(context.Background(), suite.testReports["remote_account_1_report_local_account_2"], requestingAccount)
+ adminReport, err := suite.typeconverter.ReportToAdminAPIReport(suite.T().Context(), suite.testReports["remote_account_1_report_local_account_2"], requestingAccount)
suite.NoError(err)
b, err := json.MarshalIndent(adminReport, "", " ")
@@ -3652,7 +3652,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontendSuspendedLoca
func (suite *InternalToFrontendTestSuite) TestRelationshipFollowRequested() {
var (
- ctx = context.Background()
+ ctx = suite.T().Context()
account1 = suite.testAccounts["admin_account"]
account2 = suite.testAccounts["local_account_2"]
)
@@ -3741,7 +3741,7 @@ func (suite *InternalToFrontendTestSuite) TestRelationshipFollowRequested() {
func (suite *InternalToFrontendTestSuite) TestIntReqToAPI() {
requestingAccount := suite.testAccounts["local_account_2"]
adminReport, err := suite.typeconverter.InteractionReqToAPIInteractionReq(
- context.Background(),
+ suite.T().Context(),
suite.testInteractionRequests["admin_account_reply_turtle"],
requestingAccount,
)
@@ -4020,7 +4020,7 @@ func (suite *InternalToFrontendTestSuite) TestIntReqToAPI() {
func (suite *InternalToFrontendTestSuite) TestConversationToAPISelfConvo() {
var (
- ctx = context.Background()
+ ctx = suite.T().Context()
requester = suite.testAccounts["local_account_1"]
lastStatus = suite.testStatuses["local_account_1_status_1"]
filters []*gtsmodel.Filter = nil
@@ -4195,7 +4195,7 @@ func (suite *InternalToFrontendTestSuite) TestConversationToAPISelfConvo() {
func (suite *InternalToFrontendTestSuite) TestConversationToAPI() {
var (
- ctx = context.Background()
+ ctx = suite.T().Context()
requester = suite.testAccounts["local_account_1"]
lastStatus = suite.testStatuses["local_account_1_status_1"]
filters []*gtsmodel.Filter = nil
@@ -4379,7 +4379,7 @@ func (suite *InternalToFrontendTestSuite) TestConversationToAPI() {
}
func (suite *InternalToFrontendTestSuite) TestStatusToAPIEdits() {
- ctx, cncl := context.WithCancel(context.Background())
+ ctx, cncl := context.WithCancel(suite.T().Context())
defer cncl()
statusID := suite.testStatuses["local_account_1_status_9"].ID
diff --git a/internal/typeutils/internaltorss_test.go b/internal/typeutils/internaltorss_test.go
index 27d22cf81..89c88be27 100644
--- a/internal/typeutils/internaltorss_test.go
+++ b/internal/typeutils/internaltorss_test.go
@@ -18,7 +18,6 @@
package typeutils_test
import (
- "context"
"encoding/xml"
"testing"
@@ -34,7 +33,7 @@ type InternalToRSSTestSuite struct {
func (suite *InternalToRSSTestSuite) TestStatusToRSSItem1() {
s := suite.testStatuses["local_account_1_status_1"]
- item, err := suite.typeconverter.StatusToRSSItem(context.Background(), s)
+ item, err := suite.typeconverter.StatusToRSSItem(suite.T().Context(), s)
suite.NoError(err)
suite.Equal("introduction post", item.Title)
@@ -59,7 +58,7 @@ func (suite *InternalToRSSTestSuite) TestStatusToRSSItem1() {
func (suite *InternalToRSSTestSuite) TestStatusToRSSItem2() {
s := suite.testStatuses["admin_account_status_1"]
- item, err := suite.typeconverter.StatusToRSSItem(context.Background(), s)
+ item, err := suite.typeconverter.StatusToRSSItem(suite.T().Context(), s)
suite.NoError(err)
suite.Equal("hello world! #welcome ! first post on the instance :rainbow: !", item.Title)
@@ -97,7 +96,7 @@ func (suite *InternalToRSSTestSuite) TestStatusToRSSItem3() {
ActivityStreamsType: ap.ObjectNote,
Federated: util.Ptr(true),
}
- item, err := suite.typeconverter.StatusToRSSItem(context.Background(), s)
+ item, err := suite.typeconverter.StatusToRSSItem(suite.T().Context(), s)
suite.NoError(err)
data, err := xml.MarshalIndent(item, "", " ")
diff --git a/internal/typeutils/util_test.go b/internal/typeutils/util_test.go
index 4f0e70db0..42a86372f 100644
--- a/internal/typeutils/util_test.go
+++ b/internal/typeutils/util_test.go
@@ -18,7 +18,6 @@
package typeutils
import (
- "context"
"testing"
"code.superseriousbusiness.org/gotosocial/internal/config"
@@ -59,8 +58,7 @@ func TestContentToContentLanguage(t *testing.T) {
expectedLang string
}
- ctx, cncl := context.WithCancel(context.Background())
- defer cncl()
+ ctx := t.Context()
for i, testcase := range []testcase{
{
diff --git a/internal/typeutils/wrap_test.go b/internal/typeutils/wrap_test.go
index ae68d98c8..48a28e3b0 100644
--- a/internal/typeutils/wrap_test.go
+++ b/internal/typeutils/wrap_test.go
@@ -18,7 +18,6 @@
package typeutils_test
import (
- "context"
"encoding/json"
"testing"
@@ -34,7 +33,7 @@ type WrapTestSuite struct {
func (suite *WrapTestSuite) TestWrapNoteInCreateIRIOnly() {
testStatus := suite.testStatuses["local_account_1_status_1"]
- note, err := suite.typeconverter.StatusToAS(context.Background(), testStatus)
+ note, err := suite.typeconverter.StatusToAS(suite.T().Context(), testStatus)
suite.NoError(err)
create := typeutils.WrapStatusableInCreate(note, true)
@@ -62,7 +61,7 @@ func (suite *WrapTestSuite) TestWrapNoteInCreateIRIOnly() {
func (suite *WrapTestSuite) TestWrapNoteInCreate() {
testStatus := suite.testStatuses["local_account_1_status_1"]
- note, err := suite.typeconverter.StatusToAS(context.Background(), testStatus)
+ note, err := suite.typeconverter.StatusToAS(suite.T().Context(), testStatus)
suite.NoError(err)
create := typeutils.WrapStatusableInCreate(note, false)
@@ -154,7 +153,7 @@ func (suite *WrapTestSuite) TestWrapNoteInCreate() {
func (suite *WrapTestSuite) TestWrapAccountableInUpdate() {
testAccount := suite.testAccounts["local_account_1"]
- accountable, err := suite.typeconverter.AccountToAS(context.Background(), testAccount)
+ accountable, err := suite.typeconverter.AccountToAS(suite.T().Context(), testAccount)
if err != nil {
suite.FailNow(err.Error())
}