Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/api/rust/dynamic_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package rust
import (
"slices"
"testing"

"github.com/matrix-org/complement/ct"
)

func mustEqual(t *testing.T, got, want []int, msg string) {
t.Helper()
if !slices.Equal(got, want) {
t.Errorf("%s, got %v want %v", msg, got, want)
ct.Errorf(t, "%s, got %v want %v", msg, got, want)
}
}

Expand Down
3 changes: 2 additions & 1 deletion internal/api/rust/generic_state_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"github.com/matrix-org/complement/ct"
"github.com/matrix-org/complement/must"
)

Expand All @@ -13,7 +14,7 @@ func receiveFromChannel(t *testing.T, ch <-chan string) string {
case val := <-ch:
return val
case <-time.After(time.Second):
t.Fatalf("failed to receive from channel")
ct.Fatalf(t, "failed to receive from channel")
}
return ""
}
Expand Down
5 changes: 3 additions & 2 deletions internal/api/rust/room_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rust
import (
"testing"

"github.com/matrix-org/complement/ct"
"github.com/matrix-org/complement/must"
)

Expand Down Expand Up @@ -40,7 +41,7 @@ func TestRoomListener(t *testing.T) {
rl.BroadcastUpdateForRoom("quuz")
select {
case <-recv:
t.Fatalf("received room id after cancel()")
ct.Fatalf(t, "received room id after cancel()")
default:
// we expect to hit this
}
Expand All @@ -54,7 +55,7 @@ func TestRoomListener(t *testing.T) {
rl.BroadcastUpdateForRoom("no one is listening")
select {
case <-recv2:
t.Fatalf("received room id after returning true")
ct.Fatalf(t, "received room id after returning true")
default:
// we expect to hit this
}
Expand Down
10 changes: 5 additions & 5 deletions internal/api/rust/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (c *RustClient) RequestOwnUserVerification(t ct.TestLike) chan api.Verifica
},
SendCancel: func() {
if err := svc.CancelVerification(); err != nil {
t.Errorf("failed to CancelVerification: %s", err)
ct.Errorf(t, "failed to CancelVerification: %s", err)
}
},
SendStart: func(method string) {
Expand All @@ -270,17 +270,17 @@ func (c *RustClient) RequestOwnUserVerification(t ct.TestLike) chan api.Verifica
return
}
if err := svc.StartSasVerification(); err != nil {
t.Errorf("failed to StartSasVerification: %s", err)
ct.Errorf(t, "failed to StartSasVerification: %s", err)
}
},
SendApprove: func() {
if err := svc.ApproveVerification(); err != nil {
t.Errorf("failed to ApproveVerification: %s", err)
ct.Errorf(t, "failed to ApproveVerification: %s", err)
}
},
SendDecline: func() {
if err := svc.DeclineVerification(); err != nil {
t.Errorf("failed to ApproveVerification: %s", err)
ct.Errorf(t, "failed to ApproveVerification: %s", err)
}
},
SendTransition: func() {
Expand Down Expand Up @@ -317,7 +317,7 @@ func (c *RustClient) DeletePersistentStorage(t ct.TestLike) {
}
func (c *RustClient) ForceClose(t ct.TestLike) {
t.Helper()
t.Fatalf("Cannot force close a rust client, use an RPC client instead.")
ct.Fatalf(t, "Cannot force close a rust client, use an RPC client instead.")
}

func (c *RustClient) Close(t ct.TestLike) {
Expand Down
3 changes: 2 additions & 1 deletion internal/cc/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/matrix-org/complement-crypto/internal/api"
"github.com/matrix-org/complement-crypto/internal/config"
"github.com/matrix-org/complement-crypto/internal/deploy"
"github.com/matrix-org/complement/ct"

complementconfig "github.com/matrix-org/complement/config"
)
Expand Down Expand Up @@ -124,7 +125,7 @@ func (i *Instance) CreateTestContext(t *testing.T, clientType ...api.ClientType)
tc.Charlie = tc.RegisterNewUser(t, clientType[2], "charlie")
}
if len(clientType) > 3 {
t.Fatalf("CreateTestContext: too many clients: got %d", len(clientType))
ct.Fatalf(t, "CreateTestContext: too many clients: got %d", len(clientType))
}
return tc
}
4 changes: 2 additions & 2 deletions internal/cc/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (c *TestContext) mustCreateMultiprocessClient(t *testing.T, req *ClientCrea
ctxPrefix := fmt.Sprintf("%d", c.RPCInstance.Add(1))
remoteBindings, err := rpc.NewLanguageBindings(c.RPCBinaryPath, req.User.ClientType.Lang, ctxPrefix)
if err != nil {
t.Fatalf("Failed to create new RPC language bindings: %s", err)
ct.Fatalf(t, "Failed to create new RPC language bindings: %s", err)
}
return api.NewTestClient(remoteBindings.MustCreateClient(t, req.Opts))
}
Expand Down Expand Up @@ -319,7 +319,7 @@ func (c *TestContext) MustCreateClient(t *testing.T, req *ClientCreationRequest)
func mustCreateClient(t *testing.T, clientType api.ClientType, cfg api.ClientCreationOpts) api.TestClient {
bindings := langs.GetLanguageBindings(clientType.Lang)
if bindings == nil {
t.Fatalf("unknown language: %s", clientType.Lang)
ct.Fatalf(t, "unknown language: %s", clientType.Lang)
}
c := bindings.MustCreateClient(t, cfg)
return api.NewTestClient(c)
Expand Down
8 changes: 4 additions & 4 deletions internal/deploy/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (c *RPCClient) ForceClose(t ct.TestLike) {
t.Helper()
err := c.rpcCmd.Process.Kill()
if err != nil {
t.Fatalf("failed to kill process: %s", err)
ct.Fatalf(t, "failed to kill process: %s", err)
}
}

Expand Down Expand Up @@ -230,7 +230,7 @@ func (c *RPCClient) DeletePersistentStorage(t ct.TestLike) {
var void int
err := c.client.Call("Server.DeletePersistentStorage", t.Name(), &void)
if err != nil {
t.Fatalf("RPCClient.DeletePersistentStorage: %s", err)
ct.Fatalf(t, "RPCClient.DeletePersistentStorage: %s", err)
}
}
func (c *RPCClient) Login(t ct.TestLike, opts api.ClientCreationOpts) error {
Expand Down Expand Up @@ -295,7 +295,7 @@ func (c *RPCClient) WaitUntilEventInRoom(t ct.TestLike, roomID string, checker f
RoomID: roomID,
}, &waiterID)
if err != nil {
t.Fatalf("RPCClient.WaitUntilEventInRoom: %s", err)
ct.Fatalf(t, "RPCClient.WaitUntilEventInRoom: %s", err)
}
return &RPCWaiter{
client: c.client,
Expand Down Expand Up @@ -356,7 +356,7 @@ func (c *RPCClient) Logf(t ct.TestLike, format string, args ...interface{}) {
var void int
err := c.client.Call("Server.Logf", str, &void)
if err != nil {
t.Fatalf("RPCClient.Logf: %s", err)
ct.Fatalf(t, "RPCClient.Logf: %s", err)
}
}

Expand Down
9 changes: 6 additions & 3 deletions internal/tests/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ package tests

import (
"fmt"

complementconfig "github.com/matrix-org/complement/config"
"github.com/matrix-org/complement/ct"

"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -41,7 +44,7 @@ func Deploy(t *testing.T) *deploy.ComplementCryptoDeployment {
}
wd, err := os.Getwd()
if err != nil {
t.Fatalf("failed to get wd: %s", err)
ct.Fatalf(t, "failed to get wd: %s", err)
}
ssDeployment = deploy.RunNewDeployment(t, filepath.Join(wd, "../../tests/mitmproxy_addons"), "")
return ssDeployment
Expand All @@ -51,14 +54,14 @@ func TestMain(m *testing.M) {
rustClientCreator := func(t *testing.T, cfg api.ClientCreationOpts) api.TestClient {
client, err := rust.NewRustClient(t, cfg)
if err != nil {
t.Fatalf("NewRustClient: %s", err)
ct.Fatalf(t, "NewRustClient: %s", err)
}
return api.NewTestClient(client)
}
jsClientCreator := func(t *testing.T, cfg api.ClientCreationOpts) api.TestClient {
client, err := js.NewJSClient(t, cfg)
if err != nil {
t.Fatalf("NewJSClient: %s", err)
ct.Fatalf(t, "NewJSClient: %s", err)
}
return api.NewTestClient(client)
}
Expand Down
10 changes: 5 additions & 5 deletions tests/room_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func TestRoomKeyIsNotCycledOnClientRestart(t *testing.T) {
case api.ClientTypeJS:
testRoomKeyIsNotCycledOnClientRestartJS(t, a)
default:
t.Fatalf("unknown lang: %s", a.Lang)
ct.Fatalf(t, "unknown lang: %s", a.Lang)
}
})
}
Expand Down Expand Up @@ -572,7 +572,7 @@ func TestSpoofedEventSenderHandling(t *testing.T) {
shield, err := bob.GetEventShield(t, roomID, spoofedEventID)
must.NotError(t, "Could not get shield for Bob's view of spoofed message", err)
if shield == nil {
t.Errorf("Bob did not get a shield for the spoofed message")
ct.Errorf(t, "Bob did not get a shield for the spoofed message")
} else {
must.Equal(t, shield.Colour, api.EventShieldColourRed, "Colour of shield")
must.Equal(t, shield.Code, api.EventShieldCodeMismatchedSender, "Shield code")
Expand Down Expand Up @@ -613,7 +613,7 @@ func withSpoofSender(t *testing.T, tc *cc.TestContext, attackerUserID string, ta
t.Logf("Rewriting event %s from %s to have sender of %s", event.Get("event_id").String(), event.Get("sender").String(), spoofedUserID)
var err error
if eventArrayRaw, err = sjson.Set(eventArrayRaw, fmt.Sprintf("%d.sender", idx.Int()), spoofedUserID); err != nil {
t.Fatalf("Couldn't patch event array: %s", err)
ct.Fatalf(t, "Couldn't patch event array: %s", err)
}
}
return true
Expand All @@ -636,7 +636,7 @@ func withSpoofSender(t *testing.T, tc *cc.TestContext, attackerUserID string, ta
roomListJSONPath = "rooms"
timelineJSONPath = "timeline"
} else {
t.Fatalf("Unknown sync endpoint: %s", cd.URL)
ct.Fatalf(t, "Unknown sync endpoint: %s", cd.URL)
}

rawBody := string(cd.ResponseBody)
Expand All @@ -648,7 +648,7 @@ func withSpoofSender(t *testing.T, tc *cc.TestContext, attackerUserID string, ta
jsonPath := fmt.Sprintf("%s.%s.%s", roomListJSONPath, gjson.Escape(roomID.String()), timelineJSONPath)
var err error
if rawBody, err = sjson.SetRaw(rawBody, jsonPath, patchedTimeline); err != nil {
t.Fatalf("Couldn't patch response json: %s", err)
ct.Fatalf(t, "Couldn't patch response json: %s", err)
}
return true
})
Expand Down
4 changes: 2 additions & 2 deletions tests/state_synchronisation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestSigkillBeforeKeysUploadResponse(t *testing.T) {
case api.ClientTypeJS:
testSigkillBeforeKeysUploadResponseJS(t, a)
default:
t.Fatalf("unknown lang: %s", a.Lang)
ct.Fatalf(t, "unknown lang: %s", a.Lang)
}
})
}
Expand All @@ -46,7 +46,7 @@ func testSigkillBeforeKeysUploadResponseRust(t *testing.T, clientType api.Client
if terminated.Load() {
// make sure the 2nd upload 200 OKs
if cd.ResponseCode != 200 {
t.Errorf("2nd /keys/upload did not 200 OK => got %v", cd.ResponseCode)
ct.Errorf(t, "2nd /keys/upload did not 200 OK => got %v", cd.ResponseCode)
}
t.Logf("recv 2nd /keys/upload => HTTP %d", cd.ResponseCode)
seenSecondKeysUploadWaiter.Finish()
Expand Down
5 changes: 3 additions & 2 deletions tests/to_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

"github.com/matrix-org/complement/ct"
"github.com/matrix-org/gomatrixserverlib/spec"

"github.com/matrix-org/complement-crypto/internal/api"
Expand Down Expand Up @@ -124,7 +125,7 @@ func TestUnprocessedToDeviceMessagesArentLostOnRestart(t *testing.T) {
case api.ClientTypeJS:
testUnprocessedToDeviceMessagesArentLostOnRestartJS(t, tc, roomID, eventID)
default:
t.Fatalf("unknown lang: %s", clientType.Lang)
ct.Fatalf(t, "unknown lang: %s", clientType.Lang)
}
})
})
Expand Down Expand Up @@ -310,7 +311,7 @@ func TestToDeviceMessagesAreBatched(t *testing.T) {
return nil
}
if len(usersMap.Map()) != 100 {
t.Errorf("PUT /sendToDevice did not batch messages, got %d want 100", len(usersMap.Map()))
ct.Errorf(t, "PUT /sendToDevice did not batch messages, got %d want 100", len(usersMap.Map()))
t.Logf("%s", usersMap.Raw)
}
waiter.Finish()
Expand Down
Loading