Skip to content

Commit 83f274c

Browse files
refactor(cli): Update test to work with [email protected]
- Integration test needed to be full integration tests to have access to `CARGO_BIN_EXE_parsec-cli` env var. - The changes above needed to how `testenv_utils` is exposed and need to import self as dev-dependencies with `testenv` feature enabled. - Now every cli test use either `std_cmd` or `assert_cmd` macros.
1 parent ef2e44c commit 83f274c

40 files changed

+171
-189
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ autotests = false
1313
name = "minimal_short_id"
1414
harness = false
1515

16+
[[test]]
17+
name = "integration"
18+
path = "tests/integration/mod.rs"
19+
1620
[features]
1721
use-libsodium = ["libparsec_crypto/use-libsodium"]
1822
vendored-openssl = ["libparsec_crypto/vendored-openssl"]
@@ -47,6 +51,7 @@ itertools = { workspace = true, features = ["use_std"] }
4751
[dev-dependencies]
4852
libparsec = { workspace = true, features = ["cli-tests"] }
4953
libparsec_tests_fixtures = { workspace = true }
54+
parsec-cli = { path = ".", features = ["testenv"] }
5055

5156
assert_cmd = { workspace = true }
5257
predicates = { workspace = true, features = ["regex"] }

cli/src/commands/tos/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub async fn main(args: Args) -> anyhow::Result<()> {
5050
}
5151

5252
#[derive(serde::Serialize)]
53-
pub(crate) struct TosReq<'a> {
53+
pub struct TosReq<'a> {
5454
tos: Option<HashMap<&'a str, &'a str>>,
5555
}
5656

@@ -59,12 +59,12 @@ impl<'a> TosReq<'a> {
5959
Self { tos: None }
6060
}
6161

62-
pub(crate) fn set_tos(tos: HashMap<&'a str, &'a str>) -> Self {
62+
pub fn set_tos(tos: HashMap<&'a str, &'a str>) -> Self {
6363
Self { tos: Some(tos) }
6464
}
6565
}
6666

67-
pub(crate) async fn config_tos_for_org_req<'a>(
67+
pub async fn config_tos_for_org_req<'a>(
6868
addr: &ParsecAddr,
6969
token: &'a str,
7070
organization: &OrganizationID,

cli/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
pub mod commands;
22
pub mod macros;
33

4-
#[cfg(test)]
5-
#[path = "../tests/integration/mod.rs"]
6-
mod integration_tests;
74
#[cfg(any(test, feature = "testenv"))]
85
pub mod testenv_utils;
96
#[cfg(test)]

cli/src/testenv_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
};
2323

2424
pub const DEFAULT_ADMINISTRATION_TOKEN: &str = "s3cr3t";
25-
pub(crate) const DEFAULT_DEVICE_PASSWORD: &str = "P@ssw0rd.";
25+
pub const DEFAULT_DEVICE_PASSWORD: &str = "P@ssw0rd.";
2626
const RESERVED_PORT_OFFSET: u16 = 1024;
2727
const AVAILABLE_PORT_COUNT: u16 = u16::MAX - RESERVED_PORT_OFFSET;
2828
const LAST_SERVER_PID: &str = "LAST_SERVER_ID";
@@ -221,7 +221,7 @@ async fn register_new_user(
221221
Ok(new_device)
222222
}
223223

