Skip to content

Commit 8e5852d

Browse files
committed
Cli: tests
1 parent 5b05cd8 commit 8e5852d

13 files changed

+321
-36
lines changed

.config/nextest.toml

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[profile.default]
22
# https://nexte.st/book/slow-tests.html
33
slow-timeout = { period = "10s", terminate-after = 3 } # Timeout a test after 30s (3 * 10s)
4+
# Allow the server to shutdown after the tests
5+
leak-timeout = "500ms"
46

57
[profile.ci]
68
slow-timeout = { period = "10s", terminate-after = 5 } # Timeout a test after 50s (5 * 10s)
@@ -12,3 +14,5 @@ status-level = "all"
1214
failure-output = "immediate-final"
1315
# Continue even if a test fail.
1416
fail-fast = false
17+
# Allow the server to shutdown after the tests
18+
leak-timeout = "500ms"

.github/workflows/ci-rust.yml

+39
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ concurrency:
2626
cancel-in-progress: true
2727

2828
env:
29+
poetry-version: 1.5.1
2930
CARGO_CI_FLAGS: --locked --profile ci-rust
3031
CARGO_NEXTEST_CI_FLAGS: --profile=ci --locked --cargo-profile ci-rust
3132
WINFSP_VERSION: 2.0.23075
@@ -89,6 +90,25 @@ jobs:
8990
with:
9091
9192

93+
- uses: ./.github/actions/setup-python-poetry
94+
id: setup-python
95+
with:
96+
poetry-version: ${{ env.poetry-version }}
97+
project-path: ./server
98+
timeout-minutes: 10
99+
100+
- name: Install python dependencies
101+
run: python make.py python-dev-install
102+
timeout-minutes: 10
103+
104+
- name: Build CLI binary
105+
run: cargo build --profile ci-rust --package parsec_cli --features testenv
106+
timeout-minutes: 5
107+
108+
- name: Test CLI
109+
run: cargo nextest run ${{ env.CARGO_NEXTEST_CI_FLAGS }} --package parsec_cli --features testenv
110+
timeout-minutes: 10
111+
92112
- name: Categorize workspace crates
93113
id: crates
94114
run: |
@@ -224,3 +244,22 @@ jobs:
224244
env:
225245
RUST_LOG: debug
226246
TESTBED_SERVER: http://localhost:6777
247+
248+
- uses: ./.github/actions/setup-python-poetry
249+
id: setup-python
250+
with:
251+
poetry-version: ${{ env.poetry-version }}
252+
project-path: ./server
253+
timeout-minutes: 10
254+
255+
- name: Install python dependencies
256+
run: python make.py python-dev-install
257+
timeout-minutes: 10
258+
259+
- name: Build CLI binary
260+
run: cargo build --profile ci-rust --package parsec_cli --features testenv
261+
timeout-minutes: 5
262+
263+
- name: Test CLI
264+
run: cargo nextest run ${{ env.CARGO_NEXTEST_CI_FLAGS }} --package parsec_cli --features testenv
265+
timeout-minutes: 20

Cargo.lock

+86
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ libparsec_tests_lite = { path = "libparsec/crates/tests_lite", default-features
9292
android_logger = { version = "0.13", default-features = false }
9393
anyhow = { version = "1.0.75", default-features = false }
9494
argon2 = { version = "0.5.2", default-features = false }
95+
assert_cmd = { version = "2.0.12", default-features = false }
9596
async-lock = { version = "2.8.0", default-features = false }
9697
async-broadcast = { version = "0.5.1", default-features = false }
9798
async-trait = { version = "0.1.74", default-features = false }
@@ -148,6 +149,7 @@ openssl = { version = "0.10.61", default-features = false }
148149
paste = { version = "1.0.14", default-features = false }
149150
pin-project-lite = { version = "0.2.13", default-features = false }
150151
percent-encoding = { version = "2.3.1", default-features = false }
152+
predicates = { version = "3.0.4", default-features = false }
151153
pretty_assertions = { version = "1.4.0", default-features = false }
152154
proc-macro2 = { version = "1.0.70", default-features = false }
153155
pyo3 = { version = "0.19.2", default-features = false }

cli/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ serde_json = { workspace = true }
2525
terminal-spinners = { workspace = true }
2626
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
2727
uuid = { workspace = true }
28+
29+
[dev-dependencies]
30+
libparsec = { workspace = true, features = ["cli-tests"] }
31+
32+
assert_cmd = { workspace = true }
33+
predicates = { workspace = true, features = ["regex"] }
34+
rstest = { workspace = true }

cli/src/bootstrap_organization.rs

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ pub async fn bootstrap_organization(
5858
HumanHandle::new(&bootstrap_organization.email, &bootstrap_organization.label)
5959
.map_err(|e| anyhow::anyhow!("Cannot create human handle: {e}"))?;
6060

61+
#[cfg(feature = "testenv")]
62+
let password = "test".to_string().into();
63+
#[cfg(not(feature = "testenv"))]
6164
let password = rpassword::prompt_password("password:")?.into();
6265

6366
let handle = SpinnerBuilder::new()

cli/src/create_organization.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ pub async fn create_organization(create_organization: CreateOrganization) -> any
6969
let organization_addr =
7070
BackendOrganizationBootstrapAddr::new(addr, organization_id, Some(bootstrap_token));
7171

72-
let organization_addr_display = organization_addr.to_url();
73-
74-
println!("Organization bootstrap url: {YELLOW}{organization_addr_display}{RESET}");
72+
println!("Organization bootstrap url: {YELLOW}{organization_addr}{RESET}");
7573

7674
Ok(())
7775
}

cli/src/list_devices.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ pub struct ListDevices {
1616

1717
pub async fn list_devices(list_devices: ListDevices) -> anyhow::Result<()> {
1818
let config_dir = list_devices.config_dir.unwrap_or(get_default_config_dir());
19+
let config_dir_str = config_dir.to_string_lossy();
1920
let devices = list_available_devices(&config_dir).await;
2021

2122
if devices.is_empty() {
22-
println!("No devices found in {YELLOW}{config_dir:?}{RESET}");
23+
println!("No devices found in {YELLOW}{config_dir_str}{RESET}");
2324
} else {
2425
let n = devices.len();
25-
println!("Found {GREEN}{n}{RESET} device(s) in {YELLOW}{config_dir:?}{RESET}:");
26+
println!("Found {GREEN}{n}{RESET} device(s) in {YELLOW}{config_dir_str}{RESET}:");
2627
format_devices(&devices);
2728
}
2829

cli/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ mod create_organization;
55
mod list_devices;
66
#[cfg(feature = "testenv")]
77
mod run_testenv;
8+
#[cfg(all(test, feature = "testenv"))]
9+
mod tests;
810
mod utils;
911

1012
use clap::{Parser, Subcommand};

0 commit comments

Comments
 (0)