From d1cb97663f14f4ce0ebbdb271c67f4ade1f7c597 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 11 Oct 2023 17:14:49 +0100 Subject: [PATCH] Fixup tests --- .github/workflows/tests.yml | 3 +++ tests-e2e/client_test.go | 20 +++++++++++++------- tests-e2e/conns_test.go | 14 ++++---------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6076feb..978304a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/tests-e2e/client_test.go b/tests-e2e/client_test.go index a082632..76b227e 100644 --- a/tests-e2e/client_test.go +++ b/tests-e2e/client_test.go @@ -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) { diff --git a/tests-e2e/conns_test.go b/tests-e2e/conns_test.go index ce5182c..967d3af 100644 --- a/tests-e2e/conns_test.go +++ b/tests-e2e/conns_test.go @@ -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 {