Skip to content

Commit c70caf6

Browse files
Test module refactoring
1 parent fa80867 commit c70caf6

25 files changed

+283
-301
lines changed

tests/bindings_tests.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
use predicates::prelude::*;
1516

1617
mod test_helpers;
@@ -78,21 +79,21 @@ fn test_list_bindings() -> Result<(), Box<dyn std::error::Error>> {
7879

7980
// list bindings in vhost 1
8081
run_succeeds(["-V", "bindings_vhost_1", "list", "bindings"]).stdout(
81-
predicate::str::contains("new_queue_1")
82-
.and(predicate::str::contains("routing_key_queue"))
83-
.and(predicate::str::contains("routing_key_exchange")),
82+
output_includes("new_queue_1")
83+
.and(output_includes("routing_key_queue"))
84+
.and(output_includes("routing_key_exchange")),
8485
);
8586

8687
// delete the queue from vhost 1
8788
run_succeeds(["-V", vh1, "queues", "delete", "--name", q1]);
8889

8990
// these bindings were deleted with the queue
9091
run_succeeds(["-V", "bindings_vhost_1", "list", "bindings"]).stdout(
91-
predicate::str::contains("new_queue_1")
92+
output_includes("new_queue_1")
9293
.not()
93-
.and(predicate::str::contains("routing_key_queue"))
94+
.and(output_includes("routing_key_queue"))
9495
.not()
95-
.and(predicate::str::contains("routing_key_exchange")),
96+
.and(output_includes("routing_key_exchange")),
9697
);
9798

9899
delete_vhost(vh1).expect("failed to delete a virtual host");
@@ -163,9 +164,9 @@ fn test_bindings_list() -> Result<(), Box<dyn std::error::Error>> {
163164

164165
// list bindings in vhost 1
165166
run_succeeds(["-V", vh1, "list", "bindings"]).stdout(
166-
predicate::str::contains("new_queue_1")
167-
.and(predicate::str::contains("routing_key_queue"))
168-
.and(predicate::str::contains("routing_key_exchange")),
167+
output_includes("new_queue_1")
168+
.and(output_includes("routing_key_queue"))
169+
.and(output_includes("routing_key_exchange")),
169170
);
170171

171172
// delete a binding
@@ -187,11 +188,11 @@ fn test_bindings_list() -> Result<(), Box<dyn std::error::Error>> {
187188

188189
// ensure that the deleted binding is no longer listed
189190
run_succeeds(["-V", vh1, "list", "bindings"]).stdout(
190-
predicate::str::contains("new_queue_1")
191+
output_includes("new_queue_1")
191192
.not()
192-
.and(predicate::str::contains("routing_key_queue"))
193+
.and(output_includes("routing_key_queue"))
193194
.not()
194-
.and(predicate::str::contains("routing_key_exchange")),
195+
.and(output_includes("routing_key_exchange")),
195196
);
196197

197198
delete_vhost(vh1).expect("failed to delete a virtual host");

tests/combined_integration_tests.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
use predicates::prelude::*;
1514
use std::path;
1615
use std::path::PathBuf;
1716

17+
use predicates::prelude::*;
18+
1819
mod test_helpers;
20+
use crate::test_helpers::output_includes;
1921
use test_helpers::{run_fails, run_succeeds};
2022

2123
#[test]
@@ -63,9 +65,8 @@ fn combined_integration_test2() -> Result<(), Box<dyn std::error::Error>> {
6365
vh,
6466
])
6567
.stderr(
66-
predicate::str::contains("specified configuration section (--node)").and(
67-
predicate::str::contains("was not found in the configuration file"),
68-
),
68+
output_includes("specified configuration section (--node)")
69+
.and(output_includes("was not found in the configuration file")),
6970
);
7071

7172
test_helpers::delete_vhost(vh)
@@ -90,7 +91,7 @@ fn combined_integration_test3() -> Result<(), Box<dyn std::error::Error>> {
9091
"--name",
9192
vh,
9293
])
93-
.stderr(predicate::str::contains("does not exist"));
94+
.stderr(output_includes("does not exist"));
9495

9596
test_helpers::delete_vhost(vh)
9697
}

tests/definitions_export_tests.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
use predicates::prelude::*;
1616

1717
mod test_helpers;
18-
use crate::test_helpers::delete_vhost;
18+
use crate::test_helpers::{delete_vhost, output_includes};
1919
use test_helpers::run_succeeds;
2020

2121
#[test]
2222
fn test_export_cluster_wide_definitions() -> Result<(), Box<dyn std::error::Error>> {
23-
run_succeeds(["definitions", "export"]).stdout(predicate::str::contains("guest"));
23+
run_succeeds(["definitions", "export"]).stdout(output_includes("guest"));
2424

2525
Ok(())
2626
}
@@ -36,10 +36,9 @@ fn test_export_vhost_definitions() -> Result<(), Box<dyn std::error::Error>> {
3636
"-V", vh, "declare", "queue", "--name", q, "--type", "quorum",
3737
]);
3838

39-
run_succeeds(["--vhost", vh, "definitions", "export_from_vhost"])
40-
.stdout(predicate::str::contains(q));
39+
run_succeeds(["--vhost", vh, "definitions", "export_from_vhost"]).stdout(output_includes(q));
4140
run_succeeds(["--vhost", "/", "definitions", "export_from_vhost"])
42-
.stdout(predicate::str::contains(q).not());
41+
.stdout(output_includes(q).not());
4342

4443
delete_vhost(vh).expect("failed to delete a virtual host");
4544

@@ -76,7 +75,7 @@ fn test_export_cluster_wide_definitions_with_transformations_case1()
7675
"-V", vh, "declare", "queue", "--name", q, "--type", "quorum",
7776
]);
7877

