Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libparsec_testbed crate docs #9295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion libparsec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Here, "testing" refers to two use-cases:
2. Running the application with test feature (e.g. we want to run the GUI with an
dummy organization already configured for quick testing purpose)

- `testbed`:
- `testbed`: Defines common organization templates to prevent code duplication in tests.
- `tests_macros`: Defines the `#[parsec_test]` macro that is used to decorate each
test function. Among other things, this macro conveniently handles setting up
Tokio context (so that our test can be an asynchronous function) and the testbed
Expand Down
70 changes: 70 additions & 0 deletions libparsec/crates/testbed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Libparsec Testbed

The `libparsec_testbed` crate defines common organization templates to prevent code
duplication in tests.

## Organization templates

A template defines the structure of an organization such as:

- the users & their devices
- the workspaces & their sharing rules
- the files and directories inside each workspace

Within a test, this is usually a good starting point (hence the name) and the
organization can be further customized in a way that is relevant to the test
(e.g. revoke an existing user).

Templates also allow to create deterministic tests based on the events that
should be triggered, the order in which they should be triggered or the
specific timestamp at which they should be triggered.

## Use in tests

The templates defined in this crate are used to test Libparsec, Parsec CLI and
the Parsec Server.

### Libparsec testing

The templates can be enabled via the `#[parsec_test]` macro defined in the
`tests_macros` crate.

```rust
#[parsec_test(testbed = "coolorg")]
async fn my_test_function(
// ...
env: &TestbedEnv,
){
// access and customize the organization via the TestbedEnv
}
```

### Parsec CLI testing

Currently, the testbed is only partially used in Parsec CLI tests to provide a
basic Parsec Server and setup/create organization from there (so templates are
not used). See https://github.com/Scille/parsec-cloud/issues/9144.

### Parsec Server testing

The templates are exposed as pytest fixtures in `server/tests/common/client.py`.

## Internals

Organization templates are created with a `TestbedTemplateBuilder` and exposed
via the `TESTBED_TEMPLATES` array.

Example:

```rust
let mut builder = TestbedTemplate::from_builder("my_organization");
builder.bootstrap_organization("alice"); // alice@dev1
builder
.new_user("bob")
.with_initial_profile(UserProfile::Standard); // bob@dev1
builder.new_device("alice"); // alice@dev2
builder.new_device("bob"); // bob@dev2
```

The easiest way to add a new template is to take a look at the existing ones in
the the `templates/` directory.
2 changes: 1 addition & 1 deletion libparsec/crates/testbed/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS

#![doc = include_str!("../README.md")]
// This lib provide helpers that are used for testing purpose.
// To simplify the writing of those helpers, we use the same rule for when writing tests.
#![allow(clippy::unwrap_used)]
Expand Down
Loading