mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
Fixup tests
This commit is contained in:
parent
2bca40107a
commit
d1cb97663f
3
.github/workflows/tests.yml
vendored
3
.github/workflows/tests.yml
vendored
@ -295,6 +295,9 @@ jobs:
|
|||||||
- name: Build ${{env.PREV_VERSION}}
|
- name: Build ${{env.PREV_VERSION}}
|
||||||
run: go build ./cmd/syncv3
|
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
|
- name: Run end-to-end tests
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
@ -43,8 +43,19 @@ type CSAPI struct {
|
|||||||
AvatarURL string
|
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) {
|
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()
|
t.Helper()
|
||||||
if len(opts) == 0 {
|
if len(opts) == 0 {
|
||||||
opts = append(opts, client.WithQueries(url.Values{
|
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
|
// copy the CSAPI struct and tweak the base URL so we talk to the proxy not synapse
|
||||||
csapi := *c.CSAPI
|
csapi := *c.CSAPI
|
||||||
csapi.BaseURL = proxyBaseURL
|
csapi.BaseURL = proxyBaseURL
|
||||||
res := csapi.MustDo(t, "POST", []string{"_matrix", "client", "unstable", "org.matrix.msc3575", "sync"}, opts...)
|
return csapi.Do(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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CSAPI) SlidingSyncUntilEventID(t *testing.T, pos string, roomID string, eventID string) (res *sync3.Response) {
|
func (c *CSAPI) SlidingSyncUntilEventID(t *testing.T, pos string, roomID string, eventID string) (res *sync3.Response) {
|
||||||
|
@ -5,12 +5,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/complement/b"
|
"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/sync3"
|
||||||
"github.com/matrix-org/sliding-sync/testutils/m"
|
"github.com/matrix-org/sliding-sync/testutils/m"
|
||||||
)
|
)
|
||||||
@ -34,29 +32,25 @@ func TestInvalidTokenReturnsMUnknownTokenError(t *testing.T) {
|
|||||||
|
|
||||||
var invalidResponses []*http.Response
|
var invalidResponses []*http.Response
|
||||||
// using the same token now returns a 401 with M_UNKNOWN_TOKEN
|
// 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{
|
httpRes := alice.DoSlidingSync(t, sync3.Request{
|
||||||
"timeout": []string{"500"},
|
|
||||||
}), client.WithJSONBody(t, sync3.Request{
|
|
||||||
ConnID: "A",
|
ConnID: "A",
|
||||||
RoomSubscriptions: map[string]sync3.RoomSubscription{
|
RoomSubscriptions: map[string]sync3.RoomSubscription{
|
||||||
roomID: {
|
roomID: {
|
||||||
TimelineLimit: 1,
|
TimelineLimit: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}))
|
})
|
||||||
invalidResponses = append(invalidResponses, httpRes)
|
invalidResponses = append(invalidResponses, httpRes)
|
||||||
// using a bogus access token returns a 401 with M_UNKNOWN_TOKEN
|
// using a bogus access token returns a 401 with M_UNKNOWN_TOKEN
|
||||||
alice.AccessToken = "flibble_wibble"
|
alice.AccessToken = "flibble_wibble"
|
||||||
httpRes = alice.Do(t, "POST", []string{"_matrix", "client", "unstable", "org.matrix.msc3575", "sync"}, client.WithQueries(url.Values{
|
httpRes = alice.DoSlidingSync(t, sync3.Request{
|
||||||
"timeout": []string{"500"},
|
|
||||||
}), client.WithJSONBody(t, sync3.Request{
|
|
||||||
ConnID: "A",
|
ConnID: "A",
|
||||||
RoomSubscriptions: map[string]sync3.RoomSubscription{
|
RoomSubscriptions: map[string]sync3.RoomSubscription{
|
||||||
roomID: {
|
roomID: {
|
||||||
TimelineLimit: 1,
|
TimelineLimit: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}))
|
})
|
||||||
invalidResponses = append(invalidResponses, httpRes)
|
invalidResponses = append(invalidResponses, httpRes)
|
||||||
|
|
||||||
for i, httpRes := range invalidResponses {
|
for i, httpRes := range invalidResponses {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user