mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-11 02:38:06 -06:00
[chore] Test fixes (#788)
* use 'test' value for testrig storage backend * update test dependency * add WaitFor func in testrig * use WaitFor function instead of time.Sleep * tidy up tests * make SentMessages a sync.map * go fmt
This commit is contained in:
parent
bee8458a2d
commit
0245c606d7
30 changed files with 501 additions and 222 deletions
|
|
@ -27,6 +27,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/api/client/admin"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
)
|
||||
|
||||
type MediaCleanupTestSuite struct {
|
||||
|
|
@ -47,15 +48,15 @@ func (suite *MediaCleanupTestSuite) TestMediaCleanup() {
|
|||
// we should have OK because our request was valid
|
||||
suite.Equal(http.StatusOK, recorder.Code)
|
||||
|
||||
// Wait for async task to finish
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// Get media we prunes
|
||||
prunedAttachment, err := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID)
|
||||
suite.NoError(err)
|
||||
|
||||
// the media should no longer be cached
|
||||
suite.False(*prunedAttachment.Cached)
|
||||
// the attachment should be updated in the database
|
||||
if !testrig.WaitFor(func() bool {
|
||||
if prunedAttachment, _ := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID); prunedAttachment != nil {
|
||||
return !*prunedAttachment.Cached
|
||||
}
|
||||
return false
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for attachment to be pruned")
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *MediaCleanupTestSuite) TestMediaCleanupNoArg() {
|
||||
|
|
@ -73,15 +74,14 @@ func (suite *MediaCleanupTestSuite) TestMediaCleanupNoArg() {
|
|||
// we should have OK because our request was valid
|
||||
suite.Equal(http.StatusOK, recorder.Code)
|
||||
|
||||
// Wait for async task to finish
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// Get media we prunes
|
||||
prunedAttachment, err := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID)
|
||||
suite.NoError(err)
|
||||
|
||||
// the media should no longer be cached
|
||||
suite.False(*prunedAttachment.Cached)
|
||||
if !testrig.WaitFor(func() bool {
|
||||
if prunedAttachment, _ := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID); prunedAttachment != nil {
|
||||
return !*prunedAttachment.Cached
|
||||
}
|
||||
return false
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for attachment to be pruned")
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *MediaCleanupTestSuite) TestMediaCleanupNotOldEnough() {
|
||||
|
|
@ -101,7 +101,7 @@ func (suite *MediaCleanupTestSuite) TestMediaCleanupNotOldEnough() {
|
|||
// Wait for async task to finish
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// Get media we prunes
|
||||
// Get media we pruned
|
||||
prunedAttachment, err := suite.db.GetAttachmentByID(context.Background(), testAttachment.ID)
|
||||
suite.NoError(err)
|
||||
|
||||
|
|
|
|||
|
|
@ -444,14 +444,15 @@ func (suite *InboxPostTestSuite) TestPostDelete() {
|
|||
suite.Empty(b)
|
||||
suite.Equal(http.StatusOK, result.StatusCode)
|
||||
|
||||
// sleep for a sec so side effects can process in the background
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
// local account 2 blocked foss_satan, that block should be gone now
|
||||
testBlock := suite.testBlocks["local_account_2_block_remote_account_1"]
|
||||
dbBlock := >smodel.Block{}
|
||||
err = suite.db.GetByID(ctx, testBlock.ID, dbBlock)
|
||||
suite.ErrorIs(err, db.ErrNoEntries)
|
||||
if !testrig.WaitFor(func() bool {
|
||||
// local account 2 blocked foss_satan, that block should be gone now
|
||||
testBlock := suite.testBlocks["local_account_2_block_remote_account_1"]
|
||||
dbBlock := >smodel.Block{}
|
||||
err = suite.db.GetByID(ctx, testBlock.ID, dbBlock)
|
||||
return suite.ErrorIs(err, db.ErrNoEntries)
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for block to be removed")
|
||||
}
|
||||
|
||||
// no statuses from foss satan should be left in the database
|
||||
dbStatuses, err := suite.db.GetAccountStatuses(ctx, deletedAccount.ID, 0, false, false, "", "", false, false, false)
|
||||
|
|
|
|||
|
|
@ -46,15 +46,6 @@ func (suite *OutboxGetTestSuite) TestGetOutbox() {
|
|||
signedRequest := derefRequests["foss_satan_dereference_zork_outbox"]
|
||||
targetAccount := suite.testAccounts["local_account_1"]
|
||||
|
||||
clientWorker := concurrency.NewWorkerPool[messages.FromClientAPI](-1, -1)
|
||||
fedWorker := concurrency.NewWorkerPool[messages.FromFederator](-1, -1)
|
||||
|
||||
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil, "../../../../testrig/media"), suite.db, fedWorker)
|
||||
federator := testrig.NewTestFederator(suite.db, tc, suite.storage, suite.mediaManager, fedWorker)
|
||||
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
|
||||
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender, suite.mediaManager, clientWorker, fedWorker)
|
||||
userModule := user.New(processor).(*user.Module)
|
||||
|
||||
// setup request
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := testrig.CreateGinTestContext(recorder, nil)
|
||||
|
|
@ -76,7 +67,7 @@ func (suite *OutboxGetTestSuite) TestGetOutbox() {
|
|||
}
|
||||
|
||||
// trigger the function being tested
|
||||
userModule.OutboxGETHandler(ctx)
|
||||
suite.userModule.OutboxGETHandler(ctx)
|
||||
|
||||
// check response
|
||||
suite.EqualValues(http.StatusOK, recorder.Code)
|
||||
|
|
|
|||
|
|
@ -49,15 +49,6 @@ func (suite *RepliesGetTestSuite) TestGetReplies() {
|
|||
targetAccount := suite.testAccounts["local_account_1"]
|
||||
targetStatus := suite.testStatuses["local_account_1_status_1"]
|
||||
|
||||
clientWorker := concurrency.NewWorkerPool[messages.FromClientAPI](-1, -1)
|
||||
fedWorker := concurrency.NewWorkerPool[messages.FromFederator](-1, -1)
|
||||
|
||||
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil, "../../../../testrig/media"), suite.db, fedWorker)
|
||||
federator := testrig.NewTestFederator(suite.db, tc, suite.storage, suite.mediaManager, fedWorker)
|
||||
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
|
||||
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender, suite.mediaManager, clientWorker, fedWorker)
|
||||
userModule := user.New(processor).(*user.Module)
|
||||
|
||||
// setup request
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := testrig.CreateGinTestContext(recorder, nil)
|
||||
|
|
@ -83,7 +74,7 @@ func (suite *RepliesGetTestSuite) TestGetReplies() {
|
|||
}
|
||||
|
||||
// trigger the function being tested
|
||||
userModule.StatusRepliesGETHandler(ctx)
|
||||
suite.userModule.StatusRepliesGETHandler(ctx)
|
||||
|
||||
// check response
|
||||
suite.EqualValues(http.StatusOK, recorder.Code)
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ import (
|
|||
"github.com/superseriousbusiness/activity/streams"
|
||||
"github.com/superseriousbusiness/activity/streams/vocab"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/user"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/concurrency"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
)
|
||||
|
||||
|
|
@ -48,15 +46,6 @@ func (suite *StatusGetTestSuite) TestGetStatus() {
|
|||
targetAccount := suite.testAccounts["local_account_1"]
|
||||
targetStatus := suite.testStatuses["local_account_1_status_1"]
|
||||
|
||||
clientWorker := concurrency.NewWorkerPool[messages.FromClientAPI](-1, -1)
|
||||
fedWorker := concurrency.NewWorkerPool[messages.FromFederator](-1, -1)
|
||||
|
||||
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil, "../../../../testrig/media"), suite.db, fedWorker)
|
||||
federator := testrig.NewTestFederator(suite.db, tc, suite.storage, suite.mediaManager, fedWorker)
|
||||
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
|
||||
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender, suite.mediaManager, clientWorker, fedWorker)
|
||||
userModule := user.New(processor).(*user.Module)
|
||||
|
||||
// setup request
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := testrig.CreateGinTestContext(recorder, nil)
|
||||
|
|
@ -82,7 +71,7 @@ func (suite *StatusGetTestSuite) TestGetStatus() {
|
|||
}
|
||||
|
||||
// trigger the function being tested
|
||||
userModule.StatusGETHandler(ctx)
|
||||
suite.userModule.StatusGETHandler(ctx)
|
||||
|
||||
// check response
|
||||
suite.EqualValues(http.StatusOK, recorder.Code)
|
||||
|
|
@ -116,15 +105,6 @@ func (suite *StatusGetTestSuite) TestGetStatusLowercase() {
|
|||
targetAccount := suite.testAccounts["local_account_1"]
|
||||
targetStatus := suite.testStatuses["local_account_1_status_1"]
|
||||
|
||||
clientWorker := concurrency.NewWorkerPool[messages.FromClientAPI](-1, -1)
|
||||
fedWorker := concurrency.NewWorkerPool[messages.FromFederator](-1, -1)
|
||||
|
||||
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil, "../../../../testrig/media"), suite.db, fedWorker)
|
||||
federator := testrig.NewTestFederator(suite.db, tc, suite.storage, suite.mediaManager, fedWorker)
|
||||
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
|
||||
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender, suite.mediaManager, clientWorker, fedWorker)
|
||||
userModule := user.New(processor).(*user.Module)
|
||||
|
||||
// setup request
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := testrig.CreateGinTestContext(recorder, nil)
|
||||
|
|
@ -150,7 +130,7 @@ func (suite *StatusGetTestSuite) TestGetStatusLowercase() {
|
|||
}
|
||||
|
||||
// trigger the function being tested
|
||||
userModule.StatusGETHandler(ctx)
|
||||
suite.userModule.StatusGETHandler(ctx)
|
||||
|
||||
// check response
|
||||
suite.EqualValues(http.StatusOK, recorder.Code)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import (
|
|||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
|
@ -33,8 +32,6 @@ import (
|
|||
"github.com/superseriousbusiness/activity/streams/vocab"
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/user"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/concurrency"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
)
|
||||
|
|
@ -49,15 +46,6 @@ func (suite *UserGetTestSuite) TestGetUser() {
|
|||
signedRequest := derefRequests["foss_satan_dereference_zork"]
|
||||
targetAccount := suite.testAccounts["local_account_1"]
|
||||
|
||||
clientWorker := concurrency.NewWorkerPool[messages.FromClientAPI](-1, -1)
|
||||
fedWorker := concurrency.NewWorkerPool[messages.FromFederator](-1, -1)
|
||||
|
||||
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil, "../../../../testrig/media"), suite.db, fedWorker)
|
||||
federator := testrig.NewTestFederator(suite.db, tc, suite.storage, suite.mediaManager, fedWorker)
|
||||
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
|
||||
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender, suite.mediaManager, clientWorker, fedWorker)
|
||||
userModule := user.New(processor).(*user.Module)
|
||||
|
||||
// setup request
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := testrig.CreateGinTestContext(recorder, nil)
|
||||
|
|
@ -79,7 +67,7 @@ func (suite *UserGetTestSuite) TestGetUser() {
|
|||
}
|
||||
|
||||
// trigger the function being tested
|
||||
userModule.UsersGETHandler(ctx)
|
||||
suite.userModule.UsersGETHandler(ctx)
|
||||
|
||||
// check response
|
||||
suite.EqualValues(http.StatusOK, recorder.Code)
|
||||
|
|
@ -110,6 +98,12 @@ func (suite *UserGetTestSuite) TestGetUser() {
|
|||
// TestGetUserPublicKeyDeleted checks whether the public key of a deleted account can still be dereferenced.
|
||||
// This is needed by remote instances for authenticating delete requests and stuff like that.
|
||||
func (suite *UserGetTestSuite) TestGetUserPublicKeyDeleted() {
|
||||
if err := suite.processor.Start(); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
defer suite.processor.Stop()
|
||||
|
||||
userModule := user.New(suite.processor).(*user.Module)
|
||||
targetAccount := suite.testAccounts["local_account_1"]
|
||||
|
||||
// first delete the account, as though zork had deleted himself
|
||||
|
|
@ -123,22 +117,18 @@ func (suite *UserGetTestSuite) TestGetUserPublicKeyDeleted() {
|
|||
DeleteOriginID: targetAccount.ID,
|
||||
})
|
||||
|
||||
// now wait just a sec for it to go through....
|
||||
time.Sleep(1 * time.Second)
|
||||
// wait for the account delete to be processed
|
||||
if !testrig.WaitFor(func() bool {
|
||||
a, _ := suite.db.GetAccountByID(context.Background(), targetAccount.ID)
|
||||
return !a.SuspendedAt.IsZero()
|
||||
}) {
|
||||
suite.FailNow("delete of account timed out")
|
||||
}
|
||||
|
||||
// the dereference we're gonna use
|
||||
derefRequests := testrig.NewTestDereferenceRequests(suite.testAccounts)
|
||||
signedRequest := derefRequests["foss_satan_dereference_zork_public_key"]
|
||||
|
||||
clientWorker := concurrency.NewWorkerPool[messages.FromClientAPI](-1, -1)
|
||||
fedWorker := concurrency.NewWorkerPool[messages.FromFederator](-1, -1)
|
||||
|
||||
tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil, "../../../../testrig/media"), suite.db, fedWorker)
|
||||
federator := testrig.NewTestFederator(suite.db, tc, suite.storage, suite.mediaManager, fedWorker)
|
||||
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
|
||||
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender, suite.mediaManager, clientWorker, fedWorker)
|
||||
userModule := user.New(processor).(*user.Module)
|
||||
|
||||
// setup request
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := testrig.CreateGinTestContext(recorder, nil)
|
||||
|
|
|
|||
|
|
@ -20,13 +20,12 @@ package dereferencing_test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/media"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
)
|
||||
|
||||
type AttachmentTestSuite struct {
|
||||
|
|
@ -128,12 +127,11 @@ func (suite *AttachmentTestSuite) TestDereferenceAttachmentAsync() {
|
|||
suite.NoError(err)
|
||||
attachmentID := processingMedia.AttachmentID()
|
||||
|
||||
// wait for the media to finish processing
|
||||
for finished := processingMedia.Finished(); !finished; finished = processingMedia.Finished() {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
fmt.Printf("\n\nnot finished yet...\n\n")
|
||||
if !testrig.WaitFor(func() bool {
|
||||
return processingMedia.Finished()
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for media to be processed")
|
||||
}
|
||||
fmt.Printf("\n\nfinished!\n\n")
|
||||
|
||||
// now get the attachment from the database
|
||||
attachment, err := suite.db.GetAttachmentByID(ctx, attachmentID)
|
||||
|
|
|
|||
|
|
@ -115,10 +115,22 @@ func (suite *FederatingActorTestSuite) TestSendRemoteFollower() {
|
|||
suite.NotNil(activity)
|
||||
|
||||
// because we added 1 remote follower for zork, there should be a url in sentMessage
|
||||
suite.Len(httpClient.SentMessages, 1)
|
||||
msg, ok := httpClient.SentMessages[testRemoteAccount.InboxURI]
|
||||
suite.True(ok)
|
||||
suite.Equal(`{"@context":"https://www.w3.org/ns/activitystreams","actor":"http://localhost:8080/users/the_mighty_zork","id":"http://localhost:8080/whatever_some_create","object":{"attributedTo":"http://localhost:8080/users/the_mighty_zork","content":"boobies","id":"http://localhost:8080/users/the_mighty_zork/statuses/01G1TR6BADACCZWQMNF9X21TV5","published":"2022-06-02T12:22:21+02:00","tag":[],"to":"http://localhost:8080/users/the_mighty_zork/followers","type":"Note","url":"http://localhost:8080/@the_mighty_zork/statuses/01G1TR6BADACCZWQMNF9X21TV5"},"published":"2022-06-02T12:22:21+02:00","to":"http://localhost:8080/users/the_mighty_zork/followers","type":"Create"}`, string(msg))
|
||||
var sent [][]byte
|
||||
if !testrig.WaitFor(func() bool {
|
||||
sentI, ok := httpClient.SentMessages.Load(testRemoteAccount.InboxURI)
|
||||
if ok {
|
||||
sent, ok = sentI.([][]byte)
|
||||
if !ok {
|
||||
panic("SentMessages entry was not []byte")
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for message")
|
||||
}
|
||||
|
||||
suite.Equal(`{"@context":"https://www.w3.org/ns/activitystreams","actor":"http://localhost:8080/users/the_mighty_zork","id":"http://localhost:8080/whatever_some_create","object":{"attributedTo":"http://localhost:8080/users/the_mighty_zork","content":"boobies","id":"http://localhost:8080/users/the_mighty_zork/statuses/01G1TR6BADACCZWQMNF9X21TV5","published":"2022-06-02T12:22:21+02:00","tag":[],"to":"http://localhost:8080/users/the_mighty_zork/followers","type":"Note","url":"http://localhost:8080/@the_mighty_zork/statuses/01G1TR6BADACCZWQMNF9X21TV5"},"published":"2022-06-02T12:22:21+02:00","to":"http://localhost:8080/users/the_mighty_zork/followers","type":"Create"}`, string(sent[0]))
|
||||
}
|
||||
|
||||
func TestFederatingActorTestSuite(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"codeberg.org/gruf/go-store/kv"
|
||||
"codeberg.org/gruf/go-store/storage"
|
||||
|
|
@ -34,6 +33,7 @@ import (
|
|||
gtsmodel "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/media"
|
||||
gtsstorage "github.com/superseriousbusiness/gotosocial/internal/storage"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
)
|
||||
|
||||
type ManagerTestSuite struct {
|
||||
|
|
@ -360,11 +360,11 @@ func (suite *ManagerTestSuite) TestSimpleJpegProcessAsync() {
|
|||
attachmentID := processingMedia.AttachmentID()
|
||||
|
||||
// wait for the media to finish processing
|
||||
for finished := processingMedia.Finished(); !finished; finished = processingMedia.Finished() {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
fmt.Printf("\n\nnot finished yet...\n\n")
|
||||
if !testrig.WaitFor(func() bool {
|
||||
return processingMedia.Finished()
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for media to be processed")
|
||||
}
|
||||
fmt.Printf("\n\nfinished!\n\n")
|
||||
|
||||
// fetch the attachment from the database
|
||||
attachment, err := suite.db.GetAttachmentByID(ctx, attachmentID)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/superseriousbusiness/activity/pub"
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
)
|
||||
|
||||
type AccountTestSuite struct {
|
||||
|
|
@ -59,23 +60,30 @@ func (suite *AccountTestSuite) TestAccountDeleteLocal() {
|
|||
suite.NoError(errWithCode)
|
||||
|
||||
// the delete should be federated outwards to the following account's inbox
|
||||
var sent []byte
|
||||
var ok bool
|
||||
for !ok {
|
||||
sent, ok = suite.httpClient.SentMessages[followingAccount.InboxURI]
|
||||
}
|
||||
|
||||
suite.True(ok)
|
||||
delete := &struct {
|
||||
var sent [][]byte
|
||||
delete := new(struct {
|
||||
Actor string `json:"actor"`
|
||||
ID string `json:"id"`
|
||||
Object string `json:"object"`
|
||||
To string `json:"to"`
|
||||
CC string `json:"cc"`
|
||||
Type string `json:"type"`
|
||||
}{}
|
||||
err = json.Unmarshal(sent, delete)
|
||||
suite.NoError(err)
|
||||
})
|
||||
|
||||
if !testrig.WaitFor(func() bool {
|
||||
sentI, ok := suite.httpClient.SentMessages.Load(followingAccount.InboxURI)
|
||||
if ok {
|
||||
sent, ok = sentI.([][]byte)
|
||||
if !ok {
|
||||
panic("SentMessages entry was not [][]byte")
|
||||
}
|
||||
err = json.Unmarshal(sent[0], delete)
|
||||
return err == nil
|
||||
}
|
||||
return false
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for message")
|
||||
}
|
||||
|
||||
suite.Equal(deletingAccount.URI, delete.Actor)
|
||||
suite.Equal(deletingAccount.URI, delete.Object)
|
||||
|
|
@ -83,13 +91,12 @@ func (suite *AccountTestSuite) TestAccountDeleteLocal() {
|
|||
suite.Equal(pub.PublicActivityPubIRI, delete.CC)
|
||||
suite.Equal("Delete", delete.Type)
|
||||
|
||||
// wait for the delete to go through
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// the deleted account should be deleted
|
||||
dbAccount, err := suite.db.GetAccountByID(ctx, deletingAccount.ID)
|
||||
suite.NoError(err)
|
||||
suite.WithinDuration(dbAccount.SuspendedAt, time.Now(), 30*time.Second)
|
||||
if !testrig.WaitFor(func() bool {
|
||||
dbAccount, _ := suite.db.GetAccountByID(ctx, deletingAccount.ID)
|
||||
return suite.WithinDuration(dbAccount.SuspendedAt, time.Now(), 30*time.Second)
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for account to be deleted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountTestSuite(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/stretchr/testify/suite"
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
)
|
||||
|
||||
type FollowRequestTestSuite struct {
|
||||
|
|
@ -54,11 +55,22 @@ func (suite *FollowRequestTestSuite) TestFollowRequestAccept() {
|
|||
relationship, errWithCode := suite.processor.FollowRequestAccept(context.Background(), suite.testAutheds["local_account_1"], requestingAccount.ID)
|
||||
suite.NoError(errWithCode)
|
||||
suite.EqualValues(&apimodel.Relationship{ID: "01FHMQX3GAABWSM0S2VZEC2SWC", Following: false, ShowingReblogs: false, Notifying: false, FollowedBy: true, Blocking: false, BlockedBy: false, Muting: false, MutingNotifications: false, Requested: false, DomainBlocking: false, Endorsed: false, Note: ""}, relationship)
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// accept should be sent to some_user
|
||||
sent, ok := suite.httpClient.SentMessages[requestingAccount.InboxURI]
|
||||
suite.True(ok)
|
||||
var sent [][]byte
|
||||
if !testrig.WaitFor(func() bool {
|
||||
sentI, ok := suite.httpClient.SentMessages.Load(requestingAccount.InboxURI)
|
||||
if ok {
|
||||
sent, ok = sentI.([][]byte)
|
||||
if !ok {
|
||||
panic("SentMessages entry was not []byte")
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for message")
|
||||
}
|
||||
|
||||
accept := &struct {
|
||||
Actor string `json:"actor"`
|
||||
|
|
@ -73,7 +85,7 @@ func (suite *FollowRequestTestSuite) TestFollowRequestAccept() {
|
|||
To string `json:"to"`
|
||||
Type string `json:"type"`
|
||||
}{}
|
||||
err = json.Unmarshal(sent, accept)
|
||||
err = json.Unmarshal(sent[0], accept)
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Equal(targetAccount.URI, accept.Actor)
|
||||
|
|
@ -106,11 +118,22 @@ func (suite *FollowRequestTestSuite) TestFollowRequestReject() {
|
|||
relationship, errWithCode := suite.processor.FollowRequestReject(context.Background(), suite.testAutheds["local_account_1"], requestingAccount.ID)
|
||||
suite.NoError(errWithCode)
|
||||
suite.EqualValues(&apimodel.Relationship{ID: "01FHMQX3GAABWSM0S2VZEC2SWC", Following: false, ShowingReblogs: false, Notifying: false, FollowedBy: false, Blocking: false, BlockedBy: false, Muting: false, MutingNotifications: false, Requested: false, DomainBlocking: false, Endorsed: false, Note: ""}, relationship)
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// reject should be sent to some_user
|
||||
sent, ok := suite.httpClient.SentMessages[requestingAccount.InboxURI]
|
||||
suite.True(ok)
|
||||
var sent [][]byte
|
||||
if !testrig.WaitFor(func() bool {
|
||||
sentI, ok := suite.httpClient.SentMessages.Load(requestingAccount.InboxURI)
|
||||
if ok {
|
||||
sent, ok = sentI.([][]byte)
|
||||
if !ok {
|
||||
panic("SentMessages entry was not []byte")
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for message")
|
||||
}
|
||||
|
||||
reject := &struct {
|
||||
Actor string `json:"actor"`
|
||||
|
|
@ -125,7 +148,7 @@ func (suite *FollowRequestTestSuite) TestFollowRequestReject() {
|
|||
To string `json:"to"`
|
||||
Type string `json:"type"`
|
||||
}{}
|
||||
err = json.Unmarshal(sent, reject)
|
||||
err = json.Unmarshal(sent[0], reject)
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Equal(targetAccount.URI, reject.Actor)
|
||||
|
|
|
|||
|
|
@ -482,6 +482,47 @@ func (suite *FromFederatorTestSuite) TestProcessFollowRequestUnlocked() {
|
|||
})
|
||||
suite.NoError(err)
|
||||
|
||||
// an accept message should be sent to satan's inbox
|
||||
var sent [][]byte
|
||||
if !testrig.WaitFor(func() bool {
|
||||
sentI, ok := suite.httpClient.SentMessages.Load(originAccount.InboxURI)
|
||||
if ok {
|
||||
sent, ok = sentI.([][]byte)
|
||||
if !ok {
|
||||
panic("SentMessages entry was not []byte")
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for message")
|
||||
}
|
||||
|
||||
accept := &struct {
|
||||
Actor string `json:"actor"`
|
||||
ID string `json:"id"`
|
||||
Object struct {
|
||||
Actor string `json:"actor"`
|
||||
ID string `json:"id"`
|
||||
Object string `json:"object"`
|
||||
To string `json:"to"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
To string `json:"to"`
|
||||
Type string `json:"type"`
|
||||
}{}
|
||||
err = json.Unmarshal(sent[0], accept)
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Equal(targetAccount.URI, accept.Actor)
|
||||
suite.Equal(originAccount.URI, accept.Object.Actor)
|
||||
suite.Equal(satanFollowRequestTurtle.URI, accept.Object.ID)
|
||||
suite.Equal(targetAccount.URI, accept.Object.Object)
|
||||
suite.Equal(targetAccount.URI, accept.Object.To)
|
||||
suite.Equal("Follow", accept.Object.Type)
|
||||
suite.Equal(originAccount.URI, accept.To)
|
||||
suite.Equal("Accept", accept.Type)
|
||||
|
||||
// a notification should be streamed
|
||||
var msg *stream.Message
|
||||
select {
|
||||
|
|
@ -498,34 +539,6 @@ func (suite *FromFederatorTestSuite) TestProcessFollowRequestUnlocked() {
|
|||
suite.NoError(err)
|
||||
suite.Equal("follow", notif.Type)
|
||||
suite.Equal(originAccount.ID, notif.Account.ID)
|
||||
|
||||
// an accept message should be sent to satan's inbox
|
||||
suite.Len(suite.httpClient.SentMessages, 1)
|
||||
acceptBytes := suite.httpClient.SentMessages[originAccount.InboxURI]
|
||||
accept := &struct {
|
||||
Actor string `json:"actor"`
|
||||
ID string `json:"id"`
|
||||
Object struct {
|
||||
Actor string `json:"actor"`
|
||||
ID string `json:"id"`
|
||||
Object string `json:"object"`
|
||||
To string `json:"to"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
To string `json:"to"`
|
||||
Type string `json:"type"`
|
||||
}{}
|
||||
err = json.Unmarshal(acceptBytes, accept)
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Equal(targetAccount.URI, accept.Actor)
|
||||
suite.Equal(originAccount.URI, accept.Object.Actor)
|
||||
suite.Equal(satanFollowRequestTurtle.URI, accept.Object.ID)
|
||||
suite.Equal(targetAccount.URI, accept.Object.Object)
|
||||
suite.Equal(targetAccount.URI, accept.Object.To)
|
||||
suite.Equal("Follow", accept.Object.Type)
|
||||
suite.Equal(originAccount.URI, accept.To)
|
||||
suite.Equal("Accept", accept.Type)
|
||||
}
|
||||
|
||||
// TestCreateStatusFromIRI checks if a forwarded status can be dereferenced by the processor.
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ import (
|
|||
"io"
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/media"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
)
|
||||
|
|
@ -99,10 +99,16 @@ func (suite *GetFileTestSuite) TestGetRemoteFileUncached() {
|
|||
suite.Equal(suite.testRemoteAttachments[testAttachment.RemoteURL].Data, b)
|
||||
suite.Equal(suite.testRemoteAttachments[testAttachment.RemoteURL].ContentType, content.ContentType)
|
||||
suite.EqualValues(len(suite.testRemoteAttachments[testAttachment.RemoteURL].Data), content.ContentLength)
|
||||
time.Sleep(2 * time.Second) // wait a few seconds for the media manager to finish doing stuff
|
||||
|
||||
// the attachment should be updated in the database
|
||||
dbAttachment, err := suite.db.GetAttachmentByID(ctx, testAttachment.ID)
|
||||
var dbAttachment *gtsmodel.MediaAttachment
|
||||
if !testrig.WaitFor(func() bool {
|
||||
dbAttachment, err = suite.db.GetAttachmentByID(ctx, testAttachment.ID)
|
||||
return dbAttachment != nil
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for updated attachment")
|
||||
}
|
||||
|
||||
suite.NoError(err)
|
||||
suite.True(*dbAttachment.Cached)
|
||||
|
||||
|
|
@ -149,12 +155,13 @@ func (suite *GetFileTestSuite) TestGetRemoteFileUncachedInterrupted() {
|
|||
suite.NoError(closer.Close())
|
||||
}
|
||||
|
||||
time.Sleep(2 * time.Second) // wait a few seconds for the media manager to finish doing stuff
|
||||
|
||||
// the attachment should still be updated in the database even though the caller hung up
|
||||
dbAttachment, err := suite.db.GetAttachmentByID(ctx, testAttachment.ID)
|
||||
suite.NoError(err)
|
||||
suite.True(*dbAttachment.Cached)
|
||||
if !testrig.WaitFor(func() bool {
|
||||
dbAttachment, _ := suite.db.GetAttachmentByID(ctx, testAttachment.ID)
|
||||
return *dbAttachment.Cached
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for attachment to be updated")
|
||||
}
|
||||
|
||||
// the file should be back in storage at the same path as before
|
||||
refreshedBytes, err := suite.storage.Get(ctx, testAttachment.File.Path)
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ type TransTestSuite struct {
|
|||
|
||||
func (suite *TransTestSuite) SetupTest() {
|
||||
testrig.InitTestConfig()
|
||||
testrig.InitTestLog()
|
||||
testrig.InitTestLog()
|
||||
|
||||
suite.testAccounts = testrig.NewTestAccounts()
|
||||
suite.testAccounts = testrig.NewTestAccounts()
|
||||
|
||||
suite.db = testrig.NewTestDB()
|
||||
testrig.StandardDBSetup(suite.db, nil)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue