Skip to content

Commit c356cf6

Browse files
More test refactoring
1 parent 90a8751 commit c356cf6

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

tests/list_vhost_limits_tests.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::process::Command;
21
// Copyright (C) 2023-2024 RabbitMQ Core Team ([email protected])
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,38 +11,27 @@ use std::process::Command;
1211
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1312
// See the License for the specific language governing permissions and
1413
// limitations under the License.
15-
use assert_cmd::prelude::*;
1614
use predicates::prelude::*;
1715

16+
mod test_helpers;
17+
use crate::test_helpers::*;
18+
1819
#[test]
1920
fn test_vhost_limits() -> Result<(), Box<dyn std::error::Error>> {
20-
let mut cmd = Command::cargo_bin("rabbitmqadmin")?;
21-
22-
cmd.args([
21+
let limit_name = "max-connections";
22+
run_succeeds([
2323
"declare",
2424
"vhost_limit",
2525
"--name",
26-
"max-connections",
26+
limit_name,
2727
"--value",
2828
"1234",
2929
]);
30-
cmd.assert().success();
31-
32-
let mut cmd = Command::cargo_bin("rabbitmqadmin")?;
33-
cmd.args(["list", "vhost_limits"]);
34-
cmd.assert()
35-
.success()
36-
.stdout(predicate::str::contains("max-connections").and(predicate::str::contains("1234")));
37-
38-
let mut cmd = Command::cargo_bin("rabbitmqadmin")?;
39-
cmd.args(["delete", "vhost_limit", "--name", "max-connections"]);
40-
cmd.assert().success();
4130

42-
let mut cmd = Command::cargo_bin("rabbitmqadmin")?;
43-
cmd.args(["list", "vhost_limits"]);
44-
cmd.assert()
45-
.success()
46-
.stdout(predicate::str::contains("max-connections").not());
31+
run_succeeds(["list", "vhost_limits"])
32+
.stdout(predicate::str::contains(limit_name).and(predicate::str::contains("1234")));
33+
run_succeeds(["delete", "vhost_limit", "--name", limit_name]);
34+
run_succeeds(["list", "vhost_limits"]).stdout(predicate::str::contains(limit_name).not());
4735

4836
Ok(())
4937
}

tests/list_vhosts_tests.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::process::Command;
21
// Copyright (C) 2023-2024 RabbitMQ Core Team ([email protected])
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,15 +11,21 @@ use std::process::Command;
1211
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1312
// See the License for the specific language governing permissions and
1413
// limitations under the License.
15-
use assert_cmd::prelude::*;
1614
use predicates::prelude::*;
1715

16+
mod test_helpers;
17+
use crate::test_helpers::*;
18+
1819
#[test]
1920
fn list_vhosts() -> Result<(), Box<dyn std::error::Error>> {
20-
let mut cmd = Command::cargo_bin("rabbitmqadmin")?;
21+
let vh = "list_vhosts.1";
22+
delete_vhost(vh).expect("failed to delete a virtual host");
23+
24+
run_succeeds(["declare", "vhost", "--name", vh]);
25+
run_succeeds(["list", "vhosts"])
26+
.stdout(predicate::str::contains("/").and(predicate::str::contains(vh)));
2127

22-
cmd.arg("list").arg("vhosts");
23-
cmd.assert().success().stdout(predicate::str::contains("/"));
28+
delete_vhost(vh).expect("failed to delete a virtual host");
2429

2530
Ok(())
2631
}

0 commit comments

Comments
 (0)