From 35e24da8bb176241f7ffd2b0f140f507881b0ebc Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 9 Oct 2023 14:20:24 +0100 Subject: [PATCH 1/9] Add some Must functions to CSAPI --- client/client.go | 78 +++++++++++++++++++++------- client/sync.go | 21 ++++++-- tests/csapi/keychanges_test.go | 4 +- tests/csapi/to_device_test.go | 4 +- tests/csapi/upload_keys_test.go | 4 +- tests/federation_redaction_test.go | 4 +- tests/federation_upload_keys_test.go | 4 +- tests/restricted_rooms_test.go | 33 ++++-------- 8 files changed, 96 insertions(+), 56 deletions(-) diff --git a/client/client.go b/client/client.go index 307ae8d2..923f929c 100644 --- a/client/client.go +++ b/client/client.go @@ -98,8 +98,21 @@ func (c *CSAPI) CreateRoom(t TestLike, creationContent interface{}) string { return GetJSONFieldStr(t, body, "room_id") } -// JoinRoom joins the room ID or alias given, else fails the test. Returns the room ID. -func (c *CSAPI) JoinRoom(t TestLike, roomIDOrAlias string, serverNames []string) string { +// MustJoinRoom joins the room ID or alias given, else fails the test. Returns the room ID. +func (c *CSAPI) MustJoinRoom(t TestLike, roomIDOrAlias string, serverNames []string) string { + t.Helper() + res := c.JoinRoom(t, roomIDOrAlias, serverNames) + // return the room ID if we joined with it + if roomIDOrAlias[0] == '!' { + return roomIDOrAlias + } + // otherwise we should be told the room ID if we joined via an alias + body := ParseJSON(t, res) + return GetJSONFieldStr(t, body, "room_id") +} + +// JoinRoom joins the room ID or alias given. Returns the raw http response +func (c *CSAPI) JoinRoom(t TestLike, roomIDOrAlias string, serverNames []string) *http.Response { t.Helper() // construct URL query parameters query := make(url.Values, len(serverNames)) @@ -107,17 +120,10 @@ func (c *CSAPI) JoinRoom(t TestLike, roomIDOrAlias string, serverNames []string) query.Add("server_name", serverName) } // join the room - res := c.MustDo( + return c.Do( t, "POST", []string{"_matrix", "client", "v3", "join", roomIDOrAlias}, WithQueries(query), WithJSONBody(t, map[string]interface{}{}), ) - // return the room ID if we joined with it - if roomIDOrAlias[0] == '!' { - return roomIDOrAlias - } - // otherwise we should be told the room ID if we joined via an alias - body := ParseJSON(t, res) - return GetJSONFieldStr(t, body, "room_id") } // LeaveRoom leaves the room ID, else fails the test. @@ -266,25 +272,38 @@ func (c *CSAPI) SendEventSynced(t TestLike, roomID string, e b.Event) string { return eventID } -// SendRedaction sends a redaction request. Will fail if the returned HTTP request code is not 200 -func (c *CSAPI) SendRedaction(t TestLike, roomID string, e b.Event, eventID string) string { +// SendRedaction sends a redaction request. Will fail if the returned HTTP request code is not 200. Returns the +// event ID of the redaction event. +func (c *CSAPI) MustSendRedaction(t TestLike, roomID string, e b.Event, eventID string) string { + res := c.SendRedaction(t, roomID, e, eventID) + mustRespondOK(t, res) + body := ParseJSON(t, res) + return GetJSONFieldStr(t, body, "event_id") +} + +// SendRedaction sends a redaction request. +func (c *CSAPI) SendRedaction(t TestLike, roomID string, e b.Event, eventID string) *http.Response { t.Helper() txnID := int(atomic.AddInt64(&c.txnID, 1)) paths := []string{"_matrix", "client", "v3", "rooms", roomID, "redact", eventID, strconv.Itoa(txnID)} - res := c.MustDo(t, "PUT", paths, WithJSONBody(t, e.Content)) - body := ParseJSON(t, res) - return GetJSONFieldStr(t, body, "event_id") + return c.Do(t, "PUT", paths, WithJSONBody(t, e.Content)) +} + +// MustSendTyping marks this user as typing until the timeout is reached. If isTyping is false, timeout is ignored. +func (c *CSAPI) MustSendTyping(t TestLike, roomID string, isTyping bool, timeoutMillis int) { + res := c.SendTyping(t, roomID, isTyping, timeoutMillis) + mustRespondOK(t, res) } // SendTyping marks this user as typing until the timeout is reached. If isTyping is false, timeout is ignored. -func (c *CSAPI) SendTyping(t TestLike, roomID string, isTyping bool, timeoutMillis int) { +func (c *CSAPI) SendTyping(t TestLike, roomID string, isTyping bool, timeoutMillis int) *http.Response { content := map[string]interface{}{ "typing": isTyping, } if isTyping { content["timeout"] = timeoutMillis } - c.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "typing", c.UserID}, WithJSONBody(t, content)) + return c.Do(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "typing", c.UserID}, WithJSONBody(t, content)) } // GetCapbabilities queries the server's capabilities @@ -311,7 +330,7 @@ func (c *CSAPI) GetDefaultRoomVersion(t TestLike) gomatrixserverlib.RoomVersion return gomatrixserverlib.RoomVersion(defaultVersion.Str) } -func (c *CSAPI) GenerateOneTimeKeys(t TestLike, otkCount uint) (deviceKeys map[string]interface{}, oneTimeKeys map[string]interface{}) { +func (c *CSAPI) MustGenerateOneTimeKeys(t TestLike, otkCount uint) (deviceKeys map[string]interface{}, oneTimeKeys map[string]interface{}) { t.Helper() account := olm.NewAccount() ed25519Key, curveKey := account.IdentityKeys() @@ -641,10 +660,20 @@ func SplitMxc(mxcUri string) (string, string) { // // The messages parameter is nested as follows: // user_id -> device_id -> content (map[string]interface{}) -func (c *CSAPI) SendToDeviceMessages(t TestLike, evType string, messages map[string]map[string]map[string]interface{}) { +func (c *CSAPI) MustSendToDeviceMessages(t TestLike, evType string, messages map[string]map[string]map[string]interface{}) { + t.Helper() + res := c.SendToDeviceMessages(t, evType, messages) + mustRespondOK(t, res) +} + +// SendToDeviceMessages sends to-device messages over /sendToDevice/. +// +// The messages parameter is nested as follows: +// user_id -> device_id -> content (map[string]interface{}) +func (c *CSAPI) SendToDeviceMessages(t TestLike, evType string, messages map[string]map[string]map[string]interface{}) (errRes *http.Response) { t.Helper() txnID := int(atomic.AddInt64(&c.txnID, 1)) - c.MustDo( + return c.Do( t, "PUT", []string{"_matrix", "client", "v3", "sendToDevice", evType, strconv.Itoa(txnID)}, @@ -656,3 +685,12 @@ func (c *CSAPI) SendToDeviceMessages(t TestLike, evType string, messages map[str ), ) } + +func mustRespondOK(t TestLike, res *http.Response) { + if res.StatusCode >= 200 && res.StatusCode < 300 { + return // 2xx + } + defer res.Body.Close() + body, _ := io.ReadAll(res.Body) + t.Fatalf("CSAPI.Must: %s %s returned non-2xx code: %s - body: %s", res.Request.Method, res.Request.URL.String(), res.Status, string(body)) +} diff --git a/client/sync.go b/client/sync.go index 461465f0..36a186ce 100644 --- a/client/sync.go +++ b/client/sync.go @@ -2,6 +2,7 @@ package client import ( "fmt" + "net/http" "net/url" "reflect" "sort" @@ -141,6 +142,18 @@ func (c *CSAPI) MustSyncUntil(t TestLike, syncReq SyncReq, checks ...SyncCheckOp // Fails the test if the /sync request does not return 200 OK. // Returns the top-level parsed /sync response JSON as well as the next_batch token from the response. func (c *CSAPI) MustSync(t TestLike, syncReq SyncReq) (gjson.Result, string) { + t.Helper() + jsonBody, res := c.Sync(t, syncReq) + mustRespondOK(t, res) + return jsonBody, jsonBody.Get("next_batch").Str +} + +// Perform a single /sync request with the given request options. To sync until something happens, +// see `MustSyncUntil`. +// +// Returns the HTTP response if the /sync request does not return 200 OK. +// Returns the top-level parsed /sync response JSON on 200 OK. +func (c *CSAPI) Sync(t TestLike, syncReq SyncReq) (gjson.Result, *http.Response) { t.Helper() query := url.Values{ "timeout": []string{"1000"}, @@ -161,11 +174,13 @@ func (c *CSAPI) MustSync(t TestLike, syncReq SyncReq) (gjson.Result, string) { if syncReq.SetPresence != "" { query["set_presence"] = []string{syncReq.SetPresence} } - res := c.MustDo(t, "GET", []string{"_matrix", "client", "v3", "sync"}, WithQueries(query)) + res := c.Do(t, "GET", []string{"_matrix", "client", "v3", "sync"}, WithQueries(query)) + if res.StatusCode < 200 || res.StatusCode >= 300 { + return gjson.Result{}, res + } body := ParseJSON(t, res) result := gjson.ParseBytes(body) - nextBatch := GetJSONFieldStr(t, body, "next_batch") - return result, nextBatch + return result, nil } // Check that the timeline for `roomID` has an event which passes the check function. diff --git a/tests/csapi/keychanges_test.go b/tests/csapi/keychanges_test.go index 0666c6c9..52efd3de 100644 --- a/tests/csapi/keychanges_test.go +++ b/tests/csapi/keychanges_test.go @@ -8,8 +8,8 @@ import ( "github.com/tidwall/gjson" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" ) @@ -97,7 +97,7 @@ func TestKeyChangesLocal(t *testing.T) { func mustUploadKeys(t *testing.T, user *client.CSAPI) { t.Helper() - deviceKeys, oneTimeKeys := user.GenerateOneTimeKeys(t, 5) + deviceKeys, oneTimeKeys := user.MustGenerateOneTimeKeys(t, 5) reqBody := client.WithJSONBody(t, map[string]interface{}{ "device_keys": deviceKeys, "one_time_keys": oneTimeKeys, diff --git a/tests/csapi/to_device_test.go b/tests/csapi/to_device_test.go index 57bc5833..edac4ac8 100644 --- a/tests/csapi/to_device_test.go +++ b/tests/csapi/to_device_test.go @@ -6,8 +6,8 @@ import ( "github.com/tidwall/gjson" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" ) // sytest: Can send a message directly to a device using PUT /sendToDevice @@ -28,7 +28,7 @@ func TestToDeviceMessages(t *testing.T) { "my_key": "my_value", } - alice.SendToDeviceMessages(t, "my.test.type", map[string]map[string]map[string]interface{}{ + alice.MustSendToDeviceMessages(t, "my.test.type", map[string]map[string]map[string]interface{}{ bob.UserID: { bob.DeviceID: content, }, diff --git a/tests/csapi/upload_keys_test.go b/tests/csapi/upload_keys_test.go index 4d0775a9..62821817 100644 --- a/tests/csapi/upload_keys_test.go +++ b/tests/csapi/upload_keys_test.go @@ -8,8 +8,8 @@ import ( "github.com/tidwall/gjson" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" "github.com/matrix-org/complement/runtime" @@ -22,7 +22,7 @@ func TestUploadKey(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - deviceKeys, oneTimeKeys := alice.GenerateOneTimeKeys(t, 1) + deviceKeys, oneTimeKeys := alice.MustGenerateOneTimeKeys(t, 1) t.Run("Parallel", func(t *testing.T) { // sytest: Can upload device keys diff --git a/tests/federation_redaction_test.go b/tests/federation_redaction_test.go index 00a86c87..2fb4a443 100644 --- a/tests/federation_redaction_test.go +++ b/tests/federation_redaction_test.go @@ -69,7 +69,7 @@ func TestFederationRedactSendsWithoutEvent(t *testing.T) { eventToRedact := eventID + ":" + fullServerName // the client sends a request to the local homeserver to send the redaction - res := alice.SendRedaction(t, serverRoom.RoomID, b.Event{ + redactionEventID := alice.MustSendRedaction(t, serverRoom.RoomID, b.Event{ Type: wantEventType, Content: map[string]interface{}{ "reason": "reasons...", @@ -88,5 +88,5 @@ func TestFederationRedactSendsWithoutEvent(t *testing.T) { } // check that the event id of the redaction sent by alice is the same as the redaction event in the room - must.Equal(t, lastEvent.EventID(), res, "incorrect event id") + must.Equal(t, lastEvent.EventID(), redactionEventID, "incorrect event id") } diff --git a/tests/federation_upload_keys_test.go b/tests/federation_upload_keys_test.go index f1cc422b..cdce69d6 100644 --- a/tests/federation_upload_keys_test.go +++ b/tests/federation_upload_keys_test.go @@ -8,8 +8,8 @@ import ( "github.com/tidwall/gjson" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" ) @@ -24,7 +24,7 @@ func TestFederationKeyUploadQuery(t *testing.T) { // Do an initial sync so that we can see the changes come down sync. _, nextBatchBeforeKeyUpload := bob.MustSync(t, client.SyncReq{}) - deviceKeys, oneTimeKeys := alice.GenerateOneTimeKeys(t, 1) + deviceKeys, oneTimeKeys := alice.MustGenerateOneTimeKeys(t, 1) // Upload keys reqBody := client.WithJSONBody(t, map[string]interface{}{ "device_keys": deviceKeys, diff --git a/tests/restricted_rooms_test.go b/tests/restricted_rooms_test.go index 64cc5b1b..0e0ab661 100644 --- a/tests/restricted_rooms_test.go +++ b/tests/restricted_rooms_test.go @@ -3,7 +3,6 @@ package tests import ( - "net/url" "testing" "github.com/tidwall/gjson" @@ -16,21 +15,6 @@ import ( "github.com/matrix-org/complement/runtime" ) -func failJoinRoom(t *testing.T, c *client.CSAPI, roomIDOrAlias string, serverName string) { - t.Helper() - - // This is copied from Client.JoinRoom to test a join failure. - query := make(url.Values, 1) - query.Set("server_name", serverName) - res := c.Do( - t, - "POST", - []string{"_matrix", "client", "v3", "join", roomIDOrAlias}, - client.WithQueries(query), - ) - must.MatchFailure(t, res) -} - // Creates two rooms on room version 8 and sets the second room to have // restricted join rules with allow set to the first room. func setupRestrictedRoom(t *testing.T, deployment *docker.Deployment, roomVersion string, joinRule string) (*client.CSAPI, string, string) { @@ -73,7 +57,8 @@ func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, a t.Helper() t.Run("Join should fail initially", func(t *testing.T) { - failJoinRoom(t, bob, room, "hs1") + res := bob.JoinRoom(t, room, []string{"hs1"}) + must.MatchFailure(t, res) }) t.Run("Join should succeed when joined to allowed room", func(t *testing.T) { @@ -137,7 +122,8 @@ func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, a return ev.Get("content").Get("membership").Str == "leave" })) - failJoinRoom(t, bob, room, "hs1") + res := bob.JoinRoom(t, room, []string{"hs1"}) + must.MatchFailure(t, res) }) t.Run("Join should succeed when invited", func(t *testing.T) { @@ -168,7 +154,7 @@ func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, a }, ) // Fails since invalid values get filtered out of allow. - failJoinRoom(t, bob, room, "hs1") + must.MatchFailure(t, bob.JoinRoom(t, room, []string{"hs1"})) alice.SendEventSynced( t, @@ -184,7 +170,7 @@ func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, a }, ) // Fails since a fully invalid allow key requires an invite. - failJoinRoom(t, bob, room, "hs1") + must.MatchFailure(t, bob.JoinRoom(t, room, []string{"hs1"})) }) } @@ -283,7 +269,7 @@ func doTestRestrictedRoomsRemoteJoinLocalUser(t *testing.T, roomVersion string, }) // Bob cannot join the room. - failJoinRoom(t, bob, room, "hs1") + must.MatchFailure(t, bob.JoinRoom(t, room, []string{"hs1"})) // Join the allowed room via hs2. bob.JoinRoom(t, allowed_room, []string{"hs2"}) @@ -423,7 +409,8 @@ func doTestRestrictedRoomsRemoteJoinFailOver(t *testing.T, roomVersion string, j // hs2 doesn't have anyone to invite from, so the join fails. t.Logf("%s joins the restricted room via hs2, which is expected to fail.", charlie.UserID) - failJoinRoom(t, charlie, room, "hs2") + res := bob.JoinRoom(t, room, []string{"hs2"}) + must.MatchFailure(t, res) // Including hs1 (and failing over to it) allows the join to succeed. t.Logf("%s joins the restricted room via {hs2,hs1}.", charlie.UserID) @@ -474,7 +461,7 @@ func doTestRestrictedRoomsRemoteJoinFailOver(t *testing.T, roomVersion string, j // hs2 cannot complete the join since they do not know if Charlie meets the // requirements (since it is no longer in the allowed room). t.Logf("%s joins the restricted room via hs2, which is expected to fail.", charlie.UserID) - failJoinRoom(t, charlie, room, "hs2") + must.MatchFailure(t, bob.JoinRoom(t, room, []string{"hs2"})) // Including hs1 (and failing over to it) allows the join to succeed. t.Logf("%s joins the restricted room via {hs2,hs1}.", charlie.UserID) From 4724210b1eba2a26219b93226a90c9e42c189e44 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 9 Oct 2023 14:26:30 +0100 Subject: [PATCH 2/9] Convert JoinRoom --- client/client.go | 14 +++++++++++--- tests/csapi/admin_test.go | 2 +- tests/csapi/apidoc_room_alias_test.go | 12 ++++++------ tests/csapi/apidoc_room_forget_test.go | 12 ++++++------ .../apidoc_room_history_visibility_test.go | 10 +++++----- tests/csapi/apidoc_room_members_test.go | 6 +++--- tests/csapi/device_lists_test.go | 14 +++++++------- tests/csapi/keychanges_test.go | 2 +- tests/csapi/room_ban_test.go | 2 +- tests/csapi/room_kick_test.go | 2 +- tests/csapi/room_leave_test.go | 4 ++-- tests/csapi/room_members_test.go | 6 +++--- tests/csapi/room_messages_test.go | 4 ++-- tests/csapi/room_typing_test.go | 4 ++-- tests/csapi/rooms_invite_test.go | 8 ++++---- tests/csapi/rooms_members_local_test.go | 2 +- tests/csapi/rooms_state_test.go | 4 ++-- tests/csapi/sync_archive_test.go | 8 ++++---- tests/csapi/sync_test.go | 18 +++++++++--------- tests/csapi/thread_notifications_test.go | 2 +- .../csapi/user_directory_display_names_test.go | 4 ++-- tests/federation_acl_test.go | 8 ++++---- tests/federation_redaction_test.go | 2 +- tests/federation_room_ban_test.go | 4 ++-- .../federation_room_get_missing_events_test.go | 2 +- .../federation_room_join_partial_state_test.go | 12 ++++++------ tests/federation_room_join_test.go | 16 ++++++++-------- tests/federation_room_send_test.go | 2 +- tests/federation_room_typing_test.go | 4 ++-- tests/federation_rooms_invite_test.go | 2 +- tests/federation_unreject_rejected_test.go | 2 +- tests/msc2836_test.go | 4 ++-- tests/restricted_room_hierarchy_test.go | 4 ++-- tests/room_hierarchy_test.go | 2 +- tests/room_timestamp_to_event_test.go | 14 +++++++------- 35 files changed, 113 insertions(+), 105 deletions(-) diff --git a/client/client.go b/client/client.go index 923f929c..6f194418 100644 --- a/client/client.go +++ b/client/client.go @@ -90,18 +90,26 @@ func (c *CSAPI) DownloadContent(t TestLike, mxcUri string) ([]byte, string) { return b, contentType } -// CreateRoom creates a room with an optional HTTP request body. Fails the test on error. Returns the room ID. -func (c *CSAPI) CreateRoom(t TestLike, creationContent interface{}) string { +// MustCreateRoom creates a room with an optional HTTP request body. Fails the test on error. Returns the room ID. +func (c *CSAPI) MustCreateRoom(t TestLike, creationContent interface{}) string { t.Helper() - res := c.MustDo(t, "POST", []string{"_matrix", "client", "v3", "createRoom"}, WithJSONBody(t, creationContent)) + res := c.CreateRoom(t, creationContent) + mustRespondOK(t, res) body := ParseJSON(t, res) return GetJSONFieldStr(t, body, "room_id") } +// CreateRoom creates a room with an optional HTTP request body. +func (c *CSAPI) CreateRoom(t TestLike, creationContent interface{}) *http.Response { + t.Helper() + return c.Do(t, "POST", []string{"_matrix", "client", "v3", "createRoom"}, WithJSONBody(t, creationContent)) +} + // MustJoinRoom joins the room ID or alias given, else fails the test. Returns the room ID. func (c *CSAPI) MustJoinRoom(t TestLike, roomIDOrAlias string, serverNames []string) string { t.Helper() res := c.JoinRoom(t, roomIDOrAlias, serverNames) + mustRespondOK(t, res) // return the room ID if we joined with it if roomIDOrAlias[0] == '!' { return roomIDOrAlias diff --git a/tests/csapi/admin_test.go b/tests/csapi/admin_test.go index 6d7d475c..2ed74596 100644 --- a/tests/csapi/admin_test.go +++ b/tests/csapi/admin_test.go @@ -64,7 +64,7 @@ func TestServerNotices(t *testing.T) { }) }) t.Run("Alice can join the alert room", func(t *testing.T) { - alice.JoinRoom(t, roomID, []string{}) + alice.MustJoinRoom(t, roomID, []string{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHasEventID(roomID, eventID)) }) t.Run("Alice can leave the alert room, after joining it", func(t *testing.T) { diff --git a/tests/csapi/apidoc_room_alias_test.go b/tests/csapi/apidoc_room_alias_test.go index dc134ee5..1a8334ad 100644 --- a/tests/csapi/apidoc_room_alias_test.go +++ b/tests/csapi/apidoc_room_alias_test.go @@ -198,7 +198,7 @@ func TestRoomDeleteAlias(t *testing.T) { "preset": "public_chat", }) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) roomAlias := "#no_ops_delete:hs1" @@ -230,7 +230,7 @@ func TestRoomDeleteAlias(t *testing.T) { "preset": "public_chat", }) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) roomAlias := "#no_ops_delete_canonical:hs1" @@ -314,7 +314,7 @@ func TestRoomDeleteAlias(t *testing.T) { randomAlias := "#random_alias_2:hs1" alice.InviteRoom(t, roomID, bob.UserID) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) res := setRoomAliasResp(t, bob, roomID, randomAlias) @@ -345,7 +345,7 @@ func TestRoomDeleteAlias(t *testing.T) { randomAlias := "#random_alias_3:hs1" alice.InviteRoom(t, roomID, bob.UserID) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.power_levels", @@ -388,7 +388,7 @@ func TestRoomDeleteAlias(t *testing.T) { randomAlias := "#random_alias_4:hs1" alice.InviteRoom(t, roomID, bob.UserID) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) res := setRoomAliasResp(t, alice, roomID, randomAlias) must.MatchResponse(t, res, match.HTTPResponse{ @@ -421,7 +421,7 @@ func TestRoomDeleteAlias(t *testing.T) { randomAlias := "#random_alias_5:hs1" alice.InviteRoom(t, roomID, bob.UserID) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.power_levels", diff --git a/tests/csapi/apidoc_room_forget_test.go b/tests/csapi/apidoc_room_forget_test.go index dcce4d1f..aedf5a06 100644 --- a/tests/csapi/apidoc_room_forget_test.go +++ b/tests/csapi/apidoc_room_forget_test.go @@ -38,7 +38,7 @@ func TestRoomForget(t *testing.T) { t.Run("Forgotten room messages cannot be paginated", func(t *testing.T) { t.Parallel() roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ @@ -60,7 +60,7 @@ func TestRoomForget(t *testing.T) { t.Run("Forgetting room does not show up in v2 initial /sync", func(t *testing.T) { t.Parallel() roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ @@ -105,7 +105,7 @@ func TestRoomForget(t *testing.T) { // left if it is forgotten quickly. This is arguably a bug in the spec. t.Parallel() roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ @@ -143,7 +143,7 @@ func TestRoomForget(t *testing.T) { t.Run("Can forget room you've been kicked from", func(t *testing.T) { t.Parallel() roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ @@ -185,7 +185,7 @@ func TestRoomForget(t *testing.T) { }, }) // Bob joins room - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) messageID := alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ @@ -208,7 +208,7 @@ func TestRoomForget(t *testing.T) { }) // Re-invite bob alice.InviteRoom(t, roomID, bob.UserID) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) // Query messages queryParams := url.Values{} queryParams.Set("dir", "b") diff --git a/tests/csapi/apidoc_room_history_visibility_test.go b/tests/csapi/apidoc_room_history_visibility_test.go index 1dfb3022..e42ad4e1 100644 --- a/tests/csapi/apidoc_room_history_visibility_test.go +++ b/tests/csapi/apidoc_room_history_visibility_test.go @@ -44,7 +44,7 @@ func TestFetchEvent(t *testing.T) { roomID := createRoomWithVisibility(t, alice, "shared") - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) @@ -98,7 +98,7 @@ func TestFetchHistoricalJoinedEventDenied(t *testing.T) { }, }) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) res := fetchEvent(t, bob, roomID, eventID) @@ -127,7 +127,7 @@ func TestFetchHistoricalSharedEvent(t *testing.T) { }, }) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) res := fetchEvent(t, bob, roomID, eventID) @@ -174,7 +174,7 @@ func TestFetchHistoricalInvitedEventFromBetweenInvite(t *testing.T) { }, }) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) res := fetchEvent(t, bob, roomID, eventID) @@ -221,7 +221,7 @@ func TestFetchHistoricalInvitedEventFromBeforeInvite(t *testing.T) { alice.InviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) res := fetchEvent(t, bob, roomID, eventID) diff --git a/tests/csapi/apidoc_room_members_test.go b/tests/csapi/apidoc_room_members_test.go index 48223d1b..e92de7e3 100644 --- a/tests/csapi/apidoc_room_members_test.go +++ b/tests/csapi/apidoc_room_members_test.go @@ -98,7 +98,7 @@ func TestRoomMembers(t *testing.T) { bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) // Sync to make sure bob has joined bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) @@ -130,7 +130,7 @@ func TestRoomMembers(t *testing.T) { bob.InviteRoom(t, roomID, alice.UserID) since := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(alice.UserID, roomID)) - alice.JoinRoom(t, roomID, nil) + alice.MustJoinRoom(t, roomID, nil) alice.MustSyncUntil(t, client.SyncReq{Since: since}, client.SyncJoinedTo(alice.UserID, roomID)) }) // sytest: POST /join/:room_id can join a room with custom content @@ -247,7 +247,7 @@ func TestRoomMembers(t *testing.T) { roomID := alice.CreateRoom(t, map[string]interface{}{}) alice.InviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) bob.LeaveRoom(t, roomID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID)) diff --git a/tests/csapi/device_lists_test.go b/tests/csapi/device_lists_test.go index 6c9eb00c..bff4cce5 100644 --- a/tests/csapi/device_lists_test.go +++ b/tests/csapi/device_lists_test.go @@ -121,7 +121,7 @@ func TestDeviceListUpdates(t *testing.T) { // The observing user must share a room with the dummy barrier user. roomID := barry.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - observingUser.JoinRoom(t, roomID, []string{otherHSName}) + observingUser.MustJoinRoom(t, roomID, []string{otherHSName}) observingUser.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(observingUser.UserID, roomID)) return func(t *testing.T, nextBatch string) string { @@ -155,7 +155,7 @@ func TestDeviceListUpdates(t *testing.T) { // Bob joins the room t.Logf("%s joins the test room.", bob.UserID) - bob.JoinRoom(t, roomID, []string{hsName}) + bob.MustJoinRoom(t, roomID, []string{hsName}) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // Check that Alice receives a device list update from Bob @@ -202,7 +202,7 @@ func TestDeviceListUpdates(t *testing.T) { // Alice joins the room t.Logf("%s joins the test room.", alice.UserID) - alice.JoinRoom(t, roomID, []string{otherHSName}) + alice.MustJoinRoom(t, roomID, []string{otherHSName}) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) // Check that Alice receives a device list update from Bob @@ -244,7 +244,7 @@ func TestDeviceListUpdates(t *testing.T) { // Bob joins the room t.Logf("%s joins the test room.", bob.UserID) - bob.JoinRoom(t, roomID, []string{hsName}) + bob.MustJoinRoom(t, roomID, []string{hsName}) bobNextBatch := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // Alice performs an initial sync @@ -295,7 +295,7 @@ func TestDeviceListUpdates(t *testing.T) { // Alice joins the room t.Logf("%s joins the test room.", alice.UserID) - alice.JoinRoom(t, roomID, []string{otherHSName}) + alice.MustJoinRoom(t, roomID, []string{otherHSName}) bobNextBatch := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) // Alice performs an initial sync @@ -346,7 +346,7 @@ func TestDeviceListUpdates(t *testing.T) { // Bob joins the room t.Logf("%s joins the test room.", bob.UserID) - bob.JoinRoom(t, roomID, []string{hsName}) + bob.MustJoinRoom(t, roomID, []string{hsName}) bobNextBatch := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // Alice performs an initial sync @@ -378,7 +378,7 @@ func TestDeviceListUpdates(t *testing.T) { // Bob rejoins the room t.Logf("%s joins the test room.", bob.UserID) - bob.JoinRoom(t, roomID, []string{hsName}) + bob.MustJoinRoom(t, roomID, []string{hsName}) bob.MustSyncUntil(t, client.SyncReq{Since: bobNextBatch}, client.SyncJoinedTo(bob.UserID, roomID)) // Check that Alice is notified that Bob's devices have a change diff --git a/tests/csapi/keychanges_test.go b/tests/csapi/keychanges_test.go index 52efd3de..29abdd52 100644 --- a/tests/csapi/keychanges_test.go +++ b/tests/csapi/keychanges_test.go @@ -27,7 +27,7 @@ func TestKeyChangesLocal(t *testing.T) { mustUploadKeys(t, bob) roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) nextBatch1 := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) reqBody := client.WithJSONBody(t, map[string]interface{}{ diff --git a/tests/csapi/room_ban_test.go b/tests/csapi/room_ban_test.go index b64ba97f..ca507ca6 100644 --- a/tests/csapi/room_ban_test.go +++ b/tests/csapi/room_ban_test.go @@ -45,7 +45,7 @@ func TestNotPresentUserCannotBanOthers(t *testing.T) { "preset": "public_chat", }) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.power_levels", diff --git a/tests/csapi/room_kick_test.go b/tests/csapi/room_kick_test.go index 9fdc4a2a..849cb2c3 100644 --- a/tests/csapi/room_kick_test.go +++ b/tests/csapi/room_kick_test.go @@ -45,7 +45,7 @@ func TestCannotKickLeftUser(t *testing.T) { "preset": "public_chat", }) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) diff --git a/tests/csapi/room_leave_test.go b/tests/csapi/room_leave_test.go index 30d3ac6c..ecb42e4e 100644 --- a/tests/csapi/room_leave_test.go +++ b/tests/csapi/room_leave_test.go @@ -34,7 +34,7 @@ func TestLeftRoomFixture(t *testing.T) { "preset": "public_chat", }) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) @@ -117,7 +117,7 @@ func TestLeftRoomFixture(t *testing.T) { // Have charlie join the room, to check against /members calls later // (Bob should not see Charlie in /members after he leaves the room.) - charlie.JoinRoom(t, roomID, nil) + charlie.MustJoinRoom(t, roomID, nil) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie.UserID, roomID)) // sytest: Can get rooms/{roomId}/state for a departed room (SPEC-216) diff --git a/tests/csapi/room_members_test.go b/tests/csapi/room_members_test.go index 8958faaa..a846d401 100644 --- a/tests/csapi/room_members_test.go +++ b/tests/csapi/room_members_test.go @@ -30,7 +30,7 @@ func TestGetRoomMembers(t *testing.T) { "preset": "public_chat", }) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) @@ -80,7 +80,7 @@ func TestGetRoomMembersAtPoint(t *testing.T) { syncResp, _ := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) sinceToken := syncResp.Get("rooms.join." + client.GjsonEscape(roomID) + ".timeline.prev_batch").Str - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) bob.SendEventSynced(t, roomID, b.Event{ @@ -129,7 +129,7 @@ func TestGetFilteredRoomMembers(t *testing.T) { "preset": "public_chat", }) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) diff --git a/tests/csapi/room_messages_test.go b/tests/csapi/room_messages_test.go index 506a2657..c252e78c 100644 --- a/tests/csapi/room_messages_test.go +++ b/tests/csapi/room_messages_test.go @@ -136,8 +136,8 @@ func TestRoomMessagesLazyLoading(t *testing.T) { charlie := deployment.Client(t, "hs1", "@charlie:hs1") roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.JoinRoom(t, roomID, nil) - charlie.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) + charlie.MustJoinRoom(t, roomID, nil) bob.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", diff --git a/tests/csapi/room_typing_test.go b/tests/csapi/room_typing_test.go index 055188b8..8f060452 100644 --- a/tests/csapi/room_typing_test.go +++ b/tests/csapi/room_typing_test.go @@ -17,7 +17,7 @@ func TestTyping(t *testing.T) { roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) token := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) alice.SendTyping(t, roomID, true, 10000) @@ -45,7 +45,7 @@ func TestLeakyTyping(t *testing.T) { // Alice creates a room. Bob joins it. roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) bobToken := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) diff --git a/tests/csapi/rooms_invite_test.go b/tests/csapi/rooms_invite_test.go index 99840acf..26b04f3d 100644 --- a/tests/csapi/rooms_invite_test.go +++ b/tests/csapi/rooms_invite_test.go @@ -27,7 +27,7 @@ func TestRoomsInvite(t *testing.T) { }) alice.InviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) }) @@ -103,7 +103,7 @@ func TestRoomsInvite(t *testing.T) { alice.InviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) body := client.WithJSONBody(t, map[string]interface{}{ @@ -140,7 +140,7 @@ func TestRoomsInvite(t *testing.T) { // Invite & join bob alice.InviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) // Raise the powerlevel @@ -158,7 +158,7 @@ func TestRoomsInvite(t *testing.T) { bob.InviteRoom(t, roomID, alice.UserID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(alice.UserID, roomID)) // Alice should be able to rejoin - alice.JoinRoom(t, roomID, []string{}) + alice.MustJoinRoom(t, roomID, []string{}) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) }) }) diff --git a/tests/csapi/rooms_members_local_test.go b/tests/csapi/rooms_members_local_test.go index abdf2c9d..855f867f 100644 --- a/tests/csapi/rooms_members_local_test.go +++ b/tests/csapi/rooms_members_local_test.go @@ -26,7 +26,7 @@ func TestMembersLocal(t *testing.T) { ) _, incrementalSyncTokenBeforeBobJoinsRoom := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) t.Run("Parallel", func(t *testing.T) { // sytest: New room members see their own join event diff --git a/tests/csapi/rooms_state_test.go b/tests/csapi/rooms_state_test.go index 0d9c9d90..7488f0ee 100644 --- a/tests/csapi/rooms_state_test.go +++ b/tests/csapi/rooms_state_test.go @@ -109,12 +109,12 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) { "preset": "public_chat", }) - alice.JoinRoom(t, roomID, nil) + alice.MustJoinRoom(t, roomID, nil) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) firstID := *getEventIdForState(t, alice, roomID, "m.room.member", alice.UserID) - alice.JoinRoom(t, roomID, nil) + alice.MustJoinRoom(t, roomID, nil) // Unfortunately there is no way to definitively wait // for a 'potentially false second join event' without diff --git a/tests/csapi/sync_archive_test.go b/tests/csapi/sync_archive_test.go index 8dfdd21c..7621ba8b 100644 --- a/tests/csapi/sync_archive_test.go +++ b/tests/csapi/sync_archive_test.go @@ -148,7 +148,7 @@ func TestArchivedRoomsHistory(t *testing.T) { "preset": "public_chat", }) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) _, bobSince := bob.MustSync(t, client.SyncReq{Filter: bobFilter, TimeoutMillis: "0"}) @@ -255,8 +255,8 @@ func TestOlderLeftRoomsNotInLeaveSection(t *testing.T) { "preset": "public_chat", }) - bob.JoinRoom(t, roomToLeave, nil) - bob.JoinRoom(t, roomToSpam, nil) + bob.MustJoinRoom(t, roomToLeave, nil) + bob.MustJoinRoom(t, roomToSpam, nil) bob.MustSyncUntil( t, client.SyncReq{}, @@ -339,7 +339,7 @@ func TestLeaveEventVisibility(t *testing.T) { }, "preset": "public_chat", }) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) aliceSince := alice.MustSyncUntil( t, diff --git a/tests/csapi/sync_test.go b/tests/csapi/sync_test.go index e1c68b1b..22f82fa3 100644 --- a/tests/csapi/sync_test.go +++ b/tests/csapi/sync_test.go @@ -31,7 +31,7 @@ func TestCumulativeJoinLeaveJoinSync(t *testing.T) { // Get floating next_batch from before joining at all _, since = alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) - alice.JoinRoom(t, roomID, nil) + alice.MustJoinRoom(t, roomID, nil) // This assumes that sync does not have side-effects in servers. // @@ -42,7 +42,7 @@ func TestCumulativeJoinLeaveJoinSync(t *testing.T) { sinceLeave := alice.MustSyncUntil(t, client.SyncReq{Since: sinceJoin}, client.SyncLeftFrom(alice.UserID, roomID)) - alice.JoinRoom(t, roomID, nil) + alice.MustJoinRoom(t, roomID, nil) alice.MustSyncUntil(t, client.SyncReq{Since: sinceLeave}, client.SyncJoinedTo(alice.UserID, roomID)) @@ -88,7 +88,7 @@ func TestTentativeEventualJoiningAfterRejecting(t *testing.T) { t.Errorf("Bob just rejected an invite, it should show up under 'leave' in a full sync") } - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) start = time.Now() leaveExists = true @@ -178,7 +178,7 @@ func TestSync(t *testing.T) { sendMessages(t, alice, roomID, "alice message 1-", 4) _, nextBatch := bob.MustSync(t, client.SyncReq{Filter: filterBob}) sendMessages(t, alice, roomID, "alice message 2-", 4) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) res, _ := bob.MustSync(t, client.SyncReq{Filter: filterBob, Since: nextBatch}) room := res.Get("rooms.join." + client.GjsonEscape(roomID)) @@ -206,7 +206,7 @@ func TestSync(t *testing.T) { roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) _, nextBatch := bob.MustSync(t, client.SyncReq{}) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) nextBatch = bob.MustSyncUntil(t, client.SyncReq{Since: nextBatch}, func(userID string, sync gjson.Result) error { presence := sync.Get("presence") @@ -227,7 +227,7 @@ func TestSync(t *testing.T) { nextBatch := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) sendMessages(t, alice, roomID, "dummy message", 1) _, nextBatch = alice.MustSync(t, client.SyncReq{Since: nextBatch}) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // wait until there are presence events @@ -389,8 +389,8 @@ func TestPresenceSyncDifferentRooms(t *testing.T) { alice.InviteRoom(t, bobRoomID, bob.UserID) alice.InviteRoom(t, charlieRoomID, charlie.UserID) - bob.JoinRoom(t, bobRoomID, nil) - charlie.JoinRoom(t, charlieRoomID, nil) + bob.MustJoinRoom(t, bobRoomID, nil) + charlie.MustJoinRoom(t, charlieRoomID, nil) nextBatch = alice.MustSyncUntil(t, client.SyncReq{Since: nextBatch}, @@ -471,7 +471,7 @@ func TestRoomSummary(t *testing.T) { } sinceToken := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) // Verify Bob sees the correct room summary bob.MustSyncUntil(t, client.SyncReq{Since: sinceToken}, client.SyncJoinedTo(bob.UserID, roomID), joinedCheck) // .. and Alice as well. diff --git a/tests/csapi/thread_notifications_test.go b/tests/csapi/thread_notifications_test.go index 4009afb1..f9e2a0a5 100644 --- a/tests/csapi/thread_notifications_test.go +++ b/tests/csapi/thread_notifications_test.go @@ -79,7 +79,7 @@ func TestThreadedReceipts(t *testing.T) { bob := deployment.Client(t, "hs1", "@bob:hs1") roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) // A next batch token which is past the initial room creation. bobNextBatch := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) diff --git a/tests/csapi/user_directory_display_names_test.go b/tests/csapi/user_directory_display_names_test.go index ba626a0c..374614b9 100644 --- a/tests/csapi/user_directory_display_names_test.go +++ b/tests/csapi/user_directory_display_names_test.go @@ -142,7 +142,7 @@ func TestRoomSpecificUsernameChange(t *testing.T) { // Alice waits until she sees the invite, then accepts. alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(alice.UserID, privateRoom)) - alice.JoinRoom(t, privateRoom, nil) + alice.MustJoinRoom(t, privateRoom, nil) // Alice reveals her private name to Bob alice.MustDo( @@ -171,7 +171,7 @@ func TestRoomSpecificUsernameAtJoin(t *testing.T) { // Alice waits until she sees the invite, then accepts. // When she accepts, she does so with a specific displayname. alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(alice.UserID, privateRoom)) - alice.JoinRoom(t, privateRoom, nil) + alice.MustJoinRoom(t, privateRoom, nil) // Alice reveals her private name to Bob alice.MustDo( diff --git a/tests/federation_acl_test.go b/tests/federation_acl_test.go index 74f265a3..3ffa3f43 100644 --- a/tests/federation_acl_test.go +++ b/tests/federation_acl_test.go @@ -57,15 +57,15 @@ func TestACLs(t *testing.T) { aliceSince := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) // 3. Join this room from 2nd server - bob.JoinRoom(t, roomID, []string{"hs1"}) + bob.MustJoinRoom(t, roomID, []string{"hs1"}) aliceSince = alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncJoinedTo(bob.UserID, roomID)) bobSince := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // create a different room used for a sentinel event sentinelRoom := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) aliceSince = alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncJoinedTo(alice.UserID, sentinelRoom)) - bob.JoinRoom(t, sentinelRoom, []string{"hs1"}) - charlie.JoinRoom(t, sentinelRoom, []string{"hs1"}) + bob.MustJoinRoom(t, sentinelRoom, []string{"hs1"}) + charlie.MustJoinRoom(t, sentinelRoom, []string{"hs1"}) aliceSince = alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncJoinedTo(bob.UserID, sentinelRoom), client.SyncJoinedTo(charlie.UserID, sentinelRoom), @@ -87,7 +87,7 @@ func TestACLs(t *testing.T) { bob.MustSyncUntil(t, client.SyncReq{Since: bobSince}, client.SyncTimelineHasEventID(roomID, eventID)) // 5. Join from 3rd server. - charlie.JoinRoom(t, roomID, []string{"hs1"}) + charlie.MustJoinRoom(t, roomID, []string{"hs1"}) aliceSince = alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncJoinedTo(charlie.UserID, roomID)) charlieSince := charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie.UserID, roomID)) diff --git a/tests/federation_redaction_test.go b/tests/federation_redaction_test.go index 2fb4a443..3c0f463b 100644 --- a/tests/federation_redaction_test.go +++ b/tests/federation_redaction_test.go @@ -53,7 +53,7 @@ func TestFederationRedactSendsWithoutEvent(t *testing.T) { roomAlias := srv.MakeAliasMapping("flibble", serverRoom.RoomID) // the local homeserver joins the room - alice.JoinRoom(t, roomAlias, []string{srv.ServerName()}) + alice.MustJoinRoom(t, roomAlias, []string{srv.ServerName()}) // inject event to redact in the room badEvent := srv.MustCreateEvent(t, serverRoom, federation.Event{ diff --git a/tests/federation_room_ban_test.go b/tests/federation_room_ban_test.go index 2295870c..53e9e5b4 100644 --- a/tests/federation_room_ban_test.go +++ b/tests/federation_room_ban_test.go @@ -20,7 +20,7 @@ func TestUnbanViaInvite(t *testing.T) { roomID := bob.CreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) - alice.JoinRoom(t, roomID, []string{"hs2"}) + alice.MustJoinRoom(t, roomID, []string{"hs2"}) // Ban Alice bob.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "ban"}, client.WithJSONBody(t, map[string]interface{}{ @@ -40,5 +40,5 @@ func TestUnbanViaInvite(t *testing.T) { alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(alice.UserID, roomID)) // Alice accepts (this is what previously failed in the issue) - alice.JoinRoom(t, roomID, []string{"hs2"}) + alice.MustJoinRoom(t, roomID, []string{"hs2"}) } diff --git a/tests/federation_room_get_missing_events_test.go b/tests/federation_room_get_missing_events_test.go index e93d0f70..60e4db0a 100644 --- a/tests/federation_room_get_missing_events_test.go +++ b/tests/federation_room_get_missing_events_test.go @@ -190,7 +190,7 @@ func TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6(t *test room := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, charlie)) roomAlias := srv.MakeAliasMapping("flibble", room.RoomID) // join the room - alice.JoinRoom(t, roomAlias, nil) + alice.MustJoinRoom(t, roomAlias, nil) latestEvent := room.Timeline[len(room.Timeline)-1] diff --git a/tests/federation_room_join_partial_state_test.go b/tests/federation_room_join_partial_state_test.go index 8f83164d..ae8eafbf 100644 --- a/tests/federation_room_join_partial_state_test.go +++ b/tests/federation_room_join_partial_state_test.go @@ -1250,7 +1250,7 @@ func TestPartialStateJoin(t *testing.T) { ).Methods("GET") // join charlie on hs2 to the room, via the complement homeserver - charlie.JoinRoom(t, roomID, []string{server.ServerName()}) + charlie.MustJoinRoom(t, roomID, []string{server.ServerName()}) // and let hs1 know that charlie has joined, // otherwise hs1 will refuse /state_ids requests @@ -3463,7 +3463,7 @@ func TestPartialStateJoin(t *testing.T) { defer psjResult.Destroy(t) server.AddPDUHandler(func(e gomatrixserverlib.PDU) bool { return true }) - bob.JoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) + bob.MustJoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) alice.MustSyncUntil(t, client.SyncReq{ Filter: buildLazyLoadingSyncFilter(nil), @@ -3653,7 +3653,7 @@ func TestPartialStateJoin(t *testing.T) { ) t.Log("Bob joins too") - bob.JoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) + bob.MustJoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) t.Log("Bob waits to see his join") bobNextBatch := bob.MustSyncUntil( @@ -3712,7 +3712,7 @@ func TestPartialStateJoin(t *testing.T) { // The resync has not completed because we have not called psjResult.FinishStateRequest() t.Log("Alice rejoins her room") - alice.JoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) + alice.MustJoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) aliceNextBatch = alice.MustSyncUntil( t, client.SyncReq{Since: aliceNextBatch, Filter: buildLazyLoadingSyncFilter(nil)}, @@ -3756,7 +3756,7 @@ func TestPartialStateJoin(t *testing.T) { // The resync has not completed because we have not called psjResult.FinishStateRequest() t.Log("Now Bob joins the room") - bob.JoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) + bob.MustJoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) bob.MustSyncUntil( t, client.SyncReq{Filter: buildLazyLoadingSyncFilter(nil)}, @@ -4280,7 +4280,7 @@ func beginPartialStateJoin(t *testing.T, server *server, serverRoom *federation. ) // have joiningUser join the room by room ID. - joiningUser.JoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) + joiningUser.MustJoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) t.Logf("/join request completed") success = true diff --git a/tests/federation_room_join_test.go b/tests/federation_room_join_test.go index a6942c69..27e7217c 100644 --- a/tests/federation_room_join_test.go +++ b/tests/federation_room_join_test.go @@ -71,7 +71,7 @@ func TestJoinViaRoomIDAndServerName(t *testing.T) { serverRoom := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, charlie)) // join the room by room ID, providing the serverName to join via - alice.JoinRoom(t, serverRoom.RoomID, []string{srv.ServerName()}) + alice.MustJoinRoom(t, serverRoom.RoomID, []string{srv.ServerName()}) // remove the make/send join paths from the Complement server to force HS2 to join via HS1 acceptMakeSendJoinRequests = false @@ -116,7 +116,7 @@ func TestJoinFederatedRoomFailOver(t *testing.T) { t.Logf("%s created room %s.", bob.UserID, roomID) t.Logf("%s joins the room via {complement,hs2}.", alice.UserID) - alice.JoinRoom(t, roomID, []string{srv.ServerName(), "hs2"}) + alice.MustJoinRoom(t, roomID, []string{srv.ServerName(), "hs2"}) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) } @@ -174,7 +174,7 @@ func TestJoinFederatedRoomWithUnverifiableEvents(t *testing.T) { unsignedEvent, err := verImpl.NewEventFromTrustedJSON(raw, false) must.NotError(t, "failed to make Event from unsigned event JSON", err) room.AddEvent(unsignedEvent) - alice.JoinRoom(t, roomAlias, nil) + alice.MustJoinRoom(t, roomAlias, nil) }) t.Run("/send_join response with bad signatures shouldn't block room join", func(t *testing.T) { //t.Parallel() @@ -204,7 +204,7 @@ func TestJoinFederatedRoomWithUnverifiableEvents(t *testing.T) { unsignedEvent, err := verImpl.NewEventFromTrustedJSON(raw, false) must.NotError(t, "failed to make Event from unsigned event JSON", err) room.AddEvent(unsignedEvent) - alice.JoinRoom(t, roomAlias, nil) + alice.MustJoinRoom(t, roomAlias, nil) }) t.Run("/send_join response with unobtainable keys shouldn't block room join", func(t *testing.T) { //t.Parallel() @@ -235,7 +235,7 @@ func TestJoinFederatedRoomWithUnverifiableEvents(t *testing.T) { unsignedEvent, err := verImpl.NewEventFromTrustedJSON(raw, false) must.NotError(t, "failed to make Event from unsigned event JSON", err) room.AddEvent(unsignedEvent) - alice.JoinRoom(t, roomAlias, nil) + alice.MustJoinRoom(t, roomAlias, nil) }) t.Run("/send_join response with state with unverifiable auth events shouldn't block room join", func(t *testing.T) { // FIXME: https://github.com/matrix-org/dendrite/issues/2800 @@ -293,7 +293,7 @@ func TestJoinFederatedRoomWithUnverifiableEvents(t *testing.T) { room.AddEvent(goodEvent) t.Logf("Created state event %s", goodEvent.EventID()) - alice.JoinRoom(t, roomAlias, nil) + alice.MustJoinRoom(t, roomAlias, nil) }) } @@ -520,7 +520,7 @@ func TestSendJoinPartialStateResponse(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.JoinRoom(t, roomID, nil) + bob.MustJoinRoom(t, roomID, nil) // now we send a make_join... charlie := srv.UserID("charlie") @@ -609,6 +609,6 @@ func TestJoinFederatedRoomFromApplicationServiceBridgeUser(t *testing.T) { }) // Join the AS bridge user to the remote federated room (without a profile set) - as.JoinRoom(t, roomID, []string{"hs2"}) + as.MustJoinRoom(t, roomID, []string{"hs2"}) }) } diff --git a/tests/federation_room_send_test.go b/tests/federation_room_send_test.go index 85568798..7b6c4249 100644 --- a/tests/federation_room_send_test.go +++ b/tests/federation_room_send_test.go @@ -52,7 +52,7 @@ func TestOutboundFederationSend(t *testing.T) { roomAlias := srv.MakeAliasMapping("flibble", serverRoom.RoomID) // the local homeserver joins the room - alice.JoinRoom(t, roomAlias, []string{deployment.Config.HostnameRunningComplement}) + alice.MustJoinRoom(t, roomAlias, []string{deployment.Config.HostnameRunningComplement}) // the local homeserver sends an event into the room alice.SendEventSynced(t, serverRoom.RoomID, b.Event{ diff --git a/tests/federation_room_typing_test.go b/tests/federation_room_typing_test.go index 8f84d727..81b9696b 100644 --- a/tests/federation_room_typing_test.go +++ b/tests/federation_room_typing_test.go @@ -17,8 +17,8 @@ func TestRemoteTyping(t *testing.T) { charlie := deployment.Client(t, "hs2", "@charlie:hs2") roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.JoinRoom(t, roomID, nil) - charlie.JoinRoom(t, roomID, []string{"hs1"}) + bob.MustJoinRoom(t, roomID, nil) + charlie.MustJoinRoom(t, roomID, []string{"hs1"}) bobToken := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) charlieToken := charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie.UserID, roomID)) diff --git a/tests/federation_rooms_invite_test.go b/tests/federation_rooms_invite_test.go index 5da77328..697d1c5c 100644 --- a/tests/federation_rooms_invite_test.go +++ b/tests/federation_rooms_invite_test.go @@ -92,7 +92,7 @@ func TestFederationRoomsInvite(t *testing.T) { "invite": []string{bob.UserID}, "is_direct": true, }) - bob.JoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []string{}) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool { // We expect a membership event .. diff --git a/tests/federation_unreject_rejected_test.go b/tests/federation_unreject_rejected_test.go index ce799ac5..493f49c7 100644 --- a/tests/federation_unreject_rejected_test.go +++ b/tests/federation_unreject_rejected_test.go @@ -35,7 +35,7 @@ func TestUnrejectRejectedEvents(t *testing.T) { serverRoom := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, bob)) // Join Alice to the new room on the federation server. - alice.JoinRoom(t, serverRoom.RoomID, []string{srv.ServerName()}) + alice.MustJoinRoom(t, serverRoom.RoomID, []string{srv.ServerName()}) alice.MustSyncUntil( t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, serverRoom.RoomID), diff --git a/tests/msc2836_test.go b/tests/msc2836_test.go index 582d3392..de3d237c 100644 --- a/tests/msc2836_test.go +++ b/tests/msc2836_test.go @@ -93,7 +93,7 @@ func TestEventRelationships(t *testing.T) { // Join the room from another server bob := deployment.Client(t, "hs2", "@bob:hs2") - _ = bob.JoinRoom(t, roomID, []string{"hs1"}) + _ = bob.MustJoinRoom(t, roomID, []string{"hs1"}) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // Now hit /event_relationships with eventD @@ -305,7 +305,7 @@ func TestFederatedEventRelationships(t *testing.T) { // join the room on HS1 // HS1 will not have any of these messages, only the room state. - alice.JoinRoom(t, room.RoomID, []string{srv.ServerName()}) + alice.MustJoinRoom(t, room.RoomID, []string{srv.ServerName()}) // send a new child in the thread (child of D) so the HS has something to latch on to. eventE := srv.MustCreateEvent(t, room, federation.Event{ diff --git a/tests/restricted_room_hierarchy_test.go b/tests/restricted_room_hierarchy_test.go index 285c8ba6..95e4b603 100644 --- a/tests/restricted_room_hierarchy_test.go +++ b/tests/restricted_room_hierarchy_test.go @@ -97,7 +97,7 @@ func TestRestrictedRoomsSpacesSummaryLocal(t *testing.T) { requestAndAssertSummary(t, bob, space, []interface{}{space}) // Join the space, and now the restricted room should appear. - bob.JoinRoom(t, space, []string{"hs1"}) + bob.MustJoinRoom(t, space, []string{"hs1"}) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, space)) requestAndAssertSummary(t, bob, space, []interface{}{space, room}) } @@ -181,7 +181,7 @@ func TestRestrictedRoomsSpacesSummaryFederation(t *testing.T) { // charlie joins the space and now hs2 knows that alice is in the space (and // can join the room). - charlie.JoinRoom(t, space, []string{"hs1"}) + charlie.MustJoinRoom(t, space, []string{"hs1"}) charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie.UserID, space)) // The restricted room should appear for alice (who is in the space). diff --git a/tests/room_hierarchy_test.go b/tests/room_hierarchy_test.go index 90522aaf..c6a8a2f3 100644 --- a/tests/room_hierarchy_test.go +++ b/tests/room_hierarchy_test.go @@ -462,7 +462,7 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { // Querying is done by bob who is not yet in any of the rooms. bob := deployment.Client(t, "hs1", "@bob:hs1") - bob.JoinRoom(t, root, []string{"hs1"}) + bob.MustJoinRoom(t, root, []string{"hs1"}) res := bob.MustDo(t, "GET", []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}) must.MatchResponse(t, res, match.HTTPResponse{ diff --git a/tests/room_timestamp_to_event_test.go b/tests/room_timestamp_to_event_test.go index 21f8297e..67f445f0 100644 --- a/tests/room_timestamp_to_event_test.go +++ b/tests/room_timestamp_to_event_test.go @@ -71,7 +71,7 @@ func TestJumpToDateEndpoint(t *testing.T) { // Join from the application service bridge user so we can use to send // some messages at a specific time. - as.JoinRoom(t, roomID, []string{"hs1"}) + as.MustJoinRoom(t, roomID, []string{"hs1"}) // Send a couple messages with the same timestamp after the other test // messages in the room. @@ -91,7 +91,7 @@ func TestJumpToDateEndpoint(t *testing.T) { // Join from the application service bridge user so we can use to send // some messages at a specific time. - as.JoinRoom(t, roomID, []string{"hs1"}) + as.MustJoinRoom(t, roomID, []string{"hs1"}) // Send a couple messages with the same timestamp after the other test // messages in the room. @@ -164,14 +164,14 @@ func TestJumpToDateEndpoint(t *testing.T) { t.Run("looking forwards, should be able to find event that was sent before we joined", func(t *testing.T) { t.Parallel() roomID, eventA, _ := createTestRoom(t, alice) - remoteCharlie.JoinRoom(t, roomID, []string{"hs1"}) + remoteCharlie.MustJoinRoom(t, roomID, []string{"hs1"}) mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, eventA.BeforeTimestamp, "f", eventA.EventID) }) t.Run("looking backwards, should be able to find event that was sent before we joined", func(t *testing.T) { t.Parallel() roomID, _, eventB := createTestRoom(t, alice) - remoteCharlie.JoinRoom(t, roomID, []string{"hs1"}) + remoteCharlie.MustJoinRoom(t, roomID, []string{"hs1"}) mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, eventB.AfterTimestamp, "b", eventB.EventID) }) @@ -182,20 +182,20 @@ func TestJumpToDateEndpoint(t *testing.T) { // Join from the application service bridge user so we can use it to send // some messages at a specific time. - as.JoinRoom(t, roomID, []string{"hs1"}) + as.MustJoinRoom(t, roomID, []string{"hs1"}) // Import a message in the room before the room was created importTime := time.Date(2022, 01, 03, 0, 0, 0, 0, time.Local) importedEventID := sendMessageWithTimestamp(t, as, alice, roomID, importTime, "old imported event") - remoteCharlie.JoinRoom(t, roomID, []string{"hs1"}) + remoteCharlie.MustJoinRoom(t, roomID, []string{"hs1"}) mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, timeBeforeRoomCreation, "b", importedEventID) }) t.Run("can paginate after getting remote event from timestamp to event endpoint", func(t *testing.T) { t.Parallel() roomID, eventA, eventB := createTestRoom(t, alice) - remoteCharlie.JoinRoom(t, roomID, []string{"hs1"}) + remoteCharlie.MustJoinRoom(t, roomID, []string{"hs1"}) mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, eventB.AfterTimestamp, "b", eventB.EventID) // Get a pagination token from eventB From 421832581cc3cc9b06c61e3642fcbd55b7a1d679 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 9 Oct 2023 14:58:26 +0100 Subject: [PATCH 3/9] Add more Must.. functions --- client/client.go | 23 ++++++-- tests/csapi/account_data_test.go | 2 +- tests/csapi/admin_test.go | 2 +- tests/csapi/apidoc_room_alias_test.go | 52 +++++++++---------- tests/csapi/apidoc_room_create_test.go | 12 ++--- tests/csapi/apidoc_room_forget_test.go | 32 ++++++------ .../apidoc_room_history_visibility_test.go | 6 +-- tests/csapi/apidoc_room_members_test.go | 30 +++++------ tests/csapi/apidoc_room_receipts_test.go | 2 +- tests/csapi/apidoc_room_state_test.go | 30 +++++------ tests/csapi/apidoc_search_test.go | 10 ++-- tests/csapi/device_lists_test.go | 18 +++---- tests/csapi/ignored_users_test.go | 6 +-- tests/csapi/invalid_test.go | 4 +- tests/csapi/keychanges_test.go | 2 +- tests/csapi/media_misc_test.go | 2 +- tests/csapi/power_levels_test.go | 4 +- tests/csapi/room_ban_test.go | 2 +- tests/csapi/room_kick_test.go | 6 +-- tests/csapi/room_leave_test.go | 4 +- tests/csapi/room_members_test.go | 8 +-- .../room_messages_relation_filter_test.go | 2 +- tests/csapi/room_messages_test.go | 8 +-- tests/csapi/room_profile_test.go | 2 +- tests/csapi/room_relations_test.go | 6 +-- tests/csapi/room_threads_test.go | 2 +- tests/csapi/room_typing_test.go | 4 +- tests/csapi/rooms_invite_test.go | 38 +++++++------- tests/csapi/rooms_members_local_test.go | 2 +- tests/csapi/rooms_state_test.go | 4 +- tests/csapi/sync_archive_test.go | 30 +++++------ tests/csapi/sync_test.go | 36 ++++++------- tests/csapi/thread_notifications_test.go | 2 +- tests/csapi/txnid_test.go | 12 ++--- .../user_directory_display_names_test.go | 6 +-- tests/direct_messaging_test.go | 6 +-- tests/federation_acl_test.go | 4 +- tests/federation_event_auth_test.go | 2 +- tests/federation_room_alias_test.go | 2 +- tests/federation_room_ban_test.go | 4 +- tests/federation_room_event_auth_test.go | 2 +- ...federation_room_get_missing_events_test.go | 4 +- tests/federation_room_invite_test.go | 6 +-- ...federation_room_join_partial_state_test.go | 26 +++++----- tests/federation_room_join_test.go | 10 ++-- tests/federation_room_typing_test.go | 2 +- tests/federation_rooms_invite_test.go | 20 +++---- tests/knocking_test.go | 12 ++--- tests/msc2836_test.go | 2 +- tests/msc3391_test.go | 2 +- tests/restricted_room_hierarchy_test.go | 8 +-- tests/restricted_rooms_test.go | 26 +++++----- tests/room_hierarchy_test.go | 46 ++++++++-------- tests/room_timestamp_to_event_test.go | 6 +-- 54 files changed, 307 insertions(+), 294 deletions(-) diff --git a/client/client.go b/client/client.go index 6f194418..57945acd 100644 --- a/client/client.go +++ b/client/client.go @@ -134,22 +134,35 @@ func (c *CSAPI) JoinRoom(t TestLike, roomIDOrAlias string, serverNames []string) ) } -// LeaveRoom leaves the room ID, else fails the test. -func (c *CSAPI) LeaveRoom(t TestLike, roomID string) { +// MustLeaveRoom leaves the room ID, else fails the test. +func (c *CSAPI) MustLeaveRoom(t TestLike, roomID string) { + res := c.LeaveRoom(t, roomID) + mustRespondOK(t, res) +} + +// LeaveRoom leaves the room ID. +func (c *CSAPI) LeaveRoom(t TestLike, roomID string) *http.Response { t.Helper() // leave the room body := map[string]interface{}{} - c.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "leave"}, WithJSONBody(t, body)) + return c.Do(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "leave"}, WithJSONBody(t, body)) +} + +// InviteRoom invites userID to the room ID, else fails the test. +func (c *CSAPI) MustInviteRoom(t TestLike, roomID string, userID string) { + t.Helper() + res := c.InviteRoom(t, roomID, userID) + mustRespondOK(t, res) } // InviteRoom invites userID to the room ID, else fails the test. -func (c *CSAPI) InviteRoom(t TestLike, roomID string, userID string) { +func (c *CSAPI) InviteRoom(t TestLike, roomID string, userID string) *http.Response { t.Helper() // Invite the user to the room body := map[string]interface{}{ "user_id": userID, } - c.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "invite"}, WithJSONBody(t, body)) + return c.Do(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "invite"}, WithJSONBody(t, body)) } func (c *CSAPI) GetGlobalAccountData(t TestLike, eventType string) *http.Response { diff --git a/tests/csapi/account_data_test.go b/tests/csapi/account_data_test.go index 70680e14..a22ef0d1 100644 --- a/tests/csapi/account_data_test.go +++ b/tests/csapi/account_data_test.go @@ -42,7 +42,7 @@ func TestAddAccountData(t *testing.T) { // sytest: Can get room account data without syncing t.Run("Can add room account data", func(t *testing.T) { // Create a room - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) // Set the room account data entry alice.SetRoomAccountData(t, roomID, "test.key", map[string]interface{}{"value": "room first"}) diff --git a/tests/csapi/admin_test.go b/tests/csapi/admin_test.go index 2ed74596..c779325d 100644 --- a/tests/csapi/admin_test.go +++ b/tests/csapi/admin_test.go @@ -68,7 +68,7 @@ func TestServerNotices(t *testing.T) { alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHasEventID(roomID, eventID)) }) t.Run("Alice can leave the alert room, after joining it", func(t *testing.T) { - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) }) t.Run("After leaving the alert room and on re-invitation, no new room is created", func(t *testing.T) { sendServerNotice(t, admin, reqBody, nil) diff --git a/tests/csapi/apidoc_room_alias_test.go b/tests/csapi/apidoc_room_alias_test.go index 1a8334ad..c38e2f34 100644 --- a/tests/csapi/apidoc_room_alias_test.go +++ b/tests/csapi/apidoc_room_alias_test.go @@ -68,7 +68,7 @@ func TestRoomAlias(t *testing.T) { t.Run("PUT /directory/room/:room_alias creates alias", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) roomAlias := "#creates_alias:hs1" @@ -86,7 +86,7 @@ func TestRoomAlias(t *testing.T) { // sytest: GET /rooms/:room_id/aliases lists aliases t.Run("GET /rooms/:room_id/aliases lists aliases", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) res := listRoomAliasesResp(t, alice, roomID) @@ -136,7 +136,7 @@ func TestRoomAlias(t *testing.T) { // sytest: Only room members can list aliases of a room t.Run("Only room members can list aliases of a room", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) roomAlias := "#room_members_list:hs1" @@ -166,7 +166,7 @@ func TestRoomAlias(t *testing.T) { const unicodeAlias = "#老虎£я🤨👉ඞ:hs1" - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) res := setRoomAliasResp(t, alice, roomID, unicodeAlias) must.MatchResponse(t, res, match.HTTPResponse{ @@ -194,7 +194,7 @@ func TestRoomDeleteAlias(t *testing.T) { // sytest: Alias creators can delete alias with no ops t.Run("Alias creators can delete alias with no ops", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -226,7 +226,7 @@ func TestRoomDeleteAlias(t *testing.T) { // sytest: Alias creators can delete canonical alias with no ops t.Run("Alias creators can delete canonical alias with no ops", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -276,7 +276,7 @@ func TestRoomDeleteAlias(t *testing.T) { t.Run("Can delete canonical alias", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) roomAlias := "#random_alias:hs1" @@ -309,11 +309,11 @@ func TestRoomDeleteAlias(t *testing.T) { t.Run("Regular users can add and delete aliases in the default room configuration", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) randomAlias := "#random_alias_2:hs1" - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustJoinRoom(t, roomID, nil) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) @@ -340,11 +340,11 @@ func TestRoomDeleteAlias(t *testing.T) { t.Run("Regular users can add and delete aliases when m.room.aliases is restricted", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) randomAlias := "#random_alias_3:hs1" - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustJoinRoom(t, roomID, nil) alice.SendEventSynced(t, roomID, b.Event{ @@ -383,11 +383,11 @@ func TestRoomDeleteAlias(t *testing.T) { t.Run("Users can't delete other's aliases", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) randomAlias := "#random_alias_4:hs1" - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustJoinRoom(t, roomID, nil) res := setRoomAliasResp(t, alice, roomID, randomAlias) @@ -416,11 +416,11 @@ func TestRoomDeleteAlias(t *testing.T) { t.Run("Users with sufficient power-level can delete other's aliases", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) randomAlias := "#random_alias_5:hs1" - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustJoinRoom(t, roomID, nil) alice.SendEventSynced(t, roomID, b.Event{ @@ -466,7 +466,7 @@ func TestRoomCanonicalAlias(t *testing.T) { // sytest: Canonical alias can be set t.Run("m.room.canonical_alias accepts present aliases", func(t *testing.T) { - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) t.Parallel() @@ -483,7 +483,7 @@ func TestRoomCanonicalAlias(t *testing.T) { // part of "Canonical alias can be set" t.Run("m.room.canonical_alias rejects missing aliases", func(t *testing.T) { - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) t.Parallel() @@ -502,7 +502,7 @@ func TestRoomCanonicalAlias(t *testing.T) { // part of "Canonical alias can be set" t.Run("m.room.canonical_alias rejects invalid aliases", func(t *testing.T) { - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) t.Parallel() @@ -520,7 +520,7 @@ func TestRoomCanonicalAlias(t *testing.T) { t.Run("m.room.canonical_alias setting rejects deleted aliases", func(t *testing.T) { - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) t.Parallel() @@ -554,8 +554,8 @@ func TestRoomCanonicalAlias(t *testing.T) { t.Run("m.room.canonical_alias rejects alias pointing to different local room", func(t *testing.T) { - room1 := alice.CreateRoom(t, map[string]interface{}{}) - room2 := alice.CreateRoom(t, map[string]interface{}{}) + room1 := alice.MustCreateRoom(t, map[string]interface{}{}) + room2 := alice.MustCreateRoom(t, map[string]interface{}{}) t.Parallel() @@ -579,7 +579,7 @@ func TestRoomCanonicalAlias(t *testing.T) { // The original sytest has been split out into three tests, the test name only pertained to the first. // sytest: Canonical alias can include alt_aliases t.Run("m.room.canonical_alias accepts present alt_aliases", func(t *testing.T) { - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) t.Parallel() @@ -595,7 +595,7 @@ func TestRoomCanonicalAlias(t *testing.T) { // part of "Canonical alias can include alt_aliases" t.Run("m.room.canonical_alias rejects missing aliases", func(t *testing.T) { - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) t.Parallel() @@ -619,7 +619,7 @@ func TestRoomCanonicalAlias(t *testing.T) { // part of "Canonical alias can include alt_aliases" t.Run("m.room.canonical_alias rejects invalid aliases", func(t *testing.T) { - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) t.Parallel() @@ -644,8 +644,8 @@ func TestRoomCanonicalAlias(t *testing.T) { // part of "Canonical alias can include alt_aliases" t.Run("m.room.canonical_alias rejects alt_alias pointing to different local room", func(t *testing.T) { - room1 := alice.CreateRoom(t, map[string]interface{}{}) - room2 := alice.CreateRoom(t, map[string]interface{}{}) + room1 := alice.MustCreateRoom(t, map[string]interface{}{}) + room2 := alice.MustCreateRoom(t, map[string]interface{}{}) t.Parallel() diff --git a/tests/csapi/apidoc_room_create_test.go b/tests/csapi/apidoc_room_create_test.go index eefb8305..7639d409 100644 --- a/tests/csapi/apidoc_room_create_test.go +++ b/tests/csapi/apidoc_room_create_test.go @@ -56,7 +56,7 @@ func TestRoomCreate(t *testing.T) { t.Run("POST /createRoom makes a room with a topic", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "topic": "Test Room", "preset": "public_chat", }) @@ -71,7 +71,7 @@ func TestRoomCreate(t *testing.T) { // sytest: POST /createRoom makes a room with a name t.Run("POST /createRoom makes a room with a name", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "name": "Test Room", "preset": "public_chat", }) @@ -86,7 +86,7 @@ func TestRoomCreate(t *testing.T) { // sytest: POST /createRoom creates a room with the given version t.Run("POST /createRoom creates a room with the given version", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "room_version": "2", "preset": "public_chat", }) @@ -144,7 +144,7 @@ func TestRoomCreate(t *testing.T) { }) // sytest: Rooms can be created with an initial invite list (SYN-205) t.Run("Rooms can be created with an initial invite list (SYN-205)", func(t *testing.T) { - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "invite": []string{bob.UserID}, }) @@ -153,7 +153,7 @@ func TestRoomCreate(t *testing.T) { // sytest: Can /sync newly created room t.Run("Can /sync newly created room", func(t *testing.T) { - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) // This will do the syncing for us alice.SendEventSynced(t, roomID, b.Event{ @@ -164,7 +164,7 @@ func TestRoomCreate(t *testing.T) { // sytest: POST /createRoom ignores attempts to set the room version via creation_content t.Run("POST /createRoom ignores attempts to set the room version via creation_content", func(t *testing.T) { - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "creation_content": map[string]interface{}{ "test": "azerty", "room_version": "test", diff --git a/tests/csapi/apidoc_room_forget_test.go b/tests/csapi/apidoc_room_forget_test.go index aedf5a06..ba1df726 100644 --- a/tests/csapi/apidoc_room_forget_test.go +++ b/tests/csapi/apidoc_room_forget_test.go @@ -25,7 +25,7 @@ func TestRoomForget(t *testing.T) { // sytest: Can't forget room you're still in t.Run("Can't forget room you're still in", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "private_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "private_chat"}) res := alice.Do(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "forget"}, client.WithJSONBody(t, struct{}{})) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: http.StatusBadRequest, @@ -37,7 +37,7 @@ func TestRoomForget(t *testing.T) { // sytest: Forgotten room messages cannot be paginated t.Run("Forgotten room messages cannot be paginated", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustJoinRoom(t, roomID, []string{}) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", @@ -46,7 +46,7 @@ func TestRoomForget(t *testing.T) { "body": "Hello world!", }, }) - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "forget"}, client.WithJSONBody(t, struct{}{})) res := alice.Do(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "messages"}) must.MatchResponse(t, res, match.HTTPResponse{ @@ -59,7 +59,7 @@ func TestRoomForget(t *testing.T) { // sytest: Forgetting room does not show up in v2 /sync t.Run("Forgetting room does not show up in v2 initial /sync", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustJoinRoom(t, roomID, []string{}) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", @@ -68,7 +68,7 @@ func TestRoomForget(t *testing.T) { "body": "Hello world!", }, }) - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) // Ensure Alice left the room bob.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(alice.UserID, roomID)) alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "forget"}, client.WithJSONBody(t, struct{}{})) @@ -104,7 +104,7 @@ func TestRoomForget(t *testing.T) { // that would make it impossible for other devices to determine that a room has been // left if it is forgotten quickly. This is arguably a bug in the spec. t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustJoinRoom(t, roomID, []string{}) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", @@ -114,7 +114,7 @@ func TestRoomForget(t *testing.T) { }, }) tokenBeforeLeave := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) // Ensure Alice left the room bob.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(alice.UserID, roomID)) alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "forget"}, client.WithJSONBody(t, struct{}{})) @@ -142,7 +142,7 @@ func TestRoomForget(t *testing.T) { // sytest: Can forget room you've been kicked from t.Run("Can forget room you've been kicked from", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustJoinRoom(t, roomID, []string{}) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", @@ -174,9 +174,9 @@ func TestRoomForget(t *testing.T) { // sytest: Can re-join room if re-invited t.Run("Can re-join room if re-invited", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "private_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "private_chat"}) // Invite Bob - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) // Update join_rules alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.join_rules", @@ -194,7 +194,7 @@ func TestRoomForget(t *testing.T) { }, }) // Bob leaves and forgets room - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) // Ensure Bob has really left the room alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID)) bob.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "forget"}, client.WithJSONBody(t, struct{}{})) @@ -207,7 +207,7 @@ func TestRoomForget(t *testing.T) { }, }) // Re-invite bob - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustJoinRoom(t, roomID, []string{}) // Query messages queryParams := url.Values{} @@ -246,14 +246,14 @@ func TestRoomForget(t *testing.T) { t.Run("Can forget room we weren't an actual member", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "private_chat"}) - alice.InviteRoom(t, roomID, bob.UserID) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "private_chat"}) + alice.MustInviteRoom(t, roomID, bob.UserID) // Bob rejects the invite - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) // Bob tries to forget about this room bob.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "forget"}, client.WithJSONBody(t, struct{}{})) // Alice also leaves the room - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) // Alice tries to forget about this room alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "forget"}, client.WithJSONBody(t, struct{}{})) }) diff --git a/tests/csapi/apidoc_room_history_visibility_test.go b/tests/csapi/apidoc_room_history_visibility_test.go index e42ad4e1..a37c9026 100644 --- a/tests/csapi/apidoc_room_history_visibility_test.go +++ b/tests/csapi/apidoc_room_history_visibility_test.go @@ -19,7 +19,7 @@ func fetchEvent(t *testing.T, c *client.CSAPI, roomId, eventId string) *http.Res } func createRoomWithVisibility(t *testing.T, c *client.CSAPI, visibility string) string { - return c.CreateRoom(t, map[string]interface{}{ + return c.MustCreateRoom(t, map[string]interface{}{ "initial_state": []map[string]interface{}{ { "content": map[string]interface{}{ @@ -163,7 +163,7 @@ func TestFetchHistoricalInvitedEventFromBetweenInvite(t *testing.T) { roomID := createRoomWithVisibility(t, alice, "invited") - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) eventID := alice.SendEventSynced(t, roomID, b.Event{ @@ -218,7 +218,7 @@ func TestFetchHistoricalInvitedEventFromBeforeInvite(t *testing.T) { }, }) - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) bob.MustJoinRoom(t, roomID, nil) diff --git a/tests/csapi/apidoc_room_members_test.go b/tests/csapi/apidoc_room_members_test.go index e92de7e3..11876211 100644 --- a/tests/csapi/apidoc_room_members_test.go +++ b/tests/csapi/apidoc_room_members_test.go @@ -20,7 +20,7 @@ func TestRoomMembers(t *testing.T) { // sytest: POST /rooms/:room_id/join can join a room t.Run("POST /rooms/:room_id/join can join a room", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", }) @@ -40,7 +40,7 @@ func TestRoomMembers(t *testing.T) { // sytest: POST /join/:room_alias can join a room t.Run("POST /join/:room_alias can join a room", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", "room_alias_name": "room_alias_random", @@ -61,7 +61,7 @@ func TestRoomMembers(t *testing.T) { // sytest: POST /join/:room_id can join a room t.Run("POST /join/:room_id can join a room", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", }) @@ -90,11 +90,11 @@ func TestRoomMembers(t *testing.T) { // sytest: Test that we can be reinvited to a room we created t.Run("Test that we can be reinvited to a room we created", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) @@ -116,7 +116,7 @@ func TestRoomMembers(t *testing.T) { }, }) - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) // Wait until alice has left the room bob.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas( @@ -128,7 +128,7 @@ func TestRoomMembers(t *testing.T) { }, )) - bob.InviteRoom(t, roomID, alice.UserID) + bob.MustInviteRoom(t, roomID, alice.UserID) since := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(alice.UserID, roomID)) alice.MustJoinRoom(t, roomID, nil) alice.MustSyncUntil(t, client.SyncReq{Since: since}, client.SyncJoinedTo(alice.UserID, roomID)) @@ -136,7 +136,7 @@ func TestRoomMembers(t *testing.T) { // sytest: POST /join/:room_id can join a room with custom content t.Run("POST /join/:room_id can join a room with custom content", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", "room_alias": "helloWorld", @@ -167,7 +167,7 @@ func TestRoomMembers(t *testing.T) { // sytest: POST /join/:room_alias can join a room with custom content t.Run("POST /join/:room_alias can join a room with custom content", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", "room_alias_name": "room_alias_random2", @@ -197,7 +197,7 @@ func TestRoomMembers(t *testing.T) { // sytest: POST /rooms/:room_id/ban can ban a user t.Run("POST /rooms/:room_id/ban can ban a user", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", }) @@ -230,8 +230,8 @@ func TestRoomMembers(t *testing.T) { // sytest: POST /rooms/:room_id/invite can send an invite t.Run("POST /rooms/:room_id/invite can send an invite", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{}) - alice.InviteRoom(t, roomID, bob.UserID) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) + alice.MustInviteRoom(t, roomID, bob.UserID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) res := alice.Do(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.member", bob.UserID}) must.MatchResponse(t, res, match.HTTPResponse{ @@ -244,12 +244,12 @@ func TestRoomMembers(t *testing.T) { // sytest: POST /rooms/:room_id/leave can leave a room t.Run("POST /rooms/:room_id/leave can leave a room", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{}) - alice.InviteRoom(t, roomID, bob.UserID) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) bob.MustJoinRoom(t, roomID, []string{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID)) res := alice.Do(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.member", bob.UserID}) diff --git a/tests/csapi/apidoc_room_receipts_test.go b/tests/csapi/apidoc_room_receipts_test.go index 50724877..eeafbe05 100644 --- a/tests/csapi/apidoc_room_receipts_test.go +++ b/tests/csapi/apidoc_room_receipts_test.go @@ -12,7 +12,7 @@ import ( // tests/10apidoc/37room-receipts.pl func createRoomForReadReceipts(t *testing.T, c *client.CSAPI, deployment *docker.Deployment) (string, string) { - roomID := c.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := c.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) c.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(c.UserID, roomID)) diff --git a/tests/csapi/apidoc_room_state_test.go b/tests/csapi/apidoc_room_state_test.go index af33f6cb..8a8ac1e0 100644 --- a/tests/csapi/apidoc_room_state_test.go +++ b/tests/csapi/apidoc_room_state_test.go @@ -22,7 +22,7 @@ func TestRoomState(t *testing.T) { // sytest: GET /rooms/:room_id/state/m.room.member/:user_id fetches my membership t.Run("GET /rooms/:room_id/state/m.room.member/:user_id fetches my membership", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", }) @@ -40,7 +40,7 @@ func TestRoomState(t *testing.T) { t.Parallel() queryParams := url.Values{} queryParams.Set("format", "event") - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", }) @@ -60,7 +60,7 @@ func TestRoomState(t *testing.T) { t.Run("GET /rooms/:room_id/state/m.room.power_levels fetches powerlevels", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", "room_alias_name": "room_alias", @@ -83,7 +83,7 @@ func TestRoomState(t *testing.T) { // sytest: GET /rooms/:room_id/joined_members fetches my membership t.Run("GET /rooms/:room_id/joined_members fetches my membership", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", }) @@ -101,7 +101,7 @@ func TestRoomState(t *testing.T) { // sytest: GET /publicRooms lists newly-created room t.Run("GET /publicRooms lists newly-created room", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", }) @@ -136,7 +136,7 @@ func TestRoomState(t *testing.T) { t.Run("GET /directory/room/:room_alias yields room ID", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", "room_alias_name": "room_new", @@ -157,7 +157,7 @@ func TestRoomState(t *testing.T) { t.Run("GET /joined_rooms lists newly-created room", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", }) @@ -187,7 +187,7 @@ func TestRoomState(t *testing.T) { t.Run("GET /rooms/:room_id/state/m.room.name gets name", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", "name": "room_name_test", @@ -206,7 +206,7 @@ func TestRoomState(t *testing.T) { t.Run("POST /rooms/:room_id/state/m.room.name sets name", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", }) @@ -230,7 +230,7 @@ func TestRoomState(t *testing.T) { t.Run("GET /rooms/:room_id/state/m.room.topic gets topic", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", "topic": "room_topic_test", @@ -249,7 +249,7 @@ func TestRoomState(t *testing.T) { t.Run("PUT /rooms/:room_id/state/m.room.topic sets topic", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", }) @@ -273,7 +273,7 @@ func TestRoomState(t *testing.T) { t.Run("GET /rooms/:room_id/state fetches entire room state", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", "name": "room_test", @@ -310,7 +310,7 @@ func TestRoomState(t *testing.T) { t.Run("PUT /createRoom with creation content", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{ + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", "creation_content": map[string]interface{}{ @@ -329,8 +329,8 @@ func TestRoomState(t *testing.T) { }) t.Run("GET /rooms/:room_id/joined_members is forbidden after leaving room", func(t *testing.T) { t.Parallel() - roomID := authedClient.CreateRoom(t, map[string]interface{}{}) - authedClient.LeaveRoom(t, roomID) + roomID := authedClient.MustCreateRoom(t, map[string]interface{}{}) + authedClient.MustLeaveRoom(t, roomID) res := authedClient.Do(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "joined_members"}) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: http.StatusForbidden, diff --git a/tests/csapi/apidoc_search_test.go b/tests/csapi/apidoc_search_test.go index f7603301..811e5164 100644 --- a/tests/csapi/apidoc_search_test.go +++ b/tests/csapi/apidoc_search_test.go @@ -27,7 +27,7 @@ func TestSearch(t *testing.T) { // sytest: Can search for an event by body t.Run("Can search for an event by body", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) eventID := alice.SendEventSynced(t, roomID, b.Event{ @@ -71,7 +71,7 @@ func TestSearch(t *testing.T) { // sytest: Can get context around search results t.Run("Can get context around search results", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) @@ -130,7 +130,7 @@ func TestSearch(t *testing.T) { // sytest: Can back-paginate search results t.Run("Can back-paginate search results", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) @@ -198,7 +198,7 @@ func TestSearch(t *testing.T) { // sytest: Search works across an upgraded room and its predecessor t.Run("Search works across an upgraded room and its predecessor", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", "version": "8", }) @@ -277,7 +277,7 @@ func TestSearch(t *testing.T) { // sytest: Search results with $ordering_type ordering do not include redacted events t.Run(fmt.Sprintf("Search results with %s ordering do not include redacted events", ordering), func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) diff --git a/tests/csapi/device_lists_test.go b/tests/csapi/device_lists_test.go index bff4cce5..b1432a73 100644 --- a/tests/csapi/device_lists_test.go +++ b/tests/csapi/device_lists_test.go @@ -120,7 +120,7 @@ func TestDeviceListUpdates(t *testing.T) { barry := deployment.RegisterUser(t, otherHSName, generateLocalpart("barry"), "password", false) // The observing user must share a room with the dummy barrier user. - roomID := barry.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := barry.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) observingUser.MustJoinRoom(t, roomID, []string{otherHSName}) observingUser.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(observingUser.UserID, roomID)) @@ -147,7 +147,7 @@ func TestDeviceListUpdates(t *testing.T) { barrier := makeBarrier(t, deployment, alice, otherHSName) checkBobKeys := uploadNewKeys(t, bob) - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) t.Logf("%s created test room %s.", alice.UserID, roomID) // Alice performs an initial sync @@ -194,7 +194,7 @@ func TestDeviceListUpdates(t *testing.T) { barrier := makeBarrier(t, deployment, alice, otherHSName) checkBobKeys := uploadNewKeys(t, bob) - roomID := bob.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := bob.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) t.Logf("%s created test room %s.", bob.UserID, roomID) // Alice performs an initial sync @@ -239,7 +239,7 @@ func TestDeviceListUpdates(t *testing.T) { barrier := makeBarrier(t, deployment, alice, otherHSName) checkBobKeys := uploadNewKeys(t, bob) - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) t.Logf("%s created test room %s.", alice.UserID, roomID) // Bob joins the room @@ -255,7 +255,7 @@ func TestDeviceListUpdates(t *testing.T) { // Bob leaves the room t.Logf("%s leaves the test room.", bob.UserID) - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) bob.MustSyncUntil(t, client.SyncReq{Since: bobNextBatch}, client.SyncLeftFrom(bob.UserID, roomID)) // Check that Alice is notified that she will no longer receive updates about Bob's devices @@ -290,7 +290,7 @@ func TestDeviceListUpdates(t *testing.T) { barrier := makeBarrier(t, deployment, alice, otherHSName) checkBobKeys := uploadNewKeys(t, bob) - roomID := bob.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := bob.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) t.Logf("%s created test room %s.", bob.UserID, roomID) // Alice joins the room @@ -306,7 +306,7 @@ func TestDeviceListUpdates(t *testing.T) { // Alice leaves the room t.Logf("%s leaves the test room.", alice.UserID) - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) bob.MustSyncUntil(t, client.SyncReq{Since: bobNextBatch}, client.SyncLeftFrom(alice.UserID, roomID)) // Check that Alice is notified that she will no longer receive updates about Bob's devices @@ -341,7 +341,7 @@ func TestDeviceListUpdates(t *testing.T) { barrier := makeBarrier(t, deployment, alice, otherHSName) checkBobKeys := uploadNewKeys(t, bob) - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) t.Logf("%s created test room %s.", alice.UserID, roomID) // Bob joins the room @@ -358,7 +358,7 @@ func TestDeviceListUpdates(t *testing.T) { // Both homeservers think Bob has joined now // Bob leaves the room t.Logf("%s leaves the test room.", bob.UserID) - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) bobNextBatch = bob.MustSyncUntil(t, client.SyncReq{Since: bobNextBatch}, client.SyncLeftFrom(bob.UserID, roomID)) // Check that Alice is notified that she will no longer receive updates about Bob's devices diff --git a/tests/csapi/ignored_users_test.go b/tests/csapi/ignored_users_test.go index ee75290d..6a1105dc 100644 --- a/tests/csapi/ignored_users_test.go +++ b/tests/csapi/ignored_users_test.go @@ -34,7 +34,7 @@ func TestInviteFromIgnoredUsersDoesNotAppearInSync(t *testing.T) { chris := deployment.RegisterUser(t, "hs1", "chris", "sufficiently_long_password_chris", false) // Alice creates a room for herself. - publicRoom := alice.CreateRoom(t, map[string]interface{}{ + publicRoom := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -63,13 +63,13 @@ func TestInviteFromIgnoredUsersDoesNotAppearInSync(t *testing.T) { )) // Bob invites Alice to a private room. - bobRoom := bob.CreateRoom(t, map[string]interface{}{ + bobRoom := bob.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", "invite": []string{alice.UserID}, }) // So does Chris. - chrisRoom := chris.CreateRoom(t, map[string]interface{}{ + chrisRoom := chris.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", "invite": []string{alice.UserID}, }) diff --git a/tests/csapi/invalid_test.go b/tests/csapi/invalid_test.go index 80d14240..2270e032 100644 --- a/tests/csapi/invalid_test.go +++ b/tests/csapi/invalid_test.go @@ -15,7 +15,7 @@ func TestJson(t *testing.T) { deployment := Deploy(t, b.BlueprintAlice) defer deployment.Destroy(t) alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "room_opts": map[string]interface{}{ "room_version": "6", }, @@ -190,7 +190,7 @@ func TestEvent(t *testing.T) { deployment := Deploy(t, b.BlueprintAlice) defer deployment.Destroy(t) alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "room_opts": map[string]interface{}{ "room_version": "6", }, diff --git a/tests/csapi/keychanges_test.go b/tests/csapi/keychanges_test.go index 29abdd52..3767a6f1 100644 --- a/tests/csapi/keychanges_test.go +++ b/tests/csapi/keychanges_test.go @@ -26,7 +26,7 @@ func TestKeyChangesLocal(t *testing.T) { t.Run("New login should create a device_lists.changed entry", func(t *testing.T) { mustUploadKeys(t, bob) - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustJoinRoom(t, roomID, []string{}) nextBatch1 := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) diff --git a/tests/csapi/media_misc_test.go b/tests/csapi/media_misc_test.go index c244abfd..46bcd5b1 100644 --- a/tests/csapi/media_misc_test.go +++ b/tests/csapi/media_misc_test.go @@ -26,7 +26,7 @@ func TestRoomImageRoundtrip(t *testing.T) { mxcUri := alice.UploadContent(t, data.MatrixPng, "test.png", "image/png") - roomId := alice.CreateRoom(t, struct{}{}) + roomId := alice.MustCreateRoom(t, struct{}{}) alice.SendEventSynced(t, roomId, b.Event{ Type: "m.room.message", diff --git a/tests/csapi/power_levels_test.go b/tests/csapi/power_levels_test.go index 772a5596..bfe213ca 100644 --- a/tests/csapi/power_levels_test.go +++ b/tests/csapi/power_levels_test.go @@ -21,7 +21,7 @@ func TestDemotingUsersViaUsersDefault(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "power_level_content_override": map[string]interface{}{ "users_default": 100, // the default is 0 @@ -53,7 +53,7 @@ func TestPowerLevels(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) // sytest: GET /rooms/:room_id/state/m.room.power_levels can fetch levels t.Run("GET /rooms/:room_id/state/m.room.power_levels can fetch levels", func(t *testing.T) { diff --git a/tests/csapi/room_ban_test.go b/tests/csapi/room_ban_test.go index ca507ca6..b2364a1b 100644 --- a/tests/csapi/room_ban_test.go +++ b/tests/csapi/room_ban_test.go @@ -41,7 +41,7 @@ func TestNotPresentUserCannotBanOthers(t *testing.T) { bob := deployment.Client(t, "hs1", "@bob:hs1") charlie := deployment.Client(t, "hs1", "@charlie:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) diff --git a/tests/csapi/room_kick_test.go b/tests/csapi/room_kick_test.go index 849cb2c3..f467d091 100644 --- a/tests/csapi/room_kick_test.go +++ b/tests/csapi/room_kick_test.go @@ -17,7 +17,7 @@ func TestCannotKickNonPresentUser(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -41,7 +41,7 @@ func TestCannotKickLeftUser(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -49,7 +49,7 @@ func TestCannotKickLeftUser(t *testing.T) { alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID)) diff --git a/tests/csapi/room_leave_test.go b/tests/csapi/room_leave_test.go index ecb42e4e..901d5ac0 100644 --- a/tests/csapi/room_leave_test.go +++ b/tests/csapi/room_leave_test.go @@ -21,7 +21,7 @@ func TestLeftRoomFixture(t *testing.T) { bob := deployment.Client(t, "hs1", "@bob:hs1") charlie := deployment.RegisterUser(t, "hs1", "charlie", "sufficiently_long_password_charlie", false) - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "initial_state": []map[string]interface{}{ { "content": map[string]interface{}{ @@ -85,7 +85,7 @@ func TestLeftRoomFixture(t *testing.T) { }, }) - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID)) diff --git a/tests/csapi/room_members_test.go b/tests/csapi/room_members_test.go index a846d401..a932f0fc 100644 --- a/tests/csapi/room_members_test.go +++ b/tests/csapi/room_members_test.go @@ -26,7 +26,7 @@ func TestGetRoomMembers(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -65,7 +65,7 @@ func TestGetRoomMembersAtPoint(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -125,7 +125,7 @@ func TestGetFilteredRoomMembers(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -133,7 +133,7 @@ func TestGetFilteredRoomMembers(t *testing.T) { alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID)) diff --git a/tests/csapi/room_messages_relation_filter_test.go b/tests/csapi/room_messages_relation_filter_test.go index 6d04cc86..5779b9df 100644 --- a/tests/csapi/room_messages_relation_filter_test.go +++ b/tests/csapi/room_messages_relation_filter_test.go @@ -24,7 +24,7 @@ func TestFilterMessagesByRelType(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) // A token which only has the messages of interest after it. beforeToken := alice.MustSyncUntil(t, client.SyncReq{}) diff --git a/tests/csapi/room_messages_test.go b/tests/csapi/room_messages_test.go index c252e78c..c2b10c33 100644 --- a/tests/csapi/room_messages_test.go +++ b/tests/csapi/room_messages_test.go @@ -24,7 +24,7 @@ func TestSendAndFetchMessage(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) const testMessage = "TestSendAndFetchMessage" @@ -85,7 +85,7 @@ func TestSendMessageWithTxn(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) const txnID = "lorem" @@ -135,7 +135,7 @@ func TestRoomMessagesLazyLoading(t *testing.T) { bob := deployment.Client(t, "hs1", "@bob:hs1") charlie := deployment.Client(t, "hs1", "@charlie:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustJoinRoom(t, roomID, nil) charlie.MustJoinRoom(t, roomID, nil) @@ -203,7 +203,7 @@ func TestRoomMessagesLazyLoadingLocalUser(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) token := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) diff --git a/tests/csapi/room_profile_test.go b/tests/csapi/room_profile_test.go index 3a798a57..cc998d5a 100644 --- a/tests/csapi/room_profile_test.go +++ b/tests/csapi/room_profile_test.go @@ -26,7 +26,7 @@ func testProfileFieldUpdate(t *testing.T, field string) { alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) diff --git a/tests/csapi/room_relations_test.go b/tests/csapi/room_relations_test.go index e5bcfd53..e3509a54 100644 --- a/tests/csapi/room_relations_test.go +++ b/tests/csapi/room_relations_test.go @@ -20,7 +20,7 @@ func TestRelations(t *testing.T) { defer deployment.Destroy(t) alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) _, token := alice.MustSync(t, client.SyncReq{}) res := alice.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "send", "m.room.message", "txn-1"}, client.WithJSONBody(t, map[string]interface{}{ @@ -115,7 +115,7 @@ func TestRelationsPagination(t *testing.T) { defer deployment.Destroy(t) alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) _, token := alice.MustSync(t, client.SyncReq{}) res := alice.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "send", "m.room.message", "txn-1"}, client.WithJSONBody(t, map[string]interface{}{ @@ -214,7 +214,7 @@ func TestRelationsPaginationSync(t *testing.T) { defer deployment.Destroy(t) alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) _, token := alice.MustSync(t, client.SyncReq{}) rootEventID := alice.Unsafe_SendEventUnsynced(t, roomID, b.Event{ diff --git a/tests/csapi/room_threads_test.go b/tests/csapi/room_threads_test.go index 713b4081..c52c487f 100644 --- a/tests/csapi/room_threads_test.go +++ b/tests/csapi/room_threads_test.go @@ -36,7 +36,7 @@ func TestThreadsEndpoint(t *testing.T) { defer deployment.Destroy(t) alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) _, token := alice.MustSync(t, client.SyncReq{}) // Create 2 threads in the room. diff --git a/tests/csapi/room_typing_test.go b/tests/csapi/room_typing_test.go index 8f060452..9d6f1408 100644 --- a/tests/csapi/room_typing_test.go +++ b/tests/csapi/room_typing_test.go @@ -15,7 +15,7 @@ func TestTyping(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustJoinRoom(t, roomID, nil) @@ -44,7 +44,7 @@ func TestLeakyTyping(t *testing.T) { charlie := deployment.RegisterUser(t, "hs1", "charlie", "charliepassword", false) // Alice creates a room. Bob joins it. - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustJoinRoom(t, roomID, nil) bobToken := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) diff --git a/tests/csapi/rooms_invite_test.go b/tests/csapi/rooms_invite_test.go index 26b04f3d..59156592 100644 --- a/tests/csapi/rooms_invite_test.go +++ b/tests/csapi/rooms_invite_test.go @@ -22,10 +22,10 @@ func TestRoomsInvite(t *testing.T) { // sytest: Can invite users to invite-only rooms t.Run("Can invite users to invite-only rooms", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) bob.MustJoinRoom(t, roomID, []string{}) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) @@ -35,7 +35,7 @@ func TestRoomsInvite(t *testing.T) { // sytest: Uninvited users cannot join the room t.Run("Uninvited users cannot join the room", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) res := bob.Do(t, "POST", []string{"_matrix", "client", "v3", "join", roomID}) @@ -47,28 +47,28 @@ func TestRoomsInvite(t *testing.T) { // sytest: Invited user can reject invite t.Run("Invited user can reject invite", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID)) }) // sytest: Invited user can reject invite for empty room t.Run("Invited user can reject invite for empty room", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) aliceSince := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bobSince := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncLeftFrom(alice.UserID, roomID)) - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) bobSince = bob.MustSyncUntil(t, client.SyncReq{Since: bobSince}, client.SyncLeftFrom(bob.UserID, roomID)) // sytest: Invited user can reject local invite after originator leaves // Bob should not see an invite when syncing @@ -82,7 +82,7 @@ func TestRoomsInvite(t *testing.T) { // sytest: Users cannot invite themselves to a room t.Run("Users cannot invite themselves to a room", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) body := client.WithJSONBody(t, map[string]interface{}{ @@ -97,11 +97,11 @@ func TestRoomsInvite(t *testing.T) { // sytest: Users cannot invite a user that is already in the room t.Run("Users cannot invite a user that is already in the room", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) bob.MustJoinRoom(t, roomID, []string{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) @@ -118,12 +118,12 @@ func TestRoomsInvite(t *testing.T) { // sytest: Invited user can see room metadata t.Run("Invited user can see room metadata", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", "name": "Invites room", }) - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) res, _ := bob.MustSync(t, client.SyncReq{}) verifyState(t, res, roomID, alice) @@ -133,12 +133,12 @@ func TestRoomsInvite(t *testing.T) { // This is a "multi_test" in Sytest t.Run("Test that we can be reinvited to a room we created", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) // Invite & join bob - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) bob.MustJoinRoom(t, roomID, []string{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) @@ -152,10 +152,10 @@ func TestRoomsInvite(t *testing.T) { alice.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.power_levels"}, reqBody) // Alice leaves the room - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(alice.UserID, roomID)) // Bob re-invites Alice - bob.InviteRoom(t, roomID, alice.UserID) + bob.MustInviteRoom(t, roomID, alice.UserID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(alice.UserID, roomID)) // Alice should be able to rejoin alice.MustJoinRoom(t, roomID, []string{}) diff --git a/tests/csapi/rooms_members_local_test.go b/tests/csapi/rooms_members_local_test.go index 855f867f..dd21d611 100644 --- a/tests/csapi/rooms_members_local_test.go +++ b/tests/csapi/rooms_members_local_test.go @@ -16,7 +16,7 @@ func TestMembersLocal(t *testing.T) { // Here we don't use the BlueprintOneToOneRoom because else Bob would be able to see Alice's presence changes through // that pre-existing one-on-one DM room. So we exclude that here. bob := deployment.RegisterUser(t, "hs1", "bob", "bobspassword", false) - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustDo( t, "PUT", []string{"_matrix", "client", "v3", "presence", bob.UserID, "status"}, diff --git a/tests/csapi/rooms_state_test.go b/tests/csapi/rooms_state_test.go index 7488f0ee..b4d35871 100644 --- a/tests/csapi/rooms_state_test.go +++ b/tests/csapi/rooms_state_test.go @@ -21,7 +21,7 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) { userID := "@alice:hs1" alice := deployment.Client(t, "hs1", userID) bob := deployment.RegisterUser(t, "hs1", "bob", "bobpassword", false) - roomID := alice.CreateRoom(t, struct{}{}) + roomID := alice.MustCreateRoom(t, struct{}{}) t.Run("parallel", func(t *testing.T) { // sytest: Room creation reports m.room.create to myself @@ -104,7 +104,7 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) { t.Run("Joining room twice is idempotent", func(t *testing.T) { t.Parallel() - roomID := bob.CreateRoom(t, map[string]interface{}{ + roomID := bob.MustCreateRoom(t, map[string]interface{}{ "visibility": "public", "preset": "public_chat", }) diff --git a/tests/csapi/sync_archive_test.go b/tests/csapi/sync_archive_test.go index 7621ba8b..633272e6 100644 --- a/tests/csapi/sync_archive_test.go +++ b/tests/csapi/sync_archive_test.go @@ -25,7 +25,7 @@ func TestSyncLeaveSection(t *testing.T) { }, }) - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) @@ -44,7 +44,7 @@ func TestSyncLeaveSection(t *testing.T) { }) incrementalSince := s(client.SyncReq{}) - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) // sytest: Left rooms appear in the leave section of sync t.Run("Left rooms appear in the leave section of sync", func(t *testing.T) { @@ -89,15 +89,15 @@ func TestGappedSyncLeaveSection(t *testing.T) { }, }) - roomToLeave := alice.CreateRoom(t, map[string]interface{}{}) + roomToLeave := alice.MustCreateRoom(t, map[string]interface{}{}) // j0j0: The original sytest creates an additional room to send events into, // my only suspicion as to why is to trigger a gapped-sync bug, // to see if it "skips" over the leave event. - roomToSpam := alice.CreateRoom(t, map[string]interface{}{}) + roomToSpam := alice.MustCreateRoom(t, map[string]interface{}{}) _, sinceToken := alice.MustSync(t, client.SyncReq{Filter: gappyFilter, TimeoutMillis: "0"}) - alice.LeaveRoom(t, roomToLeave) + alice.MustLeaveRoom(t, roomToLeave) for i := 0; i < 20; i++ { alice.SendEventSynced(t, roomToSpam, b.Event{ @@ -144,7 +144,7 @@ func TestArchivedRoomsHistory(t *testing.T) { //aliceFilter := createFilter(t, alice, filter) bobFilter := createFilter(t, bob, filter) - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -169,7 +169,7 @@ func TestArchivedRoomsHistory(t *testing.T) { }, }) - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID)) alice.SendEventSynced(t, roomID, b.Event{ @@ -248,10 +248,10 @@ func TestOlderLeftRoomsNotInLeaveSection(t *testing.T) { }, }) - roomToLeave := alice.CreateRoom(t, map[string]string{ + roomToLeave := alice.MustCreateRoom(t, map[string]string{ "preset": "public_chat", }) - roomToSpam := alice.CreateRoom(t, map[string]string{ + roomToSpam := alice.MustCreateRoom(t, map[string]string{ "preset": "public_chat", }) @@ -266,7 +266,7 @@ func TestOlderLeftRoomsNotInLeaveSection(t *testing.T) { _, aliceSince := alice.MustSync(t, client.SyncReq{Filter: aliceFilter, TimeoutMillis: "0"}) - alice.LeaveRoom(t, roomToLeave) + alice.MustLeaveRoom(t, roomToLeave) aliceSince = alice.MustSyncUntil(t, client.SyncReq{Filter: aliceFilter, Since: aliceSince}, client.SyncLeftFrom(alice.UserID, roomToLeave)) @@ -327,7 +327,7 @@ func TestLeaveEventVisibility(t *testing.T) { }, }) - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "initial_state": []map[string]interface{}{ { "content": map[string]interface{}{ @@ -348,7 +348,7 @@ func TestLeaveEventVisibility(t *testing.T) { client.SyncJoinedTo(bob.UserID, roomID), ) - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(alice.UserID, roomID)) syncRes, _ := alice.MustSync(t, client.SyncReq{Filter: aliceFilter, Since: aliceSince, TimeoutMillis: "0"}) @@ -410,7 +410,7 @@ func TestLeaveEventInviteRejection(t *testing.T) { }, }) - roomID := bob.CreateRoom(t, map[string]interface{}{ + roomID := bob.MustCreateRoom(t, map[string]interface{}{ "initial_state": []map[string]interface{}{ { "content": map[string]interface{}{ @@ -424,7 +424,7 @@ func TestLeaveEventInviteRejection(t *testing.T) { _, aliceSince := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0", Filter: aliceFilter}) - bob.InviteRoom(t, roomID, alice.UserID) + bob.MustInviteRoom(t, roomID, alice.UserID) aliceSince = alice.MustSyncUntil( t, @@ -432,7 +432,7 @@ func TestLeaveEventInviteRejection(t *testing.T) { client.SyncInvitedTo(alice.UserID, roomID), ) - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) aliceSince = alice.MustSyncUntil( t, diff --git a/tests/csapi/sync_test.go b/tests/csapi/sync_test.go index 22f82fa3..57954e39 100644 --- a/tests/csapi/sync_test.go +++ b/tests/csapi/sync_test.go @@ -22,7 +22,7 @@ func TestCumulativeJoinLeaveJoinSync(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - roomID := bob.CreateRoom(t, map[string]interface{}{ + roomID := bob.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -38,7 +38,7 @@ func TestCumulativeJoinLeaveJoinSync(t *testing.T) { // The alternative would be to sleep, but that is not acceptable here. sinceJoin := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) sinceLeave := alice.MustSyncUntil(t, client.SyncReq{Since: sinceJoin}, client.SyncLeftFrom(alice.UserID, roomID)) @@ -60,7 +60,7 @@ func TestTentativeEventualJoiningAfterRejecting(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -70,12 +70,12 @@ func TestTentativeEventualJoiningAfterRejecting(t *testing.T) { // Get floating current next_batch _, since = alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) // This rejects the invite - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) // Full sync leaveExists := false @@ -121,7 +121,7 @@ func TestSync(t *testing.T) { // sytest: Can sync a joined room t.Run("Can sync a joined room", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, struct{}{}) + roomID := alice.MustCreateRoom(t, struct{}{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) res, nextBatch := alice.MustSync(t, client.SyncReq{Filter: filterID}) // check all required fields exist @@ -135,7 +135,7 @@ func TestSync(t *testing.T) { // sytest: Full state sync includes joined rooms t.Run("Full state sync includes joined rooms", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, struct{}{}) + roomID := alice.MustCreateRoom(t, struct{}{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) _, nextBatch := alice.MustSync(t, client.SyncReq{Filter: filterID}) @@ -146,7 +146,7 @@ func TestSync(t *testing.T) { t.Run("Newly joined room is included in an incremental sync", func(t *testing.T) { t.Parallel() _, nextBatch := alice.MustSync(t, client.SyncReq{Filter: filterID}) - roomID := alice.CreateRoom(t, struct{}{}) + roomID := alice.MustCreateRoom(t, struct{}{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) res, nextBatch := alice.MustSync(t, client.SyncReq{Filter: filterID, Since: nextBatch}) checkJoinFieldsExist(t, res, roomID) @@ -172,7 +172,7 @@ func TestSync(t *testing.T) { }, }) - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) sendMessages(t, alice, roomID, "alice message 1-", 4) @@ -203,7 +203,7 @@ func TestSync(t *testing.T) { // sytest: Newly joined room includes presence in incremental sync t.Run("Newly joined room includes presence in incremental sync", func(t *testing.T) { runtime.SkipIf(t, runtime.Dendrite) // FIXME: https://github.com/matrix-org/dendrite/issues/1324 - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) _, nextBatch := bob.MustSync(t, client.SyncReq{}) bob.MustJoinRoom(t, roomID, []string{}) @@ -223,7 +223,7 @@ func TestSync(t *testing.T) { // sytest: Get presence for newly joined members in incremental sync t.Run("Get presence for newly joined members in incremental sync", func(t *testing.T) { runtime.SkipIf(t, runtime.Dendrite) // FIXME: https://github.com/matrix-org/dendrite/issues/1324 - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) nextBatch := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) sendMessages(t, alice, roomID, "dummy message", 1) _, nextBatch = alice.MustSync(t, client.SyncReq{Since: nextBatch}) @@ -281,10 +281,10 @@ func TestSync(t *testing.T) { charlie := srv.UserID("charlie") - redactionRoomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + redactionRoomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) redactionRoom := srv.MustJoinRoom(t, deployment, "hs1", redactionRoomID, charlie) - sentinelRoomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + sentinelRoomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) sentinelRoom := srv.MustJoinRoom(t, deployment, "hs1", sentinelRoomID, charlie) // charlie creates a bogus redaction, which he sends out, followed by @@ -383,12 +383,12 @@ func TestPresenceSyncDifferentRooms(t *testing.T) { charlie := deployment.NewUser(t, "charlie", "hs1") // Alice creates two rooms: one with her and Bob, and a second with her and Charlie. - bobRoomID := alice.CreateRoom(t, struct{}{}) - charlieRoomID := alice.CreateRoom(t, struct{}{}) + bobRoomID := alice.MustCreateRoom(t, struct{}{}) + charlieRoomID := alice.MustCreateRoom(t, struct{}{}) nextBatch := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, bobRoomID), client.SyncJoinedTo(alice.UserID, charlieRoomID)) - alice.InviteRoom(t, bobRoomID, bob.UserID) - alice.InviteRoom(t, charlieRoomID, charlie.UserID) + alice.MustInviteRoom(t, bobRoomID, bob.UserID) + alice.MustInviteRoom(t, charlieRoomID, charlie.UserID) bob.MustJoinRoom(t, bobRoomID, nil) charlie.MustJoinRoom(t, charlieRoomID, nil) @@ -441,7 +441,7 @@ func TestRoomSummary(t *testing.T) { bob := deployment.Client(t, "hs1", "@bob:hs1") _, aliceSince := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "invite": []string{bob.UserID}, }) diff --git a/tests/csapi/thread_notifications_test.go b/tests/csapi/thread_notifications_test.go index f9e2a0a5..ef53bfb9 100644 --- a/tests/csapi/thread_notifications_test.go +++ b/tests/csapi/thread_notifications_test.go @@ -78,7 +78,7 @@ func TestThreadedReceipts(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustJoinRoom(t, roomID, nil) // A next batch token which is past the initial room creation. diff --git a/tests/csapi/txnid_test.go b/tests/csapi/txnid_test.go index 340a7fab..e581e45b 100644 --- a/tests/csapi/txnid_test.go +++ b/tests/csapi/txnid_test.go @@ -23,7 +23,7 @@ func TestTxnInEvent(t *testing.T) { c := deployment.RegisterUser(t, "hs1", "alice", "password", false) // Create a room where we can send events. - roomID := c.CreateRoom(t, map[string]interface{}{}) + roomID := c.MustCreateRoom(t, map[string]interface{}{}) txnId := "abcdefg" // Let's send an event, and wait for it to appear in the timeline. @@ -78,7 +78,7 @@ func TestTxnScopeOnLocalEcho(t *testing.T) { c1.UserID, c1.AccessToken, c1.DeviceID = c1.LoginUser(t, "alice", "password") // Create a room where we can send events. - roomID := c1.CreateRoom(t, map[string]interface{}{}) + roomID := c1.MustCreateRoom(t, map[string]interface{}{}) txnId := "abdefgh" // Let's send an event, and wait for it to appear in the timeline. @@ -117,7 +117,7 @@ func TestTxnIdempotencyScopedToDevice(t *testing.T) { c1.UserID, c1.AccessToken, c1.DeviceID = c1.LoginUser(t, "alice", "password") // Create a room where we can send events. - roomID := c1.CreateRoom(t, map[string]interface{}{}) + roomID := c1.MustCreateRoom(t, map[string]interface{}{}) txnId := "abcdef" event := b.Event{ @@ -157,8 +157,8 @@ func TestTxnIdempotency(t *testing.T) { c1.UserID, c1.AccessToken, c1.DeviceID = c1.LoginUser(t, "alice", "password") // Create a room where we can send events. - roomID1 := c1.CreateRoom(t, map[string]interface{}{}) - roomID2 := c1.CreateRoom(t, map[string]interface{}{}) + roomID1 := c1.MustCreateRoom(t, map[string]interface{}{}) + roomID2 := c1.MustCreateRoom(t, map[string]interface{}{}) // choose a transaction ID txnId := "abc" @@ -213,7 +213,7 @@ func TestTxnIdWithRefreshToken(t *testing.T) { c.UserID, c.AccessToken, refreshToken, c.DeviceID, _ = c.LoginUserWithRefreshToken(t, "alice", "password") // Create a room where we can send events. - roomID := c.CreateRoom(t, map[string]interface{}{}) + roomID := c.MustCreateRoom(t, map[string]interface{}{}) txnId := "abcdef" // We send an event diff --git a/tests/csapi/user_directory_display_names_test.go b/tests/csapi/user_directory_display_names_test.go index 374614b9..14bb5b59 100644 --- a/tests/csapi/user_directory_display_names_test.go +++ b/tests/csapi/user_directory_display_names_test.go @@ -60,7 +60,7 @@ func setupUsers(t *testing.T) (*client.CSAPI, *client.CSAPI, *client.CSAPI, func ) // Alice creates a public room (so when Eve searches, she can see that Alice exists) - alice.CreateRoom(t, map[string]interface{}{"visibility": "public"}) + alice.MustCreateRoom(t, map[string]interface{}{"visibility": "public"}) return alice, bob, eve, cleanup } @@ -135,7 +135,7 @@ func TestRoomSpecificUsernameChange(t *testing.T) { defer cleanup(t) // Bob creates a new room and invites Alice. - privateRoom := bob.CreateRoom(t, map[string]interface{}{ + privateRoom := bob.MustCreateRoom(t, map[string]interface{}{ "visibility": "private", "invite": []string{alice.UserID}, }) @@ -163,7 +163,7 @@ func TestRoomSpecificUsernameAtJoin(t *testing.T) { defer cleanup(t) // Bob creates a new room and invites Alice. - privateRoom := bob.CreateRoom(t, map[string]interface{}{ + privateRoom := bob.MustCreateRoom(t, map[string]interface{}{ "visibility": "private", "invite": []string{alice.UserID}, }) diff --git a/tests/direct_messaging_test.go b/tests/direct_messaging_test.go index 2693accb..91adf7b2 100644 --- a/tests/direct_messaging_test.go +++ b/tests/direct_messaging_test.go @@ -30,7 +30,7 @@ func TestWriteMDirectAccountData(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "invite": []string{bob.UserID}, "is_direct": true, }) @@ -48,7 +48,7 @@ func TestWriteMDirectAccountData(t *testing.T) { t.Logf("%s: global account data set; syncing until it arrives", time.Now()) // synapse#13334 since := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncGlobalAccountDataHas(checkAccountData)) // now update the DM room and test that incremental syncing also pushes new account data - roomID = alice.CreateRoom(t, map[string]interface{}{ + roomID = alice.MustCreateRoom(t, map[string]interface{}{ "invite": []string{bob.UserID}, "is_direct": true, }) @@ -74,7 +74,7 @@ func TestIsDirectFlagLocal(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "invite": []string{bob.UserID}, "is_direct": true, }) diff --git a/tests/federation_acl_test.go b/tests/federation_acl_test.go index 3ffa3f43..bcca7bf8 100644 --- a/tests/federation_acl_test.go +++ b/tests/federation_acl_test.go @@ -53,7 +53,7 @@ func TestACLs(t *testing.T) { charlie := deployment.Client(t, "hs3", "@charlie:hs3") // 2. Create room on 1st server - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) aliceSince := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) // 3. Join this room from 2nd server @@ -62,7 +62,7 @@ func TestACLs(t *testing.T) { bobSince := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // create a different room used for a sentinel event - sentinelRoom := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + sentinelRoom := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) aliceSince = alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncJoinedTo(alice.UserID, sentinelRoom)) bob.MustJoinRoom(t, sentinelRoom, []string{"hs1"}) charlie.MustJoinRoom(t, sentinelRoom, []string{"hs1"}) diff --git a/tests/federation_event_auth_test.go b/tests/federation_event_auth_test.go index 6404cadb..6bd7ae74 100644 --- a/tests/federation_event_auth_test.go +++ b/tests/federation_event_auth_test.go @@ -55,7 +55,7 @@ func TestEventAuth(t *testing.T) { // make a room and join it charlie := srv.UserID("charlie") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) room := srv.MustJoinRoom(t, deployment, "hs1", roomID, charlie) diff --git a/tests/federation_room_alias_test.go b/tests/federation_room_alias_test.go index 6ad1e63b..62d4a05d 100644 --- a/tests/federation_room_alias_test.go +++ b/tests/federation_room_alias_test.go @@ -19,7 +19,7 @@ func TestRemoteAliasRequestsUnderstandUnicode(t *testing.T) { const unicodeAlias = "#老虎£я🤨👉ඞ:hs1" - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) alice.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "directory", "room", unicodeAlias}, client.WithJSONBody(t, map[string]interface{}{ "room_id": roomID, diff --git a/tests/federation_room_ban_test.go b/tests/federation_room_ban_test.go index 53e9e5b4..c6b5e2b7 100644 --- a/tests/federation_room_ban_test.go +++ b/tests/federation_room_ban_test.go @@ -17,7 +17,7 @@ func TestUnbanViaInvite(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs2", "@bob:hs2") - roomID := bob.CreateRoom(t, map[string]interface{}{ + roomID := bob.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) alice.MustJoinRoom(t, roomID, []string{"hs2"}) @@ -35,7 +35,7 @@ func TestUnbanViaInvite(t *testing.T) { bob.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(alice.UserID, roomID)) // Re-invite Alice - bob.InviteRoom(t, roomID, alice.UserID) + bob.MustInviteRoom(t, roomID, alice.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(alice.UserID, roomID)) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(alice.UserID, roomID)) diff --git a/tests/federation_room_event_auth_test.go b/tests/federation_room_event_auth_test.go index 923a53fe..7999c9ff 100644 --- a/tests/federation_room_event_auth_test.go +++ b/tests/federation_room_event_auth_test.go @@ -108,7 +108,7 @@ func TestInboundFederationRejectsEventsWithRejectedAuthEvents(t *testing.T) { // have Alice create a room, and then join it alice := deployment.Client(t, "hs1", "@alice:hs1") - testRoomID := alice.CreateRoom(t, struct { + testRoomID := alice.MustCreateRoom(t, struct { Preset string `json:"preset"` }{ "public_chat", diff --git a/tests/federation_room_get_missing_events_test.go b/tests/federation_room_get_missing_events_test.go index 60e4db0a..a1d2cdd4 100644 --- a/tests/federation_room_get_missing_events_test.go +++ b/tests/federation_room_get_missing_events_test.go @@ -62,7 +62,7 @@ func TestGetMissingEventsGapFilling(t *testing.T) { bob := srv.UserID("bob") // 1) Create a room between the HS and Complement. - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) srvRoom := srv.MustJoinRoom(t, deployment, "hs1", roomID, bob) @@ -352,7 +352,7 @@ func TestInboundCanReturnMissingEvents(t *testing.T) { } { // sytest: Inbound federation can return missing events for $vis visibility t.Run(fmt.Sprintf("Inbound federation can return missing events for %s visibility", visibility), func(t *testing.T) { - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "version": roomVersion, }) diff --git a/tests/federation_room_invite_test.go b/tests/federation_room_invite_test.go index a08152c0..03e2e195 100644 --- a/tests/federation_room_invite_test.go +++ b/tests/federation_room_invite_test.go @@ -43,18 +43,18 @@ func TestFederationRejectInvite(t *testing.T) { delia := srv.UserID("delia") // Alice creates the room, and delia joins - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) room := srv.MustJoinRoom(t, deployment, "hs1", roomID, delia) // Alice invites Charlie; Delia should see the invite waiter = NewWaiter() - alice.InviteRoom(t, roomID, charlie.UserID) + alice.MustInviteRoom(t, roomID, charlie.UserID) waiter.Wait(t, 5*time.Second) room.MustHaveMembershipForUser(t, charlie.UserID, "invite") // Charlie rejects the invite; Delia should see the rejection. waiter = NewWaiter() - charlie.LeaveRoom(t, roomID) + charlie.MustLeaveRoom(t, roomID) waiter.Wait(t, 5*time.Second) room.MustHaveMembershipForUser(t, charlie.UserID, "leave") } diff --git a/tests/federation_room_join_partial_state_test.go b/tests/federation_room_join_partial_state_test.go index ae8eafbf..4f8b745c 100644 --- a/tests/federation_room_join_partial_state_test.go +++ b/tests/federation_room_join_partial_state_test.go @@ -1216,7 +1216,7 @@ func TestPartialStateJoin(t *testing.T) { charlie := deployment.Client(t, "hs2", "@charlie:hs2") // create a public room - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -2373,7 +2373,7 @@ func TestPartialStateJoin(t *testing.T) { elsie := server2.UserID("elsie") // @alice:hs1 creates a public room. - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) // @elsie:server2 joins the room. server2Room := server2.MustJoinRoom(t, deployment, "hs1", roomID, elsie) @@ -2395,7 +2395,7 @@ func TestPartialStateJoin(t *testing.T) { leaveSharedRoom = func() { server2.WithWaitForLeave(t, server2Room, alice.UserID, func() { - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) }) } @@ -2902,7 +2902,7 @@ func TestPartialStateJoin(t *testing.T) { sendDeviceListUpdate("charlie") // @alice:hs1 creates a public room. - otherRoomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + otherRoomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) // @charlie joins the room. // Now @charlie's device list is definitely being tracked. @@ -2914,7 +2914,7 @@ func TestPartialStateJoin(t *testing.T) { }, client.SyncJoinedTo(server.UserID("charlie"), otherRoomID), ) - defer server.WithWaitForLeave(t, otherRoom, alice.UserID, func() { alice.LeaveRoom(t, otherRoomID) }) + defer server.WithWaitForLeave(t, otherRoom, alice.UserID, func() { alice.MustLeaveRoom(t, otherRoomID) }) // Depending on the homeserver implementation, @t31alice:hs1 must have been told that either: // * charlie updated their device list, or @@ -3047,7 +3047,7 @@ func TestPartialStateJoin(t *testing.T) { mustQueryKeysWithoutFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie")) // alice aborts her join before the resync completes - alice.LeaveRoom(t, room.RoomID) + alice.MustLeaveRoom(t, room.RoomID) // hs1 should no longer be tracking elsie's device list; subsequent // key requests from alice require a federation request. @@ -3330,7 +3330,7 @@ func TestPartialStateJoin(t *testing.T) { mustQueryKeysWithoutFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie")) // @t39alice:hs1 creates a public room. - otherRoomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + otherRoomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) // @elsie joins the room. // The homeserver under test is now subscribed to @elsie's device list updates. @@ -3553,7 +3553,7 @@ func TestPartialStateJoin(t *testing.T) { t.Log("Alice starts a leave request") server.AddPDUHandler(func(e gomatrixserverlib.PDU) bool { return true }) go func() { - alice.LeaveRoom(t, serverRoom.RoomID) + alice.MustLeaveRoom(t, serverRoom.RoomID) t.Log("Alice's leave request completed") leaveCompleted.Finish() }() @@ -3611,7 +3611,7 @@ func TestPartialStateJoin(t *testing.T) { return true }, ) - alice.LeaveRoom(t, serverRoom.RoomID) + alice.MustLeaveRoom(t, serverRoom.RoomID) aliceNextBatch = alice.MustSyncUntil( t, client.SyncReq{Since: aliceNextBatch, Filter: buildLazyLoadingSyncFilter(nil)}, @@ -3664,7 +3664,7 @@ func TestPartialStateJoin(t *testing.T) { t.Log("Alice leaves the room") server.AddPDUHandler(func(e gomatrixserverlib.PDU) bool { return true }) - alice.LeaveRoom(t, serverRoom.RoomID) + alice.MustLeaveRoom(t, serverRoom.RoomID) t.Log("Alice sees Alice's leave") aliceNextBatch = alice.MustSyncUntil( @@ -3701,7 +3701,7 @@ func TestPartialStateJoin(t *testing.T) { t.Log("Alice leaves the room") server.AddPDUHandler(func(e gomatrixserverlib.PDU) bool { return true }) - alice.LeaveRoom(t, serverRoom.RoomID) + alice.MustLeaveRoom(t, serverRoom.RoomID) t.Log("Alice sees Alice's leave") aliceNextBatch = alice.MustSyncUntil( @@ -3745,7 +3745,7 @@ func TestPartialStateJoin(t *testing.T) { t.Log("Alice leaves the room") server.AddPDUHandler(func(e gomatrixserverlib.PDU) bool { return true }) - alice.LeaveRoom(t, serverRoom.RoomID) + alice.MustLeaveRoom(t, serverRoom.RoomID) t.Log("Alice sees Alice's leave") aliceNextBatch = alice.MustSyncUntil( @@ -4314,7 +4314,7 @@ func (psj *partialStateJoinResult) Destroy(t *testing.T) { t, psj.ServerRoom, psj.User.UserID, - func() { psj.User.LeaveRoom(t, psj.ServerRoom.RoomID) }, + func() { psj.User.MustLeaveRoom(t, psj.ServerRoom.RoomID) }, ) } diff --git a/tests/federation_room_join_test.go b/tests/federation_room_join_test.go index 27e7217c..c2524089 100644 --- a/tests/federation_room_join_test.go +++ b/tests/federation_room_join_test.go @@ -112,7 +112,7 @@ func TestJoinFederatedRoomFailOver(t *testing.T) { }`)) })).Methods("GET") - roomID := bob.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := bob.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) t.Logf("%s created room %s.", bob.UserID, roomID) t.Logf("%s joins the room via {complement,hs2}.", alice.UserID) @@ -316,7 +316,7 @@ func TestBannedUserCannotSendJoin(t *testing.T) { // alice creates a room, and bans charlie from it. alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -410,7 +410,7 @@ func testValidationForSendMembershipEndpoint(t *testing.T, baseApiPath, expected // alice creates a room, and charlie joins it alice := deployment.Client(t, "hs1", "@alice:hs1") - roomId := alice.CreateRoom(t, createRoomOpts) + roomId := alice.MustCreateRoom(t, createRoomOpts) charlie := srv.UserID("charlie") room := srv.MustJoinRoom(t, deployment, "hs1", roomId, charlie) @@ -519,7 +519,7 @@ func TestSendJoinPartialStateResponse(t *testing.T) { // alice creates a room, which bob joins alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustJoinRoom(t, roomID, nil) // now we send a make_join... @@ -603,7 +603,7 @@ func TestJoinFederatedRoomFromApplicationServiceBridgeUser(t *testing.T) { t.Run("join remote federated room as application service user", func(t *testing.T) { //t.Parallel() // Create the room from a remote homeserver - roomID := remoteCharlie.CreateRoom(t, map[string]interface{}{ + roomID := remoteCharlie.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "hs2 room", }) diff --git a/tests/federation_room_typing_test.go b/tests/federation_room_typing_test.go index 81b9696b..99777ec2 100644 --- a/tests/federation_room_typing_test.go +++ b/tests/federation_room_typing_test.go @@ -16,7 +16,7 @@ func TestRemoteTyping(t *testing.T) { bob := deployment.Client(t, "hs1", "@bob:hs1") charlie := deployment.Client(t, "hs2", "@charlie:hs2") - roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustJoinRoom(t, roomID, nil) charlie.MustJoinRoom(t, roomID, []string{"hs1"}) diff --git a/tests/federation_rooms_invite_test.go b/tests/federation_rooms_invite_test.go index 697d1c5c..7f006622 100644 --- a/tests/federation_rooms_invite_test.go +++ b/tests/federation_rooms_invite_test.go @@ -23,25 +23,25 @@ func TestFederationRoomsInvite(t *testing.T) { // sytest: Invited user can reject invite over federation t.Run("Invited user can reject invite over federation", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", "invite": []string{bob.UserID}, }) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID)) }) // sytest: Invited user can reject invite over federation several times t.Run("Invited user can reject invite over federation several times", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) for i := 0; i < 3; i++ { - alice.InviteRoom(t, roomID, bob.UserID) + alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID)) } }) @@ -49,22 +49,22 @@ func TestFederationRoomsInvite(t *testing.T) { // sytest: Invited user can reject invite over federation for empty room t.Run("Invited user can reject invite over federation for empty room", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", "invite": []string{bob.UserID}, }) aliceSince := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) bobSince := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - alice.LeaveRoom(t, roomID) + alice.MustLeaveRoom(t, roomID) alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncLeftFrom(alice.UserID, roomID)) - bob.LeaveRoom(t, roomID) + bob.MustLeaveRoom(t, roomID) bob.MustSyncUntil(t, client.SyncReq{Since: bobSince}, client.SyncLeftFrom(bob.UserID, roomID)) }) // sytest: Remote invited user can see room metadata t.Run("Remote invited user can see room metadata", func(t *testing.T) { t.Parallel() - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", "name": "Invites room", "invite": []string{bob.UserID}, @@ -85,7 +85,7 @@ func TestFederationRoomsInvite(t *testing.T) { }) t.Run("Invited user has 'is_direct' flag in prev_content after joining", func(t *testing.T) { - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", "name": "Invites room", // invite Bob and make the room a DM, so we can verify m.direct flag is in the prev_content after joining diff --git a/tests/knocking_test.go b/tests/knocking_test.go index 372cdc60..ce4c26c4 100644 --- a/tests/knocking_test.go +++ b/tests/knocking_test.go @@ -68,14 +68,14 @@ func doTestKnocking(t *testing.T, roomVersion string, joinRule string) { david := srv.UserID("david") // Create a room for alice and bob to test knocking with - roomIDOne := alice.CreateRoom(t, struct { + roomIDOne := alice.MustCreateRoom(t, struct { Preset string `json:"preset"` RoomVersion string `json:"room_version"` }{ "private_chat", // Set to private in order to get an invite-only room roomVersion, }) - alice.InviteRoom(t, roomIDOne, david) + alice.MustInviteRoom(t, roomIDOne, david) inviteWaiter.Wait(t, 5*time.Second) serverRoomOne := srv.MustJoinRoom(t, deployment, "hs1", roomIDOne, david) @@ -83,7 +83,7 @@ func doTestKnocking(t *testing.T, roomVersion string, joinRule string) { knockingBetweenTwoUsersTest(t, roomIDOne, alice, bob, serverRoomOne, false, joinRule) // Create a room for alice and charlie to test knocking with - roomIDTwo := alice.CreateRoom(t, struct { + roomIDTwo := alice.MustCreateRoom(t, struct { Preset string `json:"preset"` RoomVersion string `json:"room_version"` }{ @@ -91,7 +91,7 @@ func doTestKnocking(t *testing.T, roomVersion string, joinRule string) { roomVersion, }) inviteWaiter = NewWaiter() - alice.InviteRoom(t, roomIDTwo, david) + alice.MustInviteRoom(t, roomIDTwo, david) inviteWaiter.Wait(t, 5*time.Second) serverRoomTwo := srv.MustJoinRoom(t, deployment, "hs1", roomIDTwo, david) @@ -379,7 +379,7 @@ func doTestKnockRoomsInPublicRoomsDirectory(t *testing.T, roomVersion string, jo alice := deployment.Client(t, "hs1", aliceUserID) // Create an invite-only room with the knock room version - roomID := alice.CreateRoom(t, struct { + roomID := alice.MustCreateRoom(t, struct { Preset string `json:"preset"` RoomVersion string `json:"room_version"` }{ @@ -402,7 +402,7 @@ func doTestKnockRoomsInPublicRoomsDirectory(t *testing.T, roomVersion string, jo publishAndCheckRoomJoinRule(t, alice, roomID, joinRule) // Create a public room - roomID = alice.CreateRoom(t, struct { + roomID = alice.MustCreateRoom(t, struct { Preset string `json:"preset"` }{ "public_chat", // Set to public in order to get a public room diff --git a/tests/msc2836_test.go b/tests/msc2836_test.go index de3d237c..77300e1a 100644 --- a/tests/msc2836_test.go +++ b/tests/msc2836_test.go @@ -46,7 +46,7 @@ func TestEventRelationships(t *testing.T) { // Create the room and send events A,B,C,D alice := deployment.Client(t, "hs1", "@alice:hs1") - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) eventA := alice.SendEventSynced(t, roomID, b.Event{ diff --git a/tests/msc3391_test.go b/tests/msc3391_test.go index 86754120..01ad488e 100644 --- a/tests/msc3391_test.go +++ b/tests/msc3391_test.go @@ -32,7 +32,7 @@ func TestRemovingAccountData(t *testing.T) { alice := deployment.Client(t, "hs1", aliceUserID) // And create a room with that user where we can store some room account data - roomID := alice.CreateRoom(t, map[string]interface{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) // Test deleting global account data. t.Run("Deleting a user's account data via DELETE works", func(t *testing.T) { diff --git a/tests/restricted_room_hierarchy_test.go b/tests/restricted_room_hierarchy_test.go index 95e4b603..ee23d1a4 100644 --- a/tests/restricted_room_hierarchy_test.go +++ b/tests/restricted_room_hierarchy_test.go @@ -40,7 +40,7 @@ func TestRestrictedRoomsSpacesSummaryLocal(t *testing.T) { // Create the rooms alice := deployment.Client(t, "hs1", "@alice:hs1") - space := alice.CreateRoom(t, map[string]interface{}{ + space := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Space", "creation_content": map[string]interface{}{ @@ -58,7 +58,7 @@ func TestRestrictedRoomsSpacesSummaryLocal(t *testing.T) { }, }) // The room is room version 8 which supports the restricted join_rule. - room := alice.CreateRoom(t, map[string]interface{}{ + room := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Room", "room_version": "8", @@ -122,7 +122,7 @@ func TestRestrictedRoomsSpacesSummaryFederation(t *testing.T) { // Create the rooms alice := deployment.Client(t, "hs1", "@alice:hs1") bob := deployment.Client(t, "hs1", "@bob:hs1") - space := alice.CreateRoom(t, map[string]interface{}{ + space := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Space", "creation_content": map[string]interface{}{ @@ -142,7 +142,7 @@ func TestRestrictedRoomsSpacesSummaryFederation(t *testing.T) { // The room is room version 8 which supports the restricted join_rule and is // created on hs2. charlie := deployment.Client(t, "hs2", "@charlie:hs2") - room := charlie.CreateRoom(t, map[string]interface{}{ + room := charlie.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Room", "room_version": "8", diff --git a/tests/restricted_rooms_test.go b/tests/restricted_rooms_test.go index 0e0ab661..6e94e98f 100644 --- a/tests/restricted_rooms_test.go +++ b/tests/restricted_rooms_test.go @@ -23,12 +23,12 @@ func setupRestrictedRoom(t *testing.T, deployment *docker.Deployment, roomVersio alice := deployment.Client(t, "hs1", "@alice:hs1") // The room which membership checks are delegated to. In practice, this will // often be an MSC1772 space, but that is not required. - allowed_room := alice.CreateRoom(t, map[string]interface{}{ + allowed_room := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Allowed Room", }) // The room is room version 8 which supports the restricted join_rule. - room := alice.CreateRoom(t, map[string]interface{}{ + room := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Room", "room_version": roomVersion, @@ -107,8 +107,8 @@ func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, a t.Run("Join should fail when left allowed room", func(t *testing.T) { // Leaving the room works and the user is unable to re-join. - bob.LeaveRoom(t, room) - bob.LeaveRoom(t, allowed_room) + bob.MustLeaveRoom(t, room) + bob.MustLeaveRoom(t, allowed_room) // Wait until Alice sees Bob leave the allowed room. This ensures that Alice's HS // has processed the leave before Bob tries rejoining, so that it rejects his @@ -128,11 +128,11 @@ func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, a t.Run("Join should succeed when invited", func(t *testing.T) { // Invite the user and joining should work. - alice.InviteRoom(t, room, bob.UserID) + alice.MustInviteRoom(t, room, bob.UserID) bob.JoinRoom(t, room, []string{"hs1"}) // Leave the room again, and join the allowed room. - bob.LeaveRoom(t, room) + bob.MustLeaveRoom(t, room) bob.JoinRoom(t, allowed_room, []string{"hs1"}) }) @@ -221,12 +221,12 @@ func doTestRestrictedRoomsRemoteJoinLocalUser(t *testing.T, roomVersion string, // This is the room which membership checks are delegated to. In practice, // this will often be an MSC1772 space, but that is not required. charlie := deployment.Client(t, "hs2", "@charlie:hs2") - allowed_room := charlie.CreateRoom(t, map[string]interface{}{ + allowed_room := charlie.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Space", }) // The room is room version 8 which supports the restricted join_rule. - room := charlie.CreateRoom(t, map[string]interface{}{ + room := charlie.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Room", "room_version": roomVersion, @@ -250,7 +250,7 @@ func doTestRestrictedRoomsRemoteJoinLocalUser(t *testing.T, roomVersion string, // Invite alice manually and accept it. alice := deployment.Client(t, "hs1", "@alice:hs1") - charlie.InviteRoom(t, room, alice.UserID) + charlie.MustInviteRoom(t, room, alice.UserID) alice.JoinRoom(t, room, []string{"hs2"}) // Confirm that Alice cannot issue invites (due to the default power levels). @@ -305,7 +305,7 @@ func doTestRestrictedRoomsRemoteJoinLocalUser(t *testing.T, roomVersion string, }, }, }) - charlie.LeaveRoom(t, room) + charlie.MustLeaveRoom(t, room) // Ensure the events have synced to hs1. alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas( @@ -322,7 +322,7 @@ func doTestRestrictedRoomsRemoteJoinLocalUser(t *testing.T, roomVersion string, // Have bob leave and rejoin. This should still work even though hs2 isn't in // the room anymore! - bob.LeaveRoom(t, room) + bob.MustLeaveRoom(t, room) bob.JoinRoom(t, room, []string{"hs1"}) } @@ -446,7 +446,7 @@ func doTestRestrictedRoomsRemoteJoinFailOver(t *testing.T, roomVersion string, j // Charlie leaves the room (so they can rejoin). t.Logf("%s leaves the restricted room.", charlie.UserID) - charlie.LeaveRoom(t, room) + charlie.MustLeaveRoom(t, room) // Ensure the events have synced to hs1 and hs2, otherwise the joins below may // happen before the leaves, from the perspective of hs1 and hs2. @@ -456,7 +456,7 @@ func doTestRestrictedRoomsRemoteJoinFailOver(t *testing.T, roomVersion string, j // Bob leaves the allowed room so that hs2 doesn't know if Charlie is in the // allowed room or not. t.Logf("%s leaves the authorizing room.", bob.UserID) - bob.LeaveRoom(t, allowed_room) + bob.MustLeaveRoom(t, allowed_room) // hs2 cannot complete the join since they do not know if Charlie meets the // requirements (since it is no longer in the allowed room). diff --git a/tests/room_hierarchy_test.go b/tests/room_hierarchy_test.go index c6a8a2f3..8e395d8a 100644 --- a/tests/room_hierarchy_test.go +++ b/tests/room_hierarchy_test.go @@ -85,7 +85,7 @@ func TestClientSpacesSummary(t *testing.T) { // create the rooms alice := deployment.Client(t, "hs1", "@alice:hs1") - root := alice.CreateRoom(t, map[string]interface{}{ + root := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Root", "creation_content": map[string]interface{}{ @@ -93,12 +93,12 @@ func TestClientSpacesSummary(t *testing.T) { }, }) roomNames[root] = "Root" - r1 := alice.CreateRoom(t, map[string]interface{}{ + r1 := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "R1", }) roomNames[r1] = "R1" - ss1 := alice.CreateRoom(t, map[string]interface{}{ + ss1 := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Sub-Space 1", "topic": "Some topic for sub-space 1", @@ -107,12 +107,12 @@ func TestClientSpacesSummary(t *testing.T) { }, }) roomNames[ss1] = "Sub-Space 1" - r2 := alice.CreateRoom(t, map[string]interface{}{ + r2 := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "R2", }) roomNames[r2] = "R2" - ss2 := alice.CreateRoom(t, map[string]interface{}{ + ss2 := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "SS2", "creation_content": map[string]interface{}{ @@ -120,14 +120,14 @@ func TestClientSpacesSummary(t *testing.T) { }, }) roomNames[ss2] = "SS2" - r3 := alice.CreateRoom(t, map[string]interface{}{ + r3 := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "R3", }) roomNames[r3] = "R3" // alice is not joined to R4 bob := deployment.Client(t, "hs1", "@bob:hs1") - r4 := bob.CreateRoom(t, map[string]interface{}{ + r4 := bob.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "R4", "initial_state": []map[string]interface{}{ @@ -141,7 +141,7 @@ func TestClientSpacesSummary(t *testing.T) { }, }) roomNames[r4] = "R4" - r5 := bob.CreateRoom(t, map[string]interface{}{ + r5 := bob.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "R5", }) @@ -390,25 +390,25 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { // create the rooms alice := deployment.Client(t, "hs1", "@alice:hs1") - root := alice.CreateRoom(t, map[string]interface{}{ + root := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Root", "creation_content": map[string]interface{}{ "type": "m.space", }, }) - r1 := alice.CreateRoom(t, map[string]interface{}{ + r1 := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", "name": "R1", }) - ss1 := alice.CreateRoom(t, map[string]interface{}{ + ss1 := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", "name": "Sub-Space 1", "creation_content": map[string]interface{}{ "type": "m.space", }, }) - r2 := alice.CreateRoom(t, map[string]interface{}{ + r2 := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "R2", "initial_state": []map[string]interface{}{ @@ -421,7 +421,7 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { }, }, }) - r3 := alice.CreateRoom(t, map[string]interface{}{ + r3 := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", "name": "R3", }) @@ -479,8 +479,8 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { }) // Invite to R1 and R3, querying again should only show R1 (since SS1 is not visible). - alice.InviteRoom(t, r1, bob.UserID) - alice.InviteRoom(t, r3, bob.UserID) + alice.MustInviteRoom(t, r1, bob.UserID) + alice.MustInviteRoom(t, r3, bob.UserID) res = bob.MustDo(t, "GET", []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}) must.MatchResponse(t, res, match.HTTPResponse{ @@ -497,7 +497,7 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { }) // Invite to SS1 and it now appears, as well as the rooms under it. - alice.InviteRoom(t, ss1, bob.UserID) + alice.MustInviteRoom(t, ss1, bob.UserID) res = bob.MustDo(t, "GET", []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}) must.MatchResponse(t, res, match.HTTPResponse{ @@ -562,14 +562,14 @@ func TestFederatedClientSpaces(t *testing.T) { } // create the rooms alice := deployment.Client(t, "hs1", "@alice:hs1") - root := alice.CreateRoom(t, worldReadableSpace) - r1 := alice.CreateRoom(t, worldReadable) - ss1 := alice.CreateRoom(t, worldReadableSpace) - r4 := alice.CreateRoom(t, worldReadable) + root := alice.MustCreateRoom(t, worldReadableSpace) + r1 := alice.MustCreateRoom(t, worldReadable) + ss1 := alice.MustCreateRoom(t, worldReadableSpace) + r4 := alice.MustCreateRoom(t, worldReadable) bob := deployment.Client(t, "hs2", "@bob:hs2") - r2 := bob.CreateRoom(t, worldReadable) - ss2 := bob.CreateRoom(t, worldReadableSpace) - r3 := bob.CreateRoom(t, worldReadable) + r2 := bob.MustCreateRoom(t, worldReadable) + ss2 := bob.MustCreateRoom(t, worldReadableSpace) + r3 := bob.MustCreateRoom(t, worldReadable) // create the links rootToR1 := eventKey(root, r1, spaceChildEventType) diff --git a/tests/room_timestamp_to_event_test.go b/tests/room_timestamp_to_event_test.go index 67f445f0..0a10f2cc 100644 --- a/tests/room_timestamp_to_event_test.go +++ b/tests/room_timestamp_to_event_test.go @@ -110,7 +110,7 @@ func TestJumpToDateEndpoint(t *testing.T) { timeBeforeRoomCreation := time.Now() // Alice will create the private room - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) @@ -138,7 +138,7 @@ func TestJumpToDateEndpoint(t *testing.T) { timeBeforeRoomCreation := time.Now() // Alice will create the public room - roomID := alice.CreateRoom(t, map[string]interface{}{ + roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) @@ -251,7 +251,7 @@ func getTxnID(prefix string) (txnID string) { func createTestRoom(t *testing.T, c *client.CSAPI) (roomID string, eventA, eventB *eventTime) { t.Helper() - roomID = c.CreateRoom(t, map[string]interface{}{ + roomID = c.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) From 68d9d638156de994c4e7073fb2715feaaad1b24a Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 9 Oct 2023 15:11:16 +0100 Subject: [PATCH 4/9] Fix npe --- client/sync.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/sync.go b/client/sync.go index 36a186ce..6bf99393 100644 --- a/client/sync.go +++ b/client/sync.go @@ -151,7 +151,7 @@ func (c *CSAPI) MustSync(t TestLike, syncReq SyncReq) (gjson.Result, string) { // Perform a single /sync request with the given request options. To sync until something happens, // see `MustSyncUntil`. // -// Returns the HTTP response if the /sync request does not return 200 OK. +// Always returns the HTTP response, even on non-2xx. // Returns the top-level parsed /sync response JSON on 200 OK. func (c *CSAPI) Sync(t TestLike, syncReq SyncReq) (gjson.Result, *http.Response) { t.Helper() @@ -180,7 +180,7 @@ func (c *CSAPI) Sync(t TestLike, syncReq SyncReq) (gjson.Result, *http.Response) } body := ParseJSON(t, res) result := gjson.ParseBytes(body) - return result, nil + return result, res } // Check that the timeline for `roomID` has an event which passes the check function. From 9e8fede89c33f33d056544df606cb710c5d016e0 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 9 Oct 2023 15:46:50 +0100 Subject: [PATCH 5/9] Fix up bad refactor --- tests/restricted_rooms_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/restricted_rooms_test.go b/tests/restricted_rooms_test.go index 6e94e98f..072fd092 100644 --- a/tests/restricted_rooms_test.go +++ b/tests/restricted_rooms_test.go @@ -409,7 +409,7 @@ func doTestRestrictedRoomsRemoteJoinFailOver(t *testing.T, roomVersion string, j // hs2 doesn't have anyone to invite from, so the join fails. t.Logf("%s joins the restricted room via hs2, which is expected to fail.", charlie.UserID) - res := bob.JoinRoom(t, room, []string{"hs2"}) + res := charlie.JoinRoom(t, room, []string{"hs2"}) must.MatchFailure(t, res) // Including hs1 (and failing over to it) allows the join to succeed. @@ -461,7 +461,7 @@ func doTestRestrictedRoomsRemoteJoinFailOver(t *testing.T, roomVersion string, j // hs2 cannot complete the join since they do not know if Charlie meets the // requirements (since it is no longer in the allowed room). t.Logf("%s joins the restricted room via hs2, which is expected to fail.", charlie.UserID) - must.MatchFailure(t, bob.JoinRoom(t, room, []string{"hs2"})) + must.MatchFailure(t, charlie.JoinRoom(t, room, []string{"hs2"})) // Including hs1 (and failing over to it) allows the join to succeed. t.Logf("%s joins the restricted room via {hs2,hs1}.", charlie.UserID) From 015aa767ddb719117cec9ff59f7cfa01ec682919 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 9 Oct 2023 17:59:18 +0100 Subject: [PATCH 6/9] Use newer functions --- tests/csapi/admin_test.go | 4 +-- tests/csapi/apidoc_room_forget_test.go | 4 +-- tests/csapi/rooms_invite_test.go | 14 +++------ ...federation_room_join_partial_state_test.go | 4 +-- tests/federation_room_join_test.go | 12 ++----- tests/knocking_test.go | 31 ++----------------- tests/restricted_rooms_test.go | 10 +----- 7 files changed, 15 insertions(+), 64 deletions(-) diff --git a/tests/csapi/admin_test.go b/tests/csapi/admin_test.go index c779325d..349984e1 100644 --- a/tests/csapi/admin_test.go +++ b/tests/csapi/admin_test.go @@ -7,8 +7,8 @@ import ( "github.com/tidwall/gjson" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" ) @@ -55,7 +55,7 @@ func TestServerNotices(t *testing.T) { roomID = syncUntilInvite(t, alice) }) t.Run("Alice cannot reject the invite", func(t *testing.T) { - res := alice.Do(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "leave"}) + res := alice.LeaveRoom(t, roomID) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: http.StatusForbidden, JSON: []match.JSON{ diff --git a/tests/csapi/apidoc_room_forget_test.go b/tests/csapi/apidoc_room_forget_test.go index ba1df726..50518d9a 100644 --- a/tests/csapi/apidoc_room_forget_test.go +++ b/tests/csapi/apidoc_room_forget_test.go @@ -8,8 +8,8 @@ import ( "github.com/tidwall/gjson" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" ) @@ -199,7 +199,7 @@ func TestRoomForget(t *testing.T) { alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID)) bob.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "forget"}, client.WithJSONBody(t, struct{}{})) // Try to re-join - joinRes := bob.Do(t, "POST", []string{"_matrix", "client", "v3", "join", roomID}, client.WithJSONBody(t, struct{}{})) + joinRes := bob.JoinRoom(t, roomID, nil) must.MatchResponse(t, joinRes, match.HTTPResponse{ StatusCode: http.StatusForbidden, JSON: []match.JSON{ diff --git a/tests/csapi/rooms_invite_test.go b/tests/csapi/rooms_invite_test.go index 59156592..5194dc94 100644 --- a/tests/csapi/rooms_invite_test.go +++ b/tests/csapi/rooms_invite_test.go @@ -4,8 +4,8 @@ import ( "net/http" "testing" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" "github.com/tidwall/gjson" @@ -38,7 +38,7 @@ func TestRoomsInvite(t *testing.T) { roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) - res := bob.Do(t, "POST", []string{"_matrix", "client", "v3", "join", roomID}) + res := bob.JoinRoom(t, roomID, nil) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: http.StatusForbidden, }) @@ -85,10 +85,7 @@ func TestRoomsInvite(t *testing.T) { roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "private_chat", }) - body := client.WithJSONBody(t, map[string]interface{}{ - "user_id": alice.UserID, - }) - res := alice.Do(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "invite"}, body) + res := alice.InviteRoom(t, roomID, alice.UserID) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: http.StatusForbidden, }) @@ -106,10 +103,7 @@ func TestRoomsInvite(t *testing.T) { bob.MustJoinRoom(t, roomID, []string{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) - body := client.WithJSONBody(t, map[string]interface{}{ - "user_id": bob.UserID, - }) - res := alice.Do(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "invite"}, body) + res := alice.InviteRoom(t, roomID, bob.UserID) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: http.StatusForbidden, }) diff --git a/tests/federation_room_join_partial_state_test.go b/tests/federation_room_join_partial_state_test.go index 9f6fa87b..5a94c831 100644 --- a/tests/federation_room_join_partial_state_test.go +++ b/tests/federation_room_join_partial_state_test.go @@ -3865,9 +3865,7 @@ func TestPartialStateJoin(t *testing.T) { ) t.Log("Alice tries to rejoin...") - queryParams := url.Values{} - queryParams.Add("server_name", server.ServerName()) - response := alice.Do(t, "POST", []string{"_matrix", "client", "v3", "join", serverRoom.RoomID}, client.WithQueries(queryParams)) + response := alice.JoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) t.Log("... but Alice was forbidden from rejoining") must.MatchResponse(t, response, match.HTTPResponse{StatusCode: http.StatusForbidden}) diff --git a/tests/federation_room_join_test.go b/tests/federation_room_join_test.go index c2524089..6ff6644c 100644 --- a/tests/federation_room_join_test.go +++ b/tests/federation_room_join_test.go @@ -78,16 +78,8 @@ func TestJoinViaRoomIDAndServerName(t *testing.T) { // join the room using ?server_name on HS2 bob := deployment.Client(t, "hs2", "@bob:hs2") - - queryParams := url.Values{} - queryParams.Set("server_name", "hs1") - res := bob.Do(t, "POST", []string{"_matrix", "client", "v3", "join", serverRoom.RoomID}, client.WithQueries(queryParams)) - must.MatchResponse(t, res, match.HTTPResponse{ - StatusCode: 200, - JSON: []match.JSON{ - match.JSONKeyEqual("room_id", serverRoom.RoomID), - }, - }) + roomID := bob.MustJoinRoom(t, serverRoom.RoomID, []string{"hs1"}) + must.Equal(t, roomID, serverRoom.RoomID, "joined room mismatch") } // This tests that joining a room with multiple ?server_name=s works correctly. diff --git a/tests/knocking_test.go b/tests/knocking_test.go index 45adce5e..fddd1afe 100644 --- a/tests/knocking_test.go +++ b/tests/knocking_test.go @@ -119,17 +119,7 @@ func knockingBetweenTwoUsersTest(t *testing.T, roomID string, inRoomUser, knocki t.Run("Attempting to join a room with join rule 'knock' without an invite should fail", func(t *testing.T) { // Set server_name so we can find rooms via ID over federation - query := url.Values{ - "server_name": []string{"hs1"}, - } - - res := knockingUser.Do( - t, - "POST", - []string{"_matrix", "client", "v3", "join", roomID}, - client.WithQueries(query), - client.WithRawBody([]byte(`{}`)), - ) + res := knockingUser.JoinRoom(t, roomID, []string{"hs1"}) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: 403, }) @@ -182,14 +172,7 @@ func knockingBetweenTwoUsersTest(t *testing.T, roomID string, inRoomUser, knocki _, since := knockingUser.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) // Rescind knock - knockingUser.MustDo( - t, - "POST", - []string{"_matrix", "client", "v3", "rooms", roomID, "leave"}, - client.WithJSONBody(t, map[string]interface{}{ - "reason": "Just kidding!", - }), - ) + knockingUser.MustLeaveRoom(t, roomID) // Use our sync token from earlier to carry out an incremental sync. Initial syncs may not contain room // leave information for obvious reasons @@ -257,15 +240,7 @@ func knockingBetweenTwoUsersTest(t *testing.T, roomID string, inRoomUser, knocki }) t.Run("A user in the room can accept a knock", func(t *testing.T) { - inRoomUser.MustDo( - t, - "POST", - []string{"_matrix", "client", "v3", "rooms", roomID, "invite"}, - client.WithJSONBody(t, map[string]string{ - "user_id": knockingUser.UserID, - "reason": "Seems like a trustworthy fellow", - }), - ) + inRoomUser.MustInviteRoom(t, roomID, knockingUser.UserID) // Wait until the invite membership event has come down sync inRoomUser.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(ev gjson.Result) bool { diff --git a/tests/restricted_rooms_test.go b/tests/restricted_rooms_test.go index 072fd092..683c4296 100644 --- a/tests/restricted_rooms_test.go +++ b/tests/restricted_rooms_test.go @@ -255,15 +255,7 @@ func doTestRestrictedRoomsRemoteJoinLocalUser(t *testing.T, roomVersion string, // Confirm that Alice cannot issue invites (due to the default power levels). bob := deployment.Client(t, "hs1", "@bob:hs1") - body := map[string]interface{}{ - "user_id": bob.UserID, - } - res := alice.Do( - t, - "POST", - []string{"_matrix", "client", "v3", "rooms", room, "invite"}, - client.WithJSONBody(t, body), - ) + res := alice.InviteRoom(t, room, bob.UserID) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: 403, }) From e1ff7a1084389e4f2d35ab71c4fa63d87059efec Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 9 Oct 2023 18:05:49 +0100 Subject: [PATCH 7/9] Review comments --- client/client.go | 20 +++++++------- client/sync.go | 4 +-- tests/csapi/media_misc_test.go | 4 +-- tests/csapi/rooms_state_test.go | 2 +- tests/csapi/sync_archive_test.go | 6 ++--- tests/csapi/sync_test.go | 12 ++++----- tests/federation_room_event_auth_test.go | 8 +++--- tests/knocking_test.go | 34 +++++++++--------------- 8 files changed, 39 insertions(+), 51 deletions(-) diff --git a/client/client.go b/client/client.go index 57945acd..b6125cd0 100644 --- a/client/client.go +++ b/client/client.go @@ -91,16 +91,16 @@ func (c *CSAPI) DownloadContent(t TestLike, mxcUri string) ([]byte, string) { } // MustCreateRoom creates a room with an optional HTTP request body. Fails the test on error. Returns the room ID. -func (c *CSAPI) MustCreateRoom(t TestLike, creationContent interface{}) string { +func (c *CSAPI) MustCreateRoom(t TestLike, creationContent map[string]interface{}) string { t.Helper() res := c.CreateRoom(t, creationContent) - mustRespondOK(t, res) + mustRespond2xx(t, res) body := ParseJSON(t, res) return GetJSONFieldStr(t, body, "room_id") } // CreateRoom creates a room with an optional HTTP request body. -func (c *CSAPI) CreateRoom(t TestLike, creationContent interface{}) *http.Response { +func (c *CSAPI) CreateRoom(t TestLike, creationContent map[string]interface{}) *http.Response { t.Helper() return c.Do(t, "POST", []string{"_matrix", "client", "v3", "createRoom"}, WithJSONBody(t, creationContent)) } @@ -109,7 +109,7 @@ func (c *CSAPI) CreateRoom(t TestLike, creationContent interface{}) *http.Respon func (c *CSAPI) MustJoinRoom(t TestLike, roomIDOrAlias string, serverNames []string) string { t.Helper() res := c.JoinRoom(t, roomIDOrAlias, serverNames) - mustRespondOK(t, res) + mustRespond2xx(t, res) // return the room ID if we joined with it if roomIDOrAlias[0] == '!' { return roomIDOrAlias @@ -137,7 +137,7 @@ func (c *CSAPI) JoinRoom(t TestLike, roomIDOrAlias string, serverNames []string) // MustLeaveRoom leaves the room ID, else fails the test. func (c *CSAPI) MustLeaveRoom(t TestLike, roomID string) { res := c.LeaveRoom(t, roomID) - mustRespondOK(t, res) + mustRespond2xx(t, res) } // LeaveRoom leaves the room ID. @@ -152,7 +152,7 @@ func (c *CSAPI) LeaveRoom(t TestLike, roomID string) *http.Response { func (c *CSAPI) MustInviteRoom(t TestLike, roomID string, userID string) { t.Helper() res := c.InviteRoom(t, roomID, userID) - mustRespondOK(t, res) + mustRespond2xx(t, res) } // InviteRoom invites userID to the room ID, else fails the test. @@ -297,7 +297,7 @@ func (c *CSAPI) SendEventSynced(t TestLike, roomID string, e b.Event) string { // event ID of the redaction event. func (c *CSAPI) MustSendRedaction(t TestLike, roomID string, e b.Event, eventID string) string { res := c.SendRedaction(t, roomID, e, eventID) - mustRespondOK(t, res) + mustRespond2xx(t, res) body := ParseJSON(t, res) return GetJSONFieldStr(t, body, "event_id") } @@ -313,7 +313,7 @@ func (c *CSAPI) SendRedaction(t TestLike, roomID string, e b.Event, eventID stri // MustSendTyping marks this user as typing until the timeout is reached. If isTyping is false, timeout is ignored. func (c *CSAPI) MustSendTyping(t TestLike, roomID string, isTyping bool, timeoutMillis int) { res := c.SendTyping(t, roomID, isTyping, timeoutMillis) - mustRespondOK(t, res) + mustRespond2xx(t, res) } // SendTyping marks this user as typing until the timeout is reached. If isTyping is false, timeout is ignored. @@ -684,7 +684,7 @@ func SplitMxc(mxcUri string) (string, string) { func (c *CSAPI) MustSendToDeviceMessages(t TestLike, evType string, messages map[string]map[string]map[string]interface{}) { t.Helper() res := c.SendToDeviceMessages(t, evType, messages) - mustRespondOK(t, res) + mustRespond2xx(t, res) } // SendToDeviceMessages sends to-device messages over /sendToDevice/. @@ -707,7 +707,7 @@ func (c *CSAPI) SendToDeviceMessages(t TestLike, evType string, messages map[str ) } -func mustRespondOK(t TestLike, res *http.Response) { +func mustRespond2xx(t TestLike, res *http.Response) { if res.StatusCode >= 200 && res.StatusCode < 300 { return // 2xx } diff --git a/client/sync.go b/client/sync.go index 6bf99393..97cf6220 100644 --- a/client/sync.go +++ b/client/sync.go @@ -144,7 +144,7 @@ func (c *CSAPI) MustSyncUntil(t TestLike, syncReq SyncReq, checks ...SyncCheckOp func (c *CSAPI) MustSync(t TestLike, syncReq SyncReq) (gjson.Result, string) { t.Helper() jsonBody, res := c.Sync(t, syncReq) - mustRespondOK(t, res) + mustRespond2xx(t, res) return jsonBody, jsonBody.Get("next_batch").Str } @@ -152,7 +152,7 @@ func (c *CSAPI) MustSync(t TestLike, syncReq SyncReq) (gjson.Result, string) { // see `MustSyncUntil`. // // Always returns the HTTP response, even on non-2xx. -// Returns the top-level parsed /sync response JSON on 200 OK. +// Returns the top-level parsed /sync response JSON on 2xx. func (c *CSAPI) Sync(t TestLike, syncReq SyncReq) (gjson.Result, *http.Response) { t.Helper() query := url.Values{ diff --git a/tests/csapi/media_misc_test.go b/tests/csapi/media_misc_test.go index 46bcd5b1..08461b09 100644 --- a/tests/csapi/media_misc_test.go +++ b/tests/csapi/media_misc_test.go @@ -6,8 +6,8 @@ import ( "github.com/tidwall/gjson" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/internal/data" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" @@ -26,7 +26,7 @@ func TestRoomImageRoundtrip(t *testing.T) { mxcUri := alice.UploadContent(t, data.MatrixPng, "test.png", "image/png") - roomId := alice.MustCreateRoom(t, struct{}{}) + roomId := alice.MustCreateRoom(t, map[string]interface{}{}) alice.SendEventSynced(t, roomId, b.Event{ Type: "m.room.message", diff --git a/tests/csapi/rooms_state_test.go b/tests/csapi/rooms_state_test.go index b4d35871..fc072d58 100644 --- a/tests/csapi/rooms_state_test.go +++ b/tests/csapi/rooms_state_test.go @@ -21,7 +21,7 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) { userID := "@alice:hs1" alice := deployment.Client(t, "hs1", userID) bob := deployment.RegisterUser(t, "hs1", "bob", "bobpassword", false) - roomID := alice.MustCreateRoom(t, struct{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) t.Run("parallel", func(t *testing.T) { // sytest: Room creation reports m.room.create to myself diff --git a/tests/csapi/sync_archive_test.go b/tests/csapi/sync_archive_test.go index 633272e6..104200a0 100644 --- a/tests/csapi/sync_archive_test.go +++ b/tests/csapi/sync_archive_test.go @@ -5,8 +5,8 @@ import ( "github.com/tidwall/gjson" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/runtime" ) @@ -248,10 +248,10 @@ func TestOlderLeftRoomsNotInLeaveSection(t *testing.T) { }, }) - roomToLeave := alice.MustCreateRoom(t, map[string]string{ + roomToLeave := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) - roomToSpam := alice.MustCreateRoom(t, map[string]string{ + roomToSpam := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) diff --git a/tests/csapi/sync_test.go b/tests/csapi/sync_test.go index 57954e39..99f81a06 100644 --- a/tests/csapi/sync_test.go +++ b/tests/csapi/sync_test.go @@ -8,8 +8,8 @@ import ( "github.com/tidwall/gjson" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/internal/federation" "github.com/matrix-org/complement/runtime" ) @@ -121,7 +121,7 @@ func TestSync(t *testing.T) { // sytest: Can sync a joined room t.Run("Can sync a joined room", func(t *testing.T) { t.Parallel() - roomID := alice.MustCreateRoom(t, struct{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) res, nextBatch := alice.MustSync(t, client.SyncReq{Filter: filterID}) // check all required fields exist @@ -135,7 +135,7 @@ func TestSync(t *testing.T) { // sytest: Full state sync includes joined rooms t.Run("Full state sync includes joined rooms", func(t *testing.T) { t.Parallel() - roomID := alice.MustCreateRoom(t, struct{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) _, nextBatch := alice.MustSync(t, client.SyncReq{Filter: filterID}) @@ -146,7 +146,7 @@ func TestSync(t *testing.T) { t.Run("Newly joined room is included in an incremental sync", func(t *testing.T) { t.Parallel() _, nextBatch := alice.MustSync(t, client.SyncReq{Filter: filterID}) - roomID := alice.MustCreateRoom(t, struct{}{}) + roomID := alice.MustCreateRoom(t, map[string]interface{}{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) res, nextBatch := alice.MustSync(t, client.SyncReq{Filter: filterID, Since: nextBatch}) checkJoinFieldsExist(t, res, roomID) @@ -383,8 +383,8 @@ func TestPresenceSyncDifferentRooms(t *testing.T) { charlie := deployment.NewUser(t, "charlie", "hs1") // Alice creates two rooms: one with her and Bob, and a second with her and Charlie. - bobRoomID := alice.MustCreateRoom(t, struct{}{}) - charlieRoomID := alice.MustCreateRoom(t, struct{}{}) + bobRoomID := alice.MustCreateRoom(t, map[string]interface{}{}) + charlieRoomID := alice.MustCreateRoom(t, map[string]interface{}{}) nextBatch := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, bobRoomID), client.SyncJoinedTo(alice.UserID, charlieRoomID)) alice.MustInviteRoom(t, bobRoomID, bob.UserID) diff --git a/tests/federation_room_event_auth_test.go b/tests/federation_room_event_auth_test.go index 7999c9ff..4c8a5483 100644 --- a/tests/federation_room_event_auth_test.go +++ b/tests/federation_room_event_auth_test.go @@ -17,8 +17,8 @@ import ( "github.com/matrix-org/gomatrixserverlib/spec" "github.com/tidwall/gjson" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/internal/federation" "github.com/matrix-org/complement/must" ) @@ -108,10 +108,8 @@ func TestInboundFederationRejectsEventsWithRejectedAuthEvents(t *testing.T) { // have Alice create a room, and then join it alice := deployment.Client(t, "hs1", "@alice:hs1") - testRoomID := alice.MustCreateRoom(t, struct { - Preset string `json:"preset"` - }{ - "public_chat", + testRoomID := alice.MustCreateRoom(t, map[string]interface{}{ + "preset": "public_chat", }) charlie := srv.UserID("charlie") room := srv.MustJoinRoom(t, deployment, "hs1", testRoomID, charlie) diff --git a/tests/knocking_test.go b/tests/knocking_test.go index fddd1afe..40bf0f14 100644 --- a/tests/knocking_test.go +++ b/tests/knocking_test.go @@ -69,12 +69,9 @@ func doTestKnocking(t *testing.T, roomVersion string, joinRule string) { david := srv.UserID("david") // Create a room for alice and bob to test knocking with - roomIDOne := alice.MustCreateRoom(t, struct { - Preset string `json:"preset"` - RoomVersion string `json:"room_version"` - }{ - "private_chat", // Set to private in order to get an invite-only room - roomVersion, + roomIDOne := alice.MustCreateRoom(t, map[string]interface{}{ + "preset": "private_chat", // Set to private in order to get an invite-only room + "room_version": roomVersion, }) alice.MustInviteRoom(t, roomIDOne, david) inviteWaiter.Wait(t, 5*time.Second) @@ -84,12 +81,9 @@ func doTestKnocking(t *testing.T, roomVersion string, joinRule string) { knockingBetweenTwoUsersTest(t, roomIDOne, alice, bob, serverRoomOne, false, joinRule) // Create a room for alice and charlie to test knocking with - roomIDTwo := alice.MustCreateRoom(t, struct { - Preset string `json:"preset"` - RoomVersion string `json:"room_version"` - }{ - "private_chat", // Set to private in order to get an invite-only room - roomVersion, + roomIDTwo := alice.MustCreateRoom(t, map[string]interface{}{ + "preset": "private_chat", // Set to private in order to get an invite-only room + "room_version": roomVersion, }) inviteWaiter = helpers.NewWaiter() alice.MustInviteRoom(t, roomIDTwo, david) @@ -355,12 +349,9 @@ func doTestKnockRoomsInPublicRoomsDirectory(t *testing.T, roomVersion string, jo alice := deployment.Client(t, "hs1", aliceUserID) // Create an invite-only room with the knock room version - roomID := alice.MustCreateRoom(t, struct { - Preset string `json:"preset"` - RoomVersion string `json:"room_version"` - }{ - "private_chat", // Set to private in order to get an invite-only room - roomVersion, + roomID := alice.MustCreateRoom(t, map[string]interface{}{ + "preset": "private_chat", // Set to private in order to get an invite-only room + "room_version": roomVersion, }) // Change the join_rule to allow knocking @@ -378,10 +369,9 @@ func doTestKnockRoomsInPublicRoomsDirectory(t *testing.T, roomVersion string, jo publishAndCheckRoomJoinRule(t, alice, roomID, joinRule) // Create a public room - roomID = alice.MustCreateRoom(t, struct { - Preset string `json:"preset"` - }{ - "public_chat", // Set to public in order to get a public room + roomID = alice.MustCreateRoom(t, map[string]interface{}{ + "preset": "private_chat", // Set to private in order to get an invite-only room + "room_version": roomVersion, }) // Publish the room, and check that the public room directory presents a 'join_rule' key of public From 2ca8903285bc2990a295e30b3ac586492ed9330b Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 9 Oct 2023 18:17:29 +0100 Subject: [PATCH 8/9] Move more things over to the new functions --- client/client.go | 8 +++---- tests/csapi/apidoc_room_create_test.go | 32 +++++++++++++------------- tests/csapi/apidoc_search_test.go | 9 ++------ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/client/client.go b/client/client.go index b6125cd0..299d998b 100644 --- a/client/client.go +++ b/client/client.go @@ -295,19 +295,19 @@ func (c *CSAPI) SendEventSynced(t TestLike, roomID string, e b.Event) string { // SendRedaction sends a redaction request. Will fail if the returned HTTP request code is not 200. Returns the // event ID of the redaction event. -func (c *CSAPI) MustSendRedaction(t TestLike, roomID string, e b.Event, eventID string) string { - res := c.SendRedaction(t, roomID, e, eventID) +func (c *CSAPI) MustSendRedaction(t TestLike, roomID string, content map[string]interface{}, eventID string) string { + res := c.SendRedaction(t, roomID, content, eventID) mustRespond2xx(t, res) body := ParseJSON(t, res) return GetJSONFieldStr(t, body, "event_id") } // SendRedaction sends a redaction request. -func (c *CSAPI) SendRedaction(t TestLike, roomID string, e b.Event, eventID string) *http.Response { +func (c *CSAPI) SendRedaction(t TestLike, roomID string, content map[string]interface{}, eventID string) *http.Response { t.Helper() txnID := int(atomic.AddInt64(&c.txnID, 1)) paths := []string{"_matrix", "client", "v3", "rooms", roomID, "redact", eventID, strconv.Itoa(txnID)} - return c.Do(t, "PUT", paths, WithJSONBody(t, e.Content)) + return c.Do(t, "PUT", paths, WithJSONBody(t, content)) } // MustSendTyping marks this user as typing until the timeout is reached. If isTyping is false, timeout is ignored. diff --git a/tests/csapi/apidoc_room_create_test.go b/tests/csapi/apidoc_room_create_test.go index 7639d409..7b85559e 100644 --- a/tests/csapi/apidoc_room_create_test.go +++ b/tests/csapi/apidoc_room_create_test.go @@ -5,17 +5,12 @@ import ( "github.com/tidwall/gjson" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" ) -func doCreateRoom(t *testing.T, c *client.CSAPI, json map[string]interface{}, match match.HTTPResponse) { - res := c.Do(t, "POST", []string{"_matrix", "client", "v3", "createRoom"}, client.WithJSONBody(t, json)) - must.MatchResponse(t, res, match) -} - func TestRoomCreate(t *testing.T) { deployment := Deploy(t, b.BlueprintOneToOneRoom) defer deployment.Destroy(t) @@ -29,10 +24,11 @@ func TestRoomCreate(t *testing.T) { t.Parallel() roomAlias := "30-room-create-alias-random" - doCreateRoom(t, alice, map[string]interface{}{ + res := alice.CreateRoom(t, map[string]interface{}{ "visibility": "public", "room_alias_name": roomAlias, - }, match.HTTPResponse{ + }) + must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: 200, JSON: []match.JSON{ match.JSONKeyTypeEqual("room_id", gjson.String), @@ -43,9 +39,10 @@ func TestRoomCreate(t *testing.T) { t.Run("POST /createRoom makes a private room", func(t *testing.T) { t.Parallel() - doCreateRoom(t, alice, map[string]interface{}{ + res := alice.CreateRoom(t, map[string]interface{}{ "visibility": "private", - }, match.HTTPResponse{ + }) + must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: 200, JSON: []match.JSON{ match.JSONKeyTypeEqual("room_id", gjson.String), @@ -102,10 +99,11 @@ func TestRoomCreate(t *testing.T) { t.Run("POST /createRoom makes a private room with invites", func(t *testing.T) { t.Parallel() - doCreateRoom(t, alice, map[string]interface{}{ + res := alice.CreateRoom(t, map[string]interface{}{ "visibility": "private", "invite": []string{bob.UserID}, - }, match.HTTPResponse{ + }) + must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: 200, JSON: []match.JSON{ match.JSONKeyTypeEqual("room_id", gjson.String), @@ -116,11 +114,12 @@ func TestRoomCreate(t *testing.T) { t.Run("POST /createRoom rejects attempts to create rooms with numeric versions", func(t *testing.T) { t.Parallel() - doCreateRoom(t, alice, map[string]interface{}{ + res := alice.CreateRoom(t, map[string]interface{}{ "visibility": "private", "room_version": 1, "preset": "public_chat", - }, match.HTTPResponse{ + }) + must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: 400, JSON: []match.JSON{ match.JSONKeyEqual("errcode", "M_BAD_JSON"), @@ -131,11 +130,12 @@ func TestRoomCreate(t *testing.T) { t.Run("POST /createRoom rejects attempts to create rooms with unknown versions", func(t *testing.T) { t.Parallel() - doCreateRoom(t, alice, map[string]interface{}{ + res := alice.CreateRoom(t, map[string]interface{}{ "visibility": "private", "room_version": "ahfgwjyerhgiuveisbruvybseyrugvi", "preset": "public_chat", - }, match.HTTPResponse{ + }) + must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: 400, JSON: []match.JSON{ match.JSONKeyEqual("errcode", "M_UNSUPPORTED_ROOM_VERSION"), diff --git a/tests/csapi/apidoc_search_test.go b/tests/csapi/apidoc_search_test.go index 811e5164..8b362f08 100644 --- a/tests/csapi/apidoc_search_test.go +++ b/tests/csapi/apidoc_search_test.go @@ -6,7 +6,6 @@ import ( "net/url" "testing" - "github.com/matrix-org/util" "github.com/tidwall/gjson" "github.com/matrix-org/complement/b" @@ -299,11 +298,7 @@ func TestSearch(t *testing.T) { }) // redact the event - redactBody := client.WithJSONBody(t, map[string]interface{}{"reason": "testing"}) - txnID := util.RandomString(8) // random string, as time.Now().Unix() might create the same txnID - resp := alice.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "redact", redactedEventID, txnID}, redactBody) - j := must.ParseJSON(t, resp.Body) - redactionEventID := must.GetJSONFieldStr(t, j, "event_id") + redactionEventID := alice.MustSendRedaction(t, roomID, map[string]interface{}{"reason": "testing"}, redactedEventID) // wait for the redaction to come down sync alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHasEventID(roomID, redactionEventID)) @@ -320,7 +315,7 @@ func TestSearch(t *testing.T) { }, }) - resp = alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "search"}, searchRequest) + resp := alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "search"}, searchRequest) sce := "search_categories.room_events" result0 := sce + ".results.0.result" must.MatchResponse(t, resp, match.HTTPResponse{ From 646e7a8113f88b250ec7aeaf9baa2cc4f1592028 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 9 Oct 2023 18:33:37 +0100 Subject: [PATCH 9/9] Add more Must functions, fix up bad refactor --- client/client.go | 20 ++++++++++++++++---- tests/csapi/account_data_test.go | 16 ++++++++-------- tests/csapi/ignored_users_test.go | 17 ++++++----------- tests/direct_messaging_test.go | 6 +++--- tests/federation_redaction_test.go | 12 +++--------- tests/knocking_test.go | 2 +- tests/msc3391_test.go | 16 ++++++++-------- tests/msc3890_test.go | 10 ++++------ 8 files changed, 49 insertions(+), 50 deletions(-) diff --git a/client/client.go b/client/client.go index 299d998b..ee373ff5 100644 --- a/client/client.go +++ b/client/client.go @@ -165,19 +165,31 @@ func (c *CSAPI) InviteRoom(t TestLike, roomID string, userID string) *http.Respo return c.Do(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "invite"}, WithJSONBody(t, body)) } +func (c *CSAPI) MustGetGlobalAccountData(t TestLike, eventType string) *http.Response { + res := c.GetGlobalAccountData(t, eventType) + mustRespond2xx(t, res) + return res +} + func (c *CSAPI) GetGlobalAccountData(t TestLike, eventType string) *http.Response { - return c.MustDo(t, "GET", []string{"_matrix", "client", "v3", "user", c.UserID, "account_data", eventType}) + return c.Do(t, "GET", []string{"_matrix", "client", "v3", "user", c.UserID, "account_data", eventType}) } -func (c *CSAPI) SetGlobalAccountData(t TestLike, eventType string, content map[string]interface{}) *http.Response { +func (c *CSAPI) MustSetGlobalAccountData(t TestLike, eventType string, content map[string]interface{}) *http.Response { return c.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "user", c.UserID, "account_data", eventType}, WithJSONBody(t, content)) } +func (c *CSAPI) MustGetRoomAccountData(t TestLike, roomID string, eventType string) *http.Response { + res := c.GetRoomAccountData(t, roomID, eventType) + mustRespond2xx(t, res) + return res +} + func (c *CSAPI) GetRoomAccountData(t TestLike, roomID string, eventType string) *http.Response { - return c.MustDo(t, "GET", []string{"_matrix", "client", "v3", "user", c.UserID, "rooms", roomID, "account_data", eventType}) + return c.Do(t, "GET", []string{"_matrix", "client", "v3", "user", c.UserID, "rooms", roomID, "account_data", eventType}) } -func (c *CSAPI) SetRoomAccountData(t TestLike, roomID string, eventType string, content map[string]interface{}) *http.Response { +func (c *CSAPI) MustSetRoomAccountData(t TestLike, roomID string, eventType string, content map[string]interface{}) *http.Response { return c.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "user", c.UserID, "rooms", roomID, "account_data", eventType}, WithJSONBody(t, content)) } diff --git a/tests/csapi/account_data_test.go b/tests/csapi/account_data_test.go index a22ef0d1..9b74550e 100644 --- a/tests/csapi/account_data_test.go +++ b/tests/csapi/account_data_test.go @@ -18,20 +18,20 @@ func TestAddAccountData(t *testing.T) { // sytest: Can get account data without syncing t.Run("Can add global account data", func(t *testing.T) { // Set the account data entry - alice.SetGlobalAccountData(t, "test.key", map[string]interface{}{"value": "first"}) + alice.MustSetGlobalAccountData(t, "test.key", map[string]interface{}{"value": "first"}) // check that getting the account data returns the correct value - must.MatchResponse(t, alice.GetGlobalAccountData(t, "test.key"), match.HTTPResponse{ + must.MatchResponse(t, alice.MustGetGlobalAccountData(t, "test.key"), match.HTTPResponse{ JSON: []match.JSON{ match.JSONKeyEqual("value", "first"), }, }) // Set it to something else - alice.SetGlobalAccountData(t, "test.key", map[string]interface{}{"value": "second"}) + alice.MustSetGlobalAccountData(t, "test.key", map[string]interface{}{"value": "second"}) // check that getting the account data returns the updated value - must.MatchResponse(t, alice.GetGlobalAccountData(t, "test.key"), match.HTTPResponse{ + must.MatchResponse(t, alice.MustGetGlobalAccountData(t, "test.key"), match.HTTPResponse{ JSON: []match.JSON{ match.JSONKeyEqual("value", "second"), }, @@ -45,20 +45,20 @@ func TestAddAccountData(t *testing.T) { roomID := alice.MustCreateRoom(t, map[string]interface{}{}) // Set the room account data entry - alice.SetRoomAccountData(t, roomID, "test.key", map[string]interface{}{"value": "room first"}) + alice.MustSetRoomAccountData(t, roomID, "test.key", map[string]interface{}{"value": "room first"}) // check that getting the account data returns the correct value - must.MatchResponse(t, alice.GetRoomAccountData(t, roomID, "test.key"), match.HTTPResponse{ + must.MatchResponse(t, alice.MustGetRoomAccountData(t, roomID, "test.key"), match.HTTPResponse{ JSON: []match.JSON{ match.JSONKeyEqual("value", "room first"), }, }) // Set it to something else - alice.SetRoomAccountData(t, roomID, "test.key", map[string]interface{}{"value": "room second"}) + alice.MustSetRoomAccountData(t, roomID, "test.key", map[string]interface{}{"value": "room second"}) // check that getting the account data returns the updated value - must.MatchResponse(t, alice.GetRoomAccountData(t, roomID, "test.key"), match.HTTPResponse{ + must.MatchResponse(t, alice.MustGetRoomAccountData(t, roomID, "test.key"), match.HTTPResponse{ JSON: []match.JSON{ match.JSONKeyEqual("value", "room second"), }, diff --git a/tests/csapi/ignored_users_test.go b/tests/csapi/ignored_users_test.go index 6a1105dc..effa490d 100644 --- a/tests/csapi/ignored_users_test.go +++ b/tests/csapi/ignored_users_test.go @@ -10,8 +10,8 @@ import ( "github.com/tidwall/gjson" - "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" ) @@ -42,16 +42,11 @@ func TestInviteFromIgnoredUsersDoesNotAppearInSync(t *testing.T) { alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, publicRoom)) // Alice ignores Bob. - alice.MustDo( - t, - "PUT", - []string{"_matrix", "client", "v3", "user", alice.UserID, "account_data", "m.ignored_user_list"}, - client.WithJSONBody(t, map[string]interface{}{ - "ignored_users": map[string]interface{}{ - bob.UserID: map[string]interface{}{}, - }, - }), - ) + alice.MustSetGlobalAccountData(t, "m.ignored_user_list", map[string]interface{}{ + "ignored_users": map[string]interface{}{ + bob.UserID: map[string]interface{}{}, + }, + }) // Alice waits to see that the ignore was successful. sinceJoinedAndIgnored := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncGlobalAccountDataHas( diff --git a/tests/direct_messaging_test.go b/tests/direct_messaging_test.go index 91adf7b2..c9ff8940 100644 --- a/tests/direct_messaging_test.go +++ b/tests/direct_messaging_test.go @@ -34,7 +34,7 @@ func TestWriteMDirectAccountData(t *testing.T) { "invite": []string{bob.UserID}, "is_direct": true, }) - alice.SetGlobalAccountData(t, "m.direct", map[string]interface{}{ + alice.MustSetGlobalAccountData(t, "m.direct", map[string]interface{}{ bob.UserID: []string{roomID}, }) @@ -52,13 +52,13 @@ func TestWriteMDirectAccountData(t *testing.T) { "invite": []string{bob.UserID}, "is_direct": true, }) - alice.SetGlobalAccountData(t, "m.direct", map[string]interface{}{ + alice.MustSetGlobalAccountData(t, "m.direct", map[string]interface{}{ bob.UserID: []string{roomID}, }) alice.MustSyncUntil(t, client.SyncReq{Since: since}, client.SyncGlobalAccountDataHas(checkAccountData)) // check that manually GETing the account data also works with the new updated value - must.MatchResponse(t, alice.GetGlobalAccountData(t, "m.direct"), match.HTTPResponse{ + must.MatchResponse(t, alice.MustGetGlobalAccountData(t, "m.direct"), match.HTTPResponse{ StatusCode: 200, JSON: []match.JSON{ match.JSONKeyEqual(client.GjsonEscape(bob.UserID), []interface{}{roomID}), diff --git a/tests/federation_redaction_test.go b/tests/federation_redaction_test.go index a3fd6cbf..7a6661ee 100644 --- a/tests/federation_redaction_test.go +++ b/tests/federation_redaction_test.go @@ -70,11 +70,8 @@ func TestFederationRedactSendsWithoutEvent(t *testing.T) { eventToRedact := eventID + ":" + fullServerName // the client sends a request to the local homeserver to send the redaction - redactionEventID := alice.MustSendRedaction(t, serverRoom.RoomID, b.Event{ - Type: wantEventType, - Content: map[string]interface{}{ - "reason": "reasons...", - }, + redactionEventID := alice.MustSendRedaction(t, serverRoom.RoomID, map[string]interface{}{ + "reason": "reasons...", }, eventToRedact) // wait for redaction to arrive at remote homeserver @@ -83,10 +80,7 @@ func TestFederationRedactSendsWithoutEvent(t *testing.T) { // Check that the last event in the room is now the redaction lastEvent := serverRoom.Timeline[len(serverRoom.Timeline)-1] lastEventType := lastEvent.Type() - wantedType := "m.room.redaction" - if lastEventType != wantedType { - t.Fatalf("Incorrent event type %s, wanted m.room.redaction.", lastEventType) - } + must.Equal(t, lastEventType, "m.room.redaction", "incorrect event type") // check that the event id of the redaction sent by alice is the same as the redaction event in the room must.Equal(t, lastEvent.EventID(), redactionEventID, "incorrect event id") diff --git a/tests/knocking_test.go b/tests/knocking_test.go index 40bf0f14..b9de4bd3 100644 --- a/tests/knocking_test.go +++ b/tests/knocking_test.go @@ -370,7 +370,7 @@ func doTestKnockRoomsInPublicRoomsDirectory(t *testing.T, roomVersion string, jo // Create a public room roomID = alice.MustCreateRoom(t, map[string]interface{}{ - "preset": "private_chat", // Set to private in order to get an invite-only room + "preset": "public_chat", "room_version": roomVersion, }) diff --git a/tests/msc3391_test.go b/tests/msc3391_test.go index 01ad488e..f64ecd5c 100644 --- a/tests/msc3391_test.go +++ b/tests/msc3391_test.go @@ -66,7 +66,7 @@ func createUserAccountData(t *testing.T, c *client.CSAPI) { // Set and check the account data // Create user account data - c.SetGlobalAccountData(t, testAccountDataType, testAccountDataContent) + c.MustSetGlobalAccountData(t, testAccountDataType, testAccountDataContent) // Wait for the account data to appear down /sync c.MustSyncUntil( @@ -78,7 +78,7 @@ func createUserAccountData(t *testing.T, c *client.CSAPI) { ) // Also check the account data content by querying the appropriate endpoint - res := c.GetGlobalAccountData(t, testAccountDataType) + res := c.MustGetGlobalAccountData(t, testAccountDataType) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONKeyEqual("", testAccountDataContent), @@ -96,7 +96,7 @@ func createRoomAccountData(t *testing.T, c *client.CSAPI, roomID string) { ) // Create room account data - c.SetRoomAccountData(t, roomID, testAccountDataType, testAccountDataContent) + c.MustSetRoomAccountData(t, roomID, testAccountDataType, testAccountDataContent) // Wait for the account data to appear down /sync c.MustSyncUntil( @@ -108,7 +108,7 @@ func createRoomAccountData(t *testing.T, c *client.CSAPI, roomID string) { ) // Also check the account data content by querying the appropriate endpoint - res := c.GetRoomAccountData(t, roomID, testAccountDataType) + res := c.MustGetRoomAccountData(t, roomID, testAccountDataType) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONKeyEqual("", testAccountDataContent), @@ -140,7 +140,7 @@ func deleteUserAccountData(t *testing.T, c *client.CSAPI, viaDelete bool) { } else { // Delete via the PUT method. PUT'ing with an empty dictionary will delete // the account data type for this user. - c.SetGlobalAccountData(t, testAccountDataType, map[string]interface{}{}) + c.MustSetGlobalAccountData(t, testAccountDataType, map[string]interface{}{}) } // Check that the content of the user account data for this type @@ -154,7 +154,7 @@ func deleteUserAccountData(t *testing.T, c *client.CSAPI, viaDelete bool) { ) // Also check the account data item is no longer found - res := c.Do(t, "GET", []string{"_matrix", "client", "v3", "user", c.UserID, "account_data", testAccountDataType}) + res := c.GetGlobalAccountData(t, testAccountDataType) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: 404, }) @@ -198,7 +198,7 @@ func deleteRoomAccountData(t *testing.T, c *client.CSAPI, viaDelete bool, roomID } else { // Delete via the PUT method. PUT'ing with an empty dictionary will delete // the account data type for this room. - c.SetRoomAccountData(t, roomID, testAccountDataType, map[string]interface{}{}) + c.MustSetRoomAccountData(t, roomID, testAccountDataType, map[string]interface{}{}) } // Check that the content of the room account data for this type @@ -212,7 +212,7 @@ func deleteRoomAccountData(t *testing.T, c *client.CSAPI, viaDelete bool, roomID ) // Also check the account data item is no longer found - res := c.Do(t, "GET", []string{"_matrix", "client", "v3", "user", c.UserID, "room", roomID, "account_data", testAccountDataType}) + res := c.GetRoomAccountData(t, roomID, testAccountDataType) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: 404, }) diff --git a/tests/msc3890_test.go b/tests/msc3890_test.go index dab5d15a..2bf57430 100644 --- a/tests/msc3890_test.go +++ b/tests/msc3890_test.go @@ -42,10 +42,8 @@ func TestDeletingDeviceRemovesDeviceLocalNotificationSettings(t *testing.T) { ) // Using the first device, create some local notification settings in the user's account data for the second device. - aliceDeviceOne.SetGlobalAccountData( - t, - accountDataType, - accountDataContent, + aliceDeviceOne.MustSetGlobalAccountData( + t, accountDataType, accountDataContent, ) checkAccountDataContent := func(r gjson.Result) bool { @@ -66,7 +64,7 @@ func TestDeletingDeviceRemovesDeviceLocalNotificationSettings(t *testing.T) { ) // Also check via the dedicated account data endpoint to ensure the similar check later is not 404'ing for some other reason. // Using `MustDo` ensures that the response code is 2xx. - res := aliceDeviceOne.MustDo(t, "GET", []string{"_matrix", "client", "v3", "user", aliceDeviceOne.UserID, "account_data", accountDataType}) + res := aliceDeviceOne.MustGetGlobalAccountData(t, accountDataType) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONKeyEqual("is_silenced", true), @@ -77,7 +75,7 @@ func TestDeletingDeviceRemovesDeviceLocalNotificationSettings(t *testing.T) { aliceDeviceTwo.MustDo(t, "POST", []string{"_matrix", "client", "v3", "logout"}) // Using the first device, check that the local notification setting account data for the deleted device was removed. - res = aliceDeviceOne.Do(t, "GET", []string{"_matrix", "client", "v3", "user", aliceDeviceOne.UserID, "account_data", accountDataType}) + res = aliceDeviceOne.MustGetGlobalAccountData(t, accountDataType) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: 404, JSON: []match.JSON{