Skip to content

Commit 914c022

Browse files
minor: improve unified test skipping functionality (#882)
1 parent ea4b9a5 commit 914c022

File tree

4 files changed

+41
-46
lines changed

4 files changed

+41
-46
lines changed

src/test/spec/client_side_encryption.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use crate::test::{
1010
async fn run_unified() {
1111
let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await;
1212

13-
#[cfg(not(feature = "openssl-tls"))]
14-
let skipped_tests = &["create datakey with KMIP KMS provider"];
15-
#[cfg(feature = "openssl-tls")]
16-
let skipped_tests = &[];
13+
let mut skipped_tests = vec![];
14+
if cfg!(not(feature = "openssl-tls")) {
15+
skipped_tests.push("create datakey with KMIP KMS provider");
16+
}
1717

1818
run_unified_tests(&["client-side-encryption", "unified"])
19-
.skip_tests(skipped_tests)
19+
.skip_tests(&skipped_tests)
2020
.await;
2121
}
2222

@@ -25,13 +25,13 @@ async fn run_unified() {
2525
async fn run_legacy() {
2626
let _guard: RwLockWriteGuard<()> = LOCK.run_exclusively().await;
2727

28-
// TODO RUST-528: Unskip timeoutMS.json when CSOT is implemented.
29-
#[cfg(not(feature = "openssl-tls"))]
30-
let skipped_files = &["timeoutMS.json", "kmipKMS.json"];
31-
#[cfg(feature = "openssl-tls")]
32-
let skipped_files = &["timeoutMS.json"];
28+
// TODO RUST-528: unskip this file
29+
let mut skipped_files = vec!["timeoutMS.json"];
30+
if cfg!(not(feature = "openssl-tls")) {
31+
skipped_files.push("kmipKMS.json");
32+
}
3333

3434
run_v2_tests(&["client-side-encryption", "legacy"])
35-
.skip_files(skipped_files)
35+
.skip_files(&skipped_files)
3636
.await;
3737
}

src/test/spec/unified_runner/mod.rs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,25 @@ pub(crate) fn run_unified_tests(spec: &'static [&'static str]) -> RunUnifiedTest
4343
type FileTransformation = Box<dyn Fn(&mut TestFile) + Send + Sync>;
4444
pub(crate) struct RunUnifiedTestsAction {
4545
spec: &'static [&'static str],
46-
skipped_files: Option<&'static [&'static str]>,
47-
skipped_tests: Option<&'static [&'static str]>,
46+
skipped_files: Option<Vec<&'static str>>,
47+
skipped_tests: Option<Vec<&'static str>>,
4848
file_transformation: Option<FileTransformation>,
4949
}
5050

