diff --git a/README.md b/README.md index bb8254a..6333c26 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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. diff --git a/tests/happy_test.go b/tests/happy_test.go index a1e8364..23e7adc 100644 --- a/tests/happy_test.go +++ b/tests/happy_test.go @@ -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) { diff --git a/tests/main_test.go b/tests/main_test.go index 5362682..aef557c 100644 --- a/tests/main_test.go +++ b/tests/main_test.go @@ -1,6 +1,7 @@ package tests import ( + "os" "sync" "testing" @@ -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() @@ -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: