diff options
author | Till <2353100+S7evinK@users.noreply.github.com> | 2023-04-27 08:07:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 08:07:13 +0200 |
commit | 2475cf4b61747e76a524af6f71a4eb7e112812af (patch) | |
tree | c2446b71a0538fc340a7fb23e8a6c75a48b0a7dd /internal | |
parent | dd5e47a9a75f717381c27adebdee18aa80a1f256 (diff) |
Add some roomserver UTs (#3067)
Adds tests for `QueryRestrictedJoinAllowed`, `IsServerAllowed` and
`PerformRoomUpgrade`. Refactors the `QueryRoomVersionForRoom` method to
accept a string and return a `gmsl.RoomVersion` instead of req/resp
structs.
Adds some more caching for `GetStateEvent`
This should also fix #2912 by ignoring state events belonging to other
users.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/transactionrequest.go | 11 | ||||
-rw-r--r-- | internal/transactionrequest_test.go | 18 |
2 files changed, 12 insertions, 17 deletions
diff --git a/internal/transactionrequest.go b/internal/transactionrequest.go index bb16cefe..400dde8e 100644 --- a/internal/transactionrequest.go +++ b/internal/transactionrequest.go @@ -115,14 +115,13 @@ func (t *TxnReq) ProcessTransaction(ctx context.Context) (*fclient.RespSend, *ut if v, ok := roomVersions[roomID]; ok { return v } - verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID} - verRes := api.QueryRoomVersionForRoomResponse{} - if err := t.rsAPI.QueryRoomVersionForRoom(ctx, &verReq, &verRes); err != nil { - util.GetLogger(ctx).WithError(err).Debug("Transaction: Failed to query room version for room", verReq.RoomID) + roomVersion, err := t.rsAPI.QueryRoomVersionForRoom(ctx, roomID) + if err != nil { + util.GetLogger(ctx).WithError(err).Debug("Transaction: Failed to query room version for room", roomID) return "" } - roomVersions[roomID] = verRes.RoomVersion - return verRes.RoomVersion + roomVersions[roomID] = roomVersion + return roomVersion } for _, pdu := range t.PDUs { diff --git a/internal/transactionrequest_test.go b/internal/transactionrequest_test.go index 6b4c6129..21e371e8 100644 --- a/internal/transactionrequest_test.go +++ b/internal/transactionrequest_test.go @@ -72,14 +72,12 @@ type FakeRsAPI struct { func (r *FakeRsAPI) QueryRoomVersionForRoom( ctx context.Context, - req *rsAPI.QueryRoomVersionForRoomRequest, - res *rsAPI.QueryRoomVersionForRoomResponse, -) error { + roomID string, +) (gomatrixserverlib.RoomVersion, error) { if r.shouldFailQuery { - return fmt.Errorf("Failure") + return "", fmt.Errorf("Failure") } - res.RoomVersion = gomatrixserverlib.RoomVersionV10 - return nil + return gomatrixserverlib.RoomVersionV10, nil } func (r *FakeRsAPI) QueryServerBannedFromRoom( @@ -722,11 +720,9 @@ func (t *testRoomserverAPI) QueryServerJoinedToRoom( // Asks for the room version for a given room. func (t *testRoomserverAPI) QueryRoomVersionForRoom( ctx context.Context, - request *rsAPI.QueryRoomVersionForRoomRequest, - response *rsAPI.QueryRoomVersionForRoomResponse, -) error { - response.RoomVersion = testRoomVersion - return nil + roomID string, +) (gomatrixserverlib.RoomVersion, error) { + return testRoomVersion, nil } func (t *testRoomserverAPI) QueryServerBannedFromRoom( |