5151
impl RunUnifiedTestsAction {
5252
/// The files to skip deserializing. The provided filenames should only contain the filename and
5353
/// extension, e.g. "unacknowledged-writes.json". Filenames are matched case-sensitively.
54-
pub(crate) fn skip_files(self, skipped_files: &'static [&'static str]) -> Self {
54+
pub(crate) fn skip_files(self, skipped_files: &[&'static str]) -> Self {
5555
Self {
56-
skipped_files: Some(skipped_files),
56+
skipped_files: Some(skipped_files.to_vec()),
5757
..self
5858
}
5959
}
6060

6161
/// The descriptions of the tests to skip. Test descriptions are matched case-sensitively.
62-
pub(crate) fn skip_tests(self, skipped_tests: &'static [&'static str]) -> Self {
62+
pub(crate) fn skip_tests(self, skipped_tests: &[&'static str]) -> Self {
6363
Self {
64-
skipped_tests: Some(skipped_tests),
64+
skipped_tests: Some(skipped_tests.to_vec()),
6565
..self
6666
}
6767
}
@@ -85,15 +85,15 @@ impl IntoFuture for RunUnifiedTestsAction {
8585
fn into_future(self) -> Self::IntoFuture {
8686
async move {
8787
for (mut test_file, path) in
88-
deserialize_spec_tests::<TestFile>(self.spec, self.skipped_files)
88+
deserialize_spec_tests::<TestFile>(self.spec, self.skipped_files.as_deref())
8989
{
9090
if let Some(ref file_transformation) = self.file_transformation {
9191
file_transformation(&mut test_file);
9292
}
9393

9494
let test_runner = TestRunner::new().await;
9595
test_runner
96-
.run_test(test_file, path, self.skipped_tests)
96+
.run_test(test_file, path, self.skipped_tests.as_ref())
9797
.await;
9898
}
9999
}
@@ -105,34 +105,31 @@ impl IntoFuture for RunUnifiedTestsAction {
105105
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
106106
async fn valid_pass() {
107107
let _guard: RwLockWriteGuard<_> = LOCK.run_exclusively().await;
108-
#[cfg(feature = "in-use-encryption-unstable")]
109-
let skipped_files = &[
110-
// TODO RUST-1570: unskip this file (ditto below)
108+
109+
let mut skipped_files = vec![
110+
// TODO RUST-1570: unskip this file
111111
"collectionData-createOptions.json",
112-
// TODO RUST-1405: unskip this file (ditto below)
112+
// TODO RUST-1405: unskip this file
113113
"expectedError-errorResponse.json",
114-
// TODO RUST-582: unskip these files (ditto below)
114+
// TODO RUST-582: unskip these files
115115
"entity-cursor-iterateOnce.json",
116116
"matches-lte-operator.json",
117117
// TODO: unskip this file when the convenient transactions API tests are converted to the
118-
// unified format (ditto below)
118+
// unified format
119119
"poc-transactions-convenient-api.json",
120120
];
121-
#[cfg(not(feature = "in-use-encryption-unstable"))]
122-
let skipped_files = &[
123-
"collectionData-createOptions.json",
124-
"expectedError-errorResponse.json",
125-
"entity-cursor-iterateOnce.json",
126-
"matches-lte-operator.json",
127-
"poc-transactions-convenient-api.json",
128-
// These tests need the in-use-encryption-unstable feature flag to be deserialized and run.
129-
"kmsProviders-placeholder_kms_credentials.json",
130-
"kmsProviders-unconfigured_kms.json",
131-
"kmsProviders-explicit_kms_credentials.json",
132-
"kmsProviders-mixed_kms_credential_fields.json",
133-
];
121+
// These tests need the in-use-encryption-unstable feature flag to be deserialized and run.
122+
if cfg!(not(feature = "in-use-encryption-unstable")) {
123+
skipped_files.extend(&[
124+
"kmsProviders-placeholder_kms_credentials.json",
125+
"kmsProviders-unconfigured_kms.json",
126+
"kmsProviders-explicit_kms_credentials.json",
127+
"kmsProviders-mixed_kms_credential_fields.json",
128+
]);
129+
}
130+
134131
run_unified_tests(&["unified-test-format", "valid-pass"])
135-
.skip_files(skipped_files)
132+
.skip_files(&skipped_files)
136133
// This test relies on old OP_QUERY behavior that many drivers still use for < 4.4, but
137134
// we do not use, due to never implementing OP_QUERY.
138135
.skip_tests(&["A successful find event with a getmore and the server kills the cursor (<= 4.4)"])

src/test/spec/unified_runner/test_runner.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl TestRunner {
110110
&self,
111111
test_file: TestFile,
112112
path: impl Into<Option<PathBuf>>,
113-
skipped_tests: impl Into<Option<&'static [&'static str]>>,
113+
skipped_tests: Option<&Vec<&str>>,
114114
) {
115115
let schema_version = &test_file.schema_version;
116116
assert!(
@@ -119,8 +119,6 @@ impl TestRunner {
119119
schema_version
120120
);
121121

122-
let skipped_tests = skipped_tests.into();
123-
124122
let test_description = match path.into() {
125123
Some(path) => format!("{} ({:?})", &test_file.description, path),
126124
None => test_file.description.clone(),

src/test/spec/v2_runner/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ pub(crate) fn run_v2_tests(spec: &'static [&'static str]) -> RunV2TestsAction {
5858

5959
pub(crate) struct RunV2TestsAction {
6060
spec: &'static [&'static str],
61-
skipped_files: Option<&'static [&'static str]>,
61+
skipped_files: Option<Vec<&'static str>>,
6262
}
6363

6464
impl RunV2TestsAction {
65-
pub(crate) fn skip_files(self, skipped_files: &'static [&'static str]) -> Self {
65+
pub(crate) fn skip_files(self, skipped_files: &[&'static str]) -> Self {
6666
Self {
67-
skipped_files: Some(skipped_files),
67+
skipped_files: Some(skipped_files.to_vec()),
6868
..self
6969
}
7070
}
@@ -77,7 +77,7 @@ impl IntoFuture for RunV2TestsAction {
7777
fn into_future(self) -> Self::IntoFuture {
7878
async move {
7979
for (test_file, path) in
80-
deserialize_spec_tests::<TestFile>(self.spec, self.skipped_files)
80+
deserialize_spec_tests::<TestFile>(self.spec, self.skipped_files.as_deref())
8181
{
8282
run_v2_test(path, test_file).await;
8383
}

0 commit comments

Comments
 (0)