diff options
author | 2022-08-31 17:31:21 +0200 | |
---|---|---|
committer | 2022-08-31 17:31:21 +0200 | |
commit | 0245c606d77c8b99833ccc2c0923a298fb482236 (patch) | |
tree | 16311e89656894f09cfaeb8b0f21b5ac9e4de502 /internal/processing/fromfederator_test.go | |
parent | [feature] add rate limit middleware (#741) (diff) | |
download | gotosocial-0245c606d77c8b99833ccc2c0923a298fb482236.tar.xz |
[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
Diffstat (limited to 'internal/processing/fromfederator_test.go')
-rw-r--r-- | internal/processing/fromfederator_test.go | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/internal/processing/fromfederator_test.go b/internal/processing/fromfederator_test.go index 86b63dade..8489303e8 100644 --- a/internal/processing/fromfederator_test.go +++ b/internal/processing/fromfederator_test.go @@ -482,26 +482,22 @@ func (suite *FromFederatorTestSuite) TestProcessFollowRequestUnlocked() { }) suite.NoError(err) - // a notification should be streamed - var msg *stream.Message - select { - case msg = <-wssStream.Messages: - // fine - case <-time.After(5 * time.Second): - suite.FailNow("no message from wssStream") + // 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") } - suite.Equal(stream.EventTypeNotification, msg.Event) - suite.NotEmpty(msg.Payload) - suite.EqualValues([]string{stream.TimelineHome}, msg.Stream) - notif := &model.Notification{} - err = json.Unmarshal([]byte(msg.Payload), notif) - 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"` @@ -515,7 +511,7 @@ func (suite *FromFederatorTestSuite) TestProcessFollowRequestUnlocked() { To string `json:"to"` Type string `json:"type"` }{} - err = json.Unmarshal(acceptBytes, accept) + err = json.Unmarshal(sent[0], accept) suite.NoError(err) suite.Equal(targetAccount.URI, accept.Actor) @@ -526,6 +522,23 @@ func (suite *FromFederatorTestSuite) TestProcessFollowRequestUnlocked() { 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 { + case msg = <-wssStream.Messages: + // fine + case <-time.After(5 * time.Second): + suite.FailNow("no message from wssStream") + } + suite.Equal(stream.EventTypeNotification, msg.Event) + suite.NotEmpty(msg.Payload) + suite.EqualValues([]string{stream.TimelineHome}, msg.Stream) + notif := &model.Notification{} + err = json.Unmarshal([]byte(msg.Payload), notif) + suite.NoError(err) + suite.Equal("follow", notif.Type) + suite.Equal(originAccount.ID, notif.Account.ID) } // TestCreateStatusFromIRI checks if a forwarded status can be dereferenced by the processor. |