224-
pub(crate) fn create_new_user(
224+
pub fn create_new_user(
225225
new_device: Arc<LocalDevice>,
226226
author: Arc<LocalDevice>,
227227
initial_profile: UserProfile,
@@ -246,7 +246,7 @@ pub(crate) fn create_new_user(
246246
(user_certificate, redacted_user_certificate)
247247
}
248248

249-
pub(crate) fn create_new_device(
249+
pub fn create_new_device(
250250
new_device: Arc<LocalDevice>,
251251
author: Arc<LocalDevice>,
252252
now: DateTime,

cli/tests/integration/certificate/poll_and_forget.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::io::{BufReader, Write};
22

3-
use assert_cmd::cargo::CommandCargoExt;
43
use libparsec::{tmp_path, TmpPath};
54

65
use crate::{
7-
integration_tests::{bootstrap_cli_test, wait_for},
6+
bootstrap_cli_test,
87
testenv_utils::{TestOrganization, DEFAULT_DEVICE_PASSWORD},
8+
wait_for,
99
};
1010

1111
#[rstest::rstest]
@@ -31,20 +31,18 @@ async fn poll_and_forget(tmp_path: TmpPath) {
3131
)
3232
.stdout(predicates::str::contains("Added 0 new certificates"));
3333

34-
let mut process = std::process::Command::cargo_bin("parsec-cli")
35-
.unwrap()
36-
.args([
37-
"certificate",
38-
"forget-all-certificates",
39-
"--device",
40-
&alice.device_id.hex(),
41-
"--password-stdin",
42-
])
43-
.stdin(std::process::Stdio::piped())
44-
.stderr(std::process::Stdio::inherit())
45-
.stdout(std::process::Stdio::piped())
46-
.spawn()
47-
.unwrap();
34+
let mut process = crate::std_cmd!(
35+
"certificate",
36+
"forget-all-certificates",
37+
"--device",
38+
&alice.device_id.hex(),
39+
"--password-stdin"
40+
)
41+
.stdin(std::process::Stdio::piped())
42+
.stderr(std::process::Stdio::inherit())
43+
.stdout(std::process::Stdio::piped())
44+
.spawn()
45+
.unwrap();
4846

4947
let mut stdout = BufReader::new(process.stdout.as_mut().unwrap());
5048
let stdin = process.stdin.as_mut().unwrap();

cli/tests/integration/device/change_authentication.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::io::{BufReader, Write};
22

3-
use assert_cmd::cargo::CommandCargoExt;
43
use libparsec::{tmp_path, TmpPath};
54
use libparsec_tests_fixtures::prelude::*;
65

76
use crate::{
8-
integration_tests::{bootstrap_cli_test, wait_for},
7+
bootstrap_cli_test,
98
testenv_utils::{TestOrganization, DEFAULT_DEVICE_PASSWORD},
9+
wait_for,
1010
};
1111

1212
#[rstest::rstest]
@@ -16,21 +16,19 @@ async fn ok(tmp_path: TmpPath) {
1616

1717
let (_, TestOrganization { alice, .. }, _) = bootstrap_cli_test(&tmp_path).await.unwrap();
1818

19-
let mut process = std::process::Command::cargo_bin("parsec-cli")
20-
.unwrap()
21-
.args([
22-
"device",
23-
"change-authentication",
24-
"--device",
25-
&alice.device_id.hex(),
26-
"--password",
27-
"--password-stdin",
28-
])
29-
.stdin(std::process::Stdio::piped())
30-
.stderr(std::process::Stdio::inherit())
31-
.stdout(std::process::Stdio::piped())
32-
.spawn()
33-
.unwrap();
19+
let mut process = crate::std_cmd!(
20+
"device",
21+
"change-authentication",
22+
"--device",
23+
&alice.device_id.hex(),
24+
"--password",
25+
"--password-stdin"
26+
)
27+
.stdin(std::process::Stdio::piped())
28+
.stderr(std::process::Stdio::inherit())
29+
.stdout(std::process::Stdio::piped())
30+
.spawn()
31+
.unwrap();
3432

3533
let mut stdout = BufReader::new(process.stdout.as_mut().unwrap());
3634
let stdin = process.stdin.as_mut().unwrap();

cli/tests/integration/device/export_recovery_device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use libparsec::{tmp_path, TmpPath};
22

33
use crate::{
4-
integration_tests::bootstrap_cli_test,
4+
bootstrap_cli_test,
55
testenv_utils::{TestOrganization, DEFAULT_DEVICE_PASSWORD},
66
};
77

cli/tests/integration/device/import_recovery_device.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use libparsec::{tmp_path, DeviceLabel, TmpPath};
22

33
use crate::{
4-
integration_tests::bootstrap_cli_test,
4+
bootstrap_cli_test,
55
testenv_utils::{TestOrganization, DEFAULT_DEVICE_PASSWORD},
6-
utils::start_client,
76
};
7+
use parsec_cli::utils::start_client;
88

99
#[rstest::rstest]
1010
#[tokio::test]

cli/tests/integration/device/list.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use libparsec::{tmp_path, TmpPath};
22

3-
use crate::{
4-
integration_tests::bootstrap_cli_test,
5-
utils::{GREEN, RESET, YELLOW},
6-
};
3+
use crate::bootstrap_cli_test;
4+
use parsec_cli::utils::{GREEN, RESET, YELLOW};
75

86
#[rstest::rstest]
97
#[tokio::test]

0 commit comments

Comments
 (0)