Skip to content

Commit

Permalink
Add COMPLEMENT_CRYPTO_TEST_CLIENTS
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Nov 3, 2023
1 parent 488560b commit 700fcee
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 13 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ COMPLEMENT_BASE_IMAGE=homeserver:latest go test -v ./tests

TODO: consider checking in working builds so you can git clone and run. Git LFS for `libmatrix_sdk_ffi.so` given it's 60MB?

#### Environment Variables

- `COMPLEMENT_CRYPTO_TEST_CLIENTS` : "mixed", "rust" or "js"
Control which kinds of clients to make for tests. `rust` only tests rust clients. `js` only tests JS clients. `mixed` tests all 4 permutations.


### Test hitlist
There is an exhaustive set of tests that this repository aims to exercise which are below:
Expand Down Expand Up @@ -92,3 +97,11 @@ cargo install uniffi-bindgen-go --path ./uniffi-bindgen-go/bindgen
* Replace field names `Error` with `Error2` to fix `unknown field Error in struct literal`.
- Sanity check compile `LIBRARY_PATH="$LIBRARY_PATH:/path/to/matrix-rust-sdk/target/debug" go test -c ./tests`


### Github Action (TODO)

Inputs:
- version/commit/branch of JS SDK
- version/commit/branch of Rust SDK
- version/commit/branch of synapse?
- Test only JS, only Rust, mixed.
14 changes: 1 addition & 13 deletions tests/happy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,7 @@ import (
// asserting that isEncrypted() returns true. This test may be expanded in the
// future to assert things like "there is a ciphertext".
func TestAliceBobEncryptionWorks(t *testing.T) {
// TODO: factor out so we can just call "matrix subtests"
t.Run("Rust x Rust", func(t *testing.T) {
testAliceBobEncryptionWorks(t, api.ClientTypeRust, api.ClientTypeRust)
})
t.Run("JS x JS", func(t *testing.T) {
testAliceBobEncryptionWorks(t, api.ClientTypeJS, api.ClientTypeJS)
})
t.Run("Rust x JS", func(t *testing.T) {
testAliceBobEncryptionWorks(t, api.ClientTypeRust, api.ClientTypeJS)
})
t.Run("JS x Rust", func(t *testing.T) {
testAliceBobEncryptionWorks(t, api.ClientTypeJS, api.ClientTypeRust)
})
ClientTypeMatrix(t, testAliceBobEncryptionWorks)
}

func testAliceBobEncryptionWorks(t *testing.T, clientTypeA, clientTypeB api.ClientType) {
Expand Down
43 changes: 43 additions & 0 deletions tests/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"os"
"sync"
"testing"

Expand All @@ -10,12 +11,28 @@ import (
"github.com/matrix-org/complement/must"
)

const (
TestClientsMixed = "mixed"
TestClientsRustOnly = "rust"
TestClientsJSOnly = "js"
)

var (
ssDeployment *deploy.SlidingSyncDeployment
ssMutex *sync.Mutex
testClients = TestClientsMixed
)

func TestMain(m *testing.M) {
ccTestClients := os.Getenv("COMPLEMENT_CRYPTO_TEST_CLIENTS")
switch ccTestClients {
case TestClientsRustOnly:
testClients = TestClientsRustOnly
case TestClientsJSOnly:
testClients = TestClientsJSOnly
default:
testClients = TestClientsMixed
}
ssMutex = &sync.Mutex{}
defer func() { // always teardown even if panicking
ssMutex.Lock()
Expand All @@ -38,6 +55,32 @@ func Deploy(t *testing.T) *deploy.SlidingSyncDeployment {
return ssDeployment
}

func ClientTypeMatrix(t *testing.T, subTest func(tt *testing.T, a, b api.ClientType)) {
switch testClients {
case TestClientsJSOnly:
t.Run("JS|JS", func(t *testing.T) {
subTest(t, api.ClientTypeJS, api.ClientTypeJS)
})
case TestClientsRustOnly:
t.Run("Rust|Rust", func(t *testing.T) {
subTest(t, api.ClientTypeRust, api.ClientTypeRust)
})
case TestClientsMixed:
t.Run("Rust|Rust", func(t *testing.T) {
subTest(t, api.ClientTypeRust, api.ClientTypeRust)
})
t.Run("Rust|JS", func(t *testing.T) {
subTest(t, api.ClientTypeRust, api.ClientTypeJS)
})
t.Run("JS|Rust", func(t *testing.T) {
subTest(t, api.ClientTypeJS, api.ClientTypeRust)
})
t.Run("JS|JS", func(t *testing.T) {
subTest(t, api.ClientTypeJS, api.ClientTypeJS)
})
}
}

func MustLoginClient(t *testing.T, clientType api.ClientType, opts api.ClientCreationOpts, ssURL string) api.Client {
switch clientType {
case api.ClientTypeRust:
Expand Down

0 comments on commit 700fcee

Please sign in to comment.