From 96d0a03374b9b82857cd9ab651e5f2329ae500bb Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Tue, 4 Oct 2022 18:10:03 -0500 Subject: [PATCH] Be tolerant of the the `end` key not existing in a /messages resposne Split out from https://github.com/matrix-org/complement/pull/214 --- tests/msc2716_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/msc2716_test.go b/tests/msc2716_test.go index ae3a29d4..5a75ea88 100644 --- a/tests/msc2716_test.go +++ b/tests/msc2716_test.go @@ -1254,7 +1254,6 @@ func paginateUntilMessageCheckOff(t *testing.T, c *client.CSAPI, roomID string, })) callCounter++ messsageResBody := client.ParseJSON(t, messagesRes) - messageResEnd = client.GetJSONFieldStr(t, messsageResBody, "end") // Since the original body can only be read once, create a new one from the body bytes we just read messagesRes.Body = ioutil.NopCloser(bytes.NewBuffer(messsageResBody)) @@ -1294,6 +1293,12 @@ func paginateUntilMessageCheckOff(t *testing.T, c *client.CSAPI, roomID string, if len(workingExpectedEventIDMap) == 0 { return } + + // Since this will throw an error if they key does not exist, do this at the end of + // the loop. It's a valid scenario to be at the end of the room and have no more to + // paginate so we want to make sure the `return` above runs when we've found all of + // the expected events. + messageResEnd = client.GetJSONFieldStr(t, messsageResBody, "end") } }