|
| 1 | +# Libparsec Testbed |
| 2 | + |
| 3 | +The `libparsec_testbed` crate defines common organization templates to prevent code |
| 4 | +duplication in tests. |
| 5 | + |
| 6 | +## Organization templates |
| 7 | + |
| 8 | +A template defines the structure of an organization such as: |
| 9 | + |
| 10 | +- the users & their devices |
| 11 | +- the workspaces & their sharing rules |
| 12 | +- the files and directories inside each workspace |
| 13 | + |
| 14 | +Within a test, this is usually a good starting point (hence the name) and the |
| 15 | +organization can be further customized in a way that is relevant to the test |
| 16 | +(e.g. revoke an existing user). |
| 17 | + |
| 18 | +Templates also allow to create deterministic tests based on the events that |
| 19 | +should be triggered, the order in which they should be triggered or the |
| 20 | +specific timestamp at which they should be triggered. |
| 21 | + |
| 22 | +## Use in tests |
| 23 | + |
| 24 | +The templates defined in this crate are used to test Libparsec, Parsec CLI and |
| 25 | +the Parsec Server. |
| 26 | + |
| 27 | +### Libparsec testing |
| 28 | + |
| 29 | +The templates can be enabled via the `#[parsec_test]` macro defined in the |
| 30 | +`tests_macros` crate. |
| 31 | + |
| 32 | +```rust |
| 33 | +#[parsec_test(testbed = "coolorg")] |
| 34 | +async fn my_test_function( |
| 35 | + // ... |
| 36 | + env: &TestbedEnv, |
| 37 | +){ |
| 38 | + // access and customize the organization via the TestbedEnv |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +### Parsec CLI testing |
| 43 | + |
| 44 | +Currently, the testbed is only partially used in Parsec CLI tests to provide a |
| 45 | +basic Parsec Server and setup/create organization from there (so templates are |
| 46 | +not used). See https://github.com/Scille/parsec-cloud/issues/9144. |
| 47 | + |
| 48 | +### Parsec Server testing |
| 49 | + |
| 50 | +The templates are exposed as pytest fixtures in `server/tests/common/client.py`. |
| 51 | + |
| 52 | +## Internals |
| 53 | + |
| 54 | +Organization templates are created with a `TestbedTemplateBuilder` and exposed |
| 55 | +via the `TESTBED_TEMPLATES` array. |
| 56 | + |
| 57 | +Example: |
| 58 | + |
| 59 | +```rust |
| 60 | +let mut builder = TestbedTemplate::from_builder("my_organization"); |
| 61 | +builder.bootstrap_organization("alice"); // alice@dev1 |
| 62 | +builder |
| 63 | + .new_user("bob") |
| 64 | + .with_initial_profile(UserProfile::Standard); // bob@dev1 |
| 65 | +builder.new_device("alice"); // alice@dev2 |
| 66 | +builder.new_device("bob"); // bob@dev2 |
| 67 | +``` |
| 68 | + |
| 69 | +The easiest way to add a new template is to take a look at the existing ones in |
| 70 | +the the `templates/` directory. |
0 commit comments