79-
run_succeeds(["--vhost", vh, "definitions", "export"]).stdout(predicate::str::contains(p1));
78+
run_succeeds(["--vhost", vh, "definitions", "export"]).stdout(output_includes(p1));
8079
// These two cannot be tested on 4.x: empty definitions will be rejected
8180
// by validation, and CMQ keys are no longer recognized as known/valid.
8281
// But at least we can test the code path this way.
@@ -88,7 +87,7 @@ fn test_export_cluster_wide_definitions_with_transformations_case1()
8887
"--transformations",
8988
"prepare_for_quorum_queue_migration,strip_cmq_keys_from_policies,drop_empty_policies",
9089
])
91-
.stdout(predicate::str::contains(p1));
90+
.stdout(output_includes(p1));
9291

9392
delete_vhost(vh).expect("failed to delete a virtual host");
9493

@@ -125,8 +124,7 @@ fn test_export_vhost_definitions_with_transformations_case1()
125124
"-V", vh, "declare", "queue", "--name", q, "--type", "quorum",
126125
]);
127126

128-
run_succeeds(["--vhost", vh, "definitions", "export_from_vhost"])
129-
.stdout(predicate::str::contains(p1));
127+
run_succeeds(["--vhost", vh, "definitions", "export_from_vhost"]).stdout(output_includes(p1));
130128
run_succeeds([
131129
"--vhost",
132130
vh,
@@ -135,7 +133,7 @@ fn test_export_vhost_definitions_with_transformations_case1()
135133
"--transformations",
136134
"prepare_for_quorum_queue_migration,strip_cmq_keys_from_policies,drop_empty_policies",
137135
])
138-
.stdout(predicate::str::contains(p1));
136+
.stdout(output_includes(p1));
139137

140138
delete_vhost(vh).expect("failed to delete a virtual host");
141139

tests/deprecated_feature_tests.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use predicates::prelude::*;
16-
1715
mod test_helpers;
1816
use crate::test_helpers::*;
1917

2018
#[test]
2119
fn test_list_all_deprecated_features() -> Result<(), Box<dyn std::error::Error>> {
22-
run_succeeds(["deprecated_features", "list"]).stdout(predicate::str::contains("ram_node_type"));
20+
run_succeeds(["deprecated_features", "list"]).stdout(output_includes("ram_node_type"));
2321

2422
Ok(())
2523
}
2624

2725
#[test]
2826
fn test_list_all_deprecated_features_via_alias() -> Result<(), Box<dyn std::error::Error>> {
29-
run_succeeds(["list", "deprecated_features"]).stdout(predicate::str::contains("ram_node_type"));
27+
run_succeeds(["list", "deprecated_features"]).stdout(output_includes("ram_node_type"));
3028

3129
Ok(())
3230
}

tests/exchange_federation_tests.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rabbitmq_http_client::commons::QueueType;
1616
use rabbitmq_http_client::requests::{ExchangeFederationParams, FederationUpstreamParams};
1717

1818
mod test_helpers;
19-
use crate::test_helpers::{amqp_endpoint_with_vhost, delete_vhost};
19+
use crate::test_helpers::{amqp_endpoint_with_vhost, delete_vhost, output_includes};
2020
use test_helpers::{run_fails, run_succeeds};
2121

2222
#[test]
@@ -200,9 +200,7 @@ fn test_federation_upstream_declaration_for_exchange_federation_case3()
200200
"--queue-type",
201201
&xfp.queue_type.to_string(),
202202
])
203-
.stderr(predicate::str::contains(
204-
"required arguments were not provided",
205-
));
203+
.stderr(output_includes("required arguments were not provided"));
206204

207205
delete_vhost(vh).expect("failed to delete a virtual host");
208206

@@ -290,10 +288,10 @@ fn test_federation_list_all_upstreams_with_exchange_federation()
290288
]);
291289

292290
run_succeeds(["-V", vh, "federation", "list_all_upstreams"])
293-
.stdout(predicate::str::contains(name))
294-
.stdout(predicate::str::contains(endpoint1.clone()))
295-
.stdout(predicate::str::contains(x))
296-
.stdout(predicate::str::contains(queue_type.to_string()));
291+
.stdout(output_includes(name))
292+
.stdout(output_includes(&endpoint1))
293+
.stdout(output_includes(x))
294+
.stdout(output_includes(&queue_type.to_string()));
297295

298296
delete_vhost(vh).expect("failed to delete a virtual host");
299297

@@ -339,10 +337,10 @@ fn test_federation_delete_an_upstream_with_exchange_federation_settings()
339337
]);
340338

341339
run_succeeds(["-V", vh, "federation", "list_all_upstreams"])
342-
.stdout(predicate::str::contains(name))
343-
.stdout(predicate::str::contains(endpoint1.clone()))
344-
.stdout(predicate::str::contains(x))
345-
.stdout(predicate::str::contains(queue_type.to_string()));
340+
.stdout(output_includes(name))
341+
.stdout(output_includes(&endpoint1))
342+
.stdout(output_includes(x))
343+
.stdout(output_includes(&queue_type.to_string()));
346344

347345
run_succeeds([
348346
"-V",
@@ -354,7 +352,7 @@ fn test_federation_delete_an_upstream_with_exchange_federation_settings()
354352
]);
355353

356354
run_succeeds(["-V", vh, "federation", "list_all_upstreams"])
357-
.stdout(predicate::str::contains(name).not());
355+
.stdout(output_includes(name).not());
358356

359357
delete_vhost(vh).expect("failed to delete a virtual host");
360358

0 commit comments

Comments
 (0)