Skip to content

Commit 93ffc71

Browse files
Sync valid-pass unified format tests (#1342)
1 parent e281c16 commit 93ffc71

29 files changed

+1657
-95
lines changed

src/bson_util.rs

+13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ pub(crate) fn get_int(val: &Bson) -> Option<i64> {
3434
}
3535
}
3636

37+
/// Coerce numeric types into an `f64` if it would be lossless to do so. If this Bson is not numeric
38+
/// or the conversion would be lossy (e.g. 1.5 -> 1), this returns `None`.
39+
#[cfg(test)]
40+
#[allow(clippy::cast_possible_truncation)]
41+
pub(crate) fn get_double(val: &Bson) -> Option<f64> {
42+
match *val {
43+
Bson::Int32(i) => Some(f64::from(i)),
44+
Bson::Int64(i) if i == i as f64 as i64 => Some(i as f64),
45+
Bson::Double(f) => Some(f),
46+
_ => None,
47+
}
48+
}
49+
3750
/// Coerce numeric types into an `i64` if it would be lossless to do so. If this Bson is not numeric
3851
/// or the conversion would be lossy (e.g. 1.5 -> 1), this returns `None`.
3952
pub(crate) fn get_int_raw(val: RawBsonRef<'_>) -> Option<i64> {

src/test/spec/json/unified-test-format/Makefile

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
SCHEMA=../schema-1.13.json
1+
SCHEMA=../schema-1.23.json
22

3-
.PHONY: all invalid valid-fail valid-pass versioned-api load-balancers gridfs transactions crud collection-management sessions command-logging-and-monitoring client-side-operations-timeout HAS_AJV
3+
.PHONY: all invalid valid-fail valid-pass atlas-data-lake versioned-api load-balancers gridfs transactions transactions-convenient-api crud collection-management read-write-concern retryable-reads retryable-writes sessions command-logging-and-monitoring client-side-operations-timeout HAS_AJV
44

5-
all: invalid valid-fail valid-pass versioned-api load-balancers gridfs transactions change-streams crud collection-management sessions command-logging-and-monitoring client-side-operations-timeout
5+
all: invalid valid-fail valid-pass atlas-data-lake versioned-api load-balancers gridfs transactions transactions-convenient-api change-streams crud collection-management read-write-concern retryable-reads retryable-writes sessions command-logging-and-monitoring client-side-operations-timeout client-side-encryption
66

77
invalid: HAS_AJV
88
@# Redirect stdout to hide expected validation errors
@@ -14,6 +14,9 @@ valid-fail: HAS_AJV
1414
valid-pass: HAS_AJV
1515
@ajv test -s $(SCHEMA) -d "valid-pass/*.yml" --valid
1616

17+
atlas-data-lake: HAS_AJV
18+
@ajv test -s $(SCHEMA) -d "../../atlas-data-lake-testing/tests/unified/*.yml" --valid
19+
1720
versioned-api: HAS_AJV
1821
@ajv test -s $(SCHEMA) -d "../../versioned-api/tests/*.yml" --valid
1922

@@ -26,6 +29,9 @@ gridfs: HAS_AJV
2629
transactions: HAS_AJV
2730
@ajv test -s $(SCHEMA) -d "../../transactions/tests/unified/*.yml" --valid
2831

32+
transactions-convenient-api: HAS_AJV
33+
@ajv test -s $(SCHEMA) -d "../../transactions-convenient-api/tests/unified/*.yml" --valid
34+
2935
change-streams: HAS_AJV
3036
@ajv test -s $(SCHEMA) -d "../../change-streams/tests/unified/*.yml" --valid
3137

@@ -38,13 +44,25 @@ crud: HAS_AJV
3844
collection-management: HAS_AJV
3945
@ajv test -s $(SCHEMA) -d "../../collection-management/tests/*.yml" --valid
4046

47+
read-write-concern: HAS_AJV
48+
@ajv test -s $(SCHEMA) -d "../../read-write-concern/tests/operation/*.yml" --valid
49+
50+
retryable-reads: HAS_AJV
51+
@ajv test -s $(SCHEMA) -d "../../retryable-reads/tests/unified/*.yml" --valid
52+
53+
retryable-writes: HAS_AJV
54+
@ajv test -s $(SCHEMA) -d "../../retryable-writes/tests/unified/*.yml" --valid
55+
4156
sessions: HAS_AJV
4257
@ajv test -s $(SCHEMA) -d "../../sessions/tests/*.yml" --valid
4358

4459
command-logging-and-monitoring: HAS_AJV
4560
@ajv test -s $(SCHEMA) -d "../../command-logging-and-monitoring/tests/logging/*.yml" --valid
4661
@ajv test -s $(SCHEMA) -d "../../command-logging-and-monitoring/tests/monitoring/*.yml" --valid
4762

63+
client-side-encryption: HAS_AJV
64+
@ajv test -s $(SCHEMA) -d "../../client-side-encryption/tests/unified/*.yml" --valid
65+
4866
HAS_AJV:
4967
@if ! command -v ajv > /dev/null; then \
5068
echo 'Error: need "npm install -g ajv-cli"' 1>&2; \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Unified Test Format Tests
2+
3+
______________________________________________________________________
4+
5+
## Introduction
6+
7+
This directory contains tests for the Unified Test Format's schema and test runner implementation(s). Tests are
8+
organized in the following directories:
9+
10+
- `invalid`: These files do not validate against the schema and are used to test the schema itself.
11+
- `valid-pass`: These files validate against the schema and should pass when executed with a test runner.
12+
- `valid-fail`: These files validate against the schema but should produce runtime errors or failures when executed with
13+
a test runner. Some do so by violating the "SHOULD" and "SHOULD NOT" guidance in the spec (e.g. referencing an
14+
undefined entity).
15+
16+
## Validating Test Files
17+
18+
JSON and YAML test files can be validated using [Ajv](https://ajv.js.org/) and a schema from the parent directory (e.g.
19+
`schema-1.0.json`).
20+
21+
Test files can be validated individually like so:
22+
23+
```bash
24+
ajv -s ../schema-1.0.json -d path/to/test.yml
25+
```
26+
27+
Ajv can also be used to assert the validity of test files:
28+
29+
```bash
30+
ajv test -s ../schema-1.0.json -d "invalid/*.yml" --invalid
31+
ajv test -s ../schema-1.0.json -d "valid-*/*.yml" --valid
32+
```

src/test/spec/json/unified-test-format/README.rst

-39
This file was deleted.

0 commit comments

Comments
 (0)