Fixup tests

This commit is contained in:
Kegan Dougal 2023-10-11 17:14:49 +01:00
parent 2bca40107a
commit d1cb97663f
3 changed files with 20 additions and 17 deletions

View File

@ -295,6 +295,9 @@ jobs:
- name: Build ${{env.PREV_VERSION}}
run: go build ./cmd/syncv3
- name: Install libolm
run: sudo apt-get update && sudo apt-get install -y libolm3 libolm-dev
- name: Run end-to-end tests
run: |
set -euo pipefail

View File

@ -43,8 +43,19 @@ type CSAPI struct {
AvatarURL string
}
// SlidingSync performs a single sliding sync request
// SlidingSync performs a single sliding sync request. Fails on non 2xx
func (c *CSAPI) SlidingSync(t *testing.T, data sync3.Request, opts ...client.RequestOpt) (resBody *sync3.Response) {
t.Helper()
res := c.DoSlidingSync(t, data, opts...)
body := client.ParseJSON(t, res)
if err := json.Unmarshal(body, &resBody); err != nil {
t.Fatalf("failed to unmarshal response: %v", err)
}
return
}
// DoSlidingSync is the same as SlidingSync but returns the raw HTTP response. Succeeds on any status code.
func (c *CSAPI) DoSlidingSync(t *testing.T, data sync3.Request, opts ...client.RequestOpt) (res *http.Response) {
t.Helper()
if len(opts) == 0 {
opts = append(opts, client.WithQueries(url.Values{
@ -55,12 +66,7 @@ func (c *CSAPI) SlidingSync(t *testing.T, data sync3.Request, opts ...client.Req
// copy the CSAPI struct and tweak the base URL so we talk to the proxy not synapse
csapi := *c.CSAPI
csapi.BaseURL = proxyBaseURL
res := csapi.MustDo(t, "POST", []string{"_matrix", "client", "unstable", "org.matrix.msc3575", "sync"}, opts...)
body := client.ParseJSON(t, res)
if err := json.Unmarshal(body, &resBody); err != nil {
t.Fatalf("failed to unmarshal response: %v", err)
}
return
return csapi.Do(t, "POST", []string{"_matrix", "client", "unstable", "org.matrix.msc3575", "sync"}, opts...)
}
func (c *CSAPI) SlidingSyncUntilEventID(t *testing.T, pos string, roomID string, eventID string) (res *sync3.Response) {

View File

@ -5,12 +5,10 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"testing"
"time"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/sliding-sync/sync3"
"github.com/matrix-org/sliding-sync/testutils/m"
)
@ -34,29 +32,25 @@ func TestInvalidTokenReturnsMUnknownTokenError(t *testing.T) {
var invalidResponses []*http.Response
// using the same token now returns a 401 with M_UNKNOWN_TOKEN
httpRes := alice.Do(t, "POST", []string{"_matrix", "client", "unstable", "org.matrix.msc3575", "sync"}, client.WithQueries(url.Values{
"timeout": []string{"500"},
}), client.WithJSONBody(t, sync3.Request{
httpRes := alice.DoSlidingSync(t, sync3.Request{
ConnID: "A",
RoomSubscriptions: map[string]sync3.RoomSubscription{
roomID: {
TimelineLimit: 1,
},
},
}))
})
invalidResponses = append(invalidResponses, httpRes)
// using a bogus access token returns a 401 with M_UNKNOWN_TOKEN
alice.AccessToken = "flibble_wibble"
httpRes = alice.Do(t, "POST", []string{"_matrix", "client", "unstable", "org.matrix.msc3575", "sync"}, client.WithQueries(url.Values{
"timeout": []string{"500"},
}), client.WithJSONBody(t, sync3.Request{
httpRes = alice.DoSlidingSync(t, sync3.Request{
ConnID: "A",
RoomSubscriptions: map[string]sync3.RoomSubscription{
roomID: {
TimelineLimit: 1,
},
},
}))
})
invalidResponses = append(invalidResponses, httpRes)
for i, httpRes := range invalidResponses {