Skip to content

Commit b32fa56

Browse files
committed
Add libparsec_testbed crate docs
1 parent 514231f commit b32fa56

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

libparsec/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Here, "testing" refers to two use-cases:
8585
2. Running the application with test feature (e.g. we want to run the GUI with an
8686
dummy organization already configured for quick testing purpose)
8787

88-
- `testbed`:
88+
- `testbed`: Defines common organization templates to prevent code duplication in tests.
8989
- `tests_macros`: Defines the `#[parsec_test]` macro that is used to decorate each
9090
test function. Among other things, this macro conveniently handles setting up
9191
Tokio context (so that our test can be an asynchronous function) and the testbed

libparsec/crates/testbed/README.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.

libparsec/crates/testbed/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS
2-
2+
#![doc = include_str!("../README.md")]
33
// This lib provide helpers that are used for testing purpose.
44
// To simplify the writing of those helpers, we use the same rule for when writing tests.
55
#![allow(clippy::unwrap_used)]

0 commit comments

Comments
 (0)