test: Add a test case for #343

This commit is contained in:
Dmitry Dygalo 2022-02-25 15:03:03 +01:00
parent 778b424b3d
commit 9d391bff7c
No known key found for this signature in database
GPG Key ID: 0D78E60518FE18BB
4 changed files with 82 additions and 1 deletions

View File

@ -33,7 +33,7 @@ jobs:
- run: pre-commit run --all-files
working-directory: ./bindings/python
test-stable:
test-drafts:
strategy:
fail-fast: false
matrix:
@ -55,6 +55,27 @@ jobs:
- run: cargo test --no-fail-fast --features ${{ matrix.draft }}
working-directory: ./jsonschema
test-stable:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
name: Test (stable) on ${{ matrix.os}}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: cargo test --no-fail-fast
working-directory: ./jsonschema
coverage:
name: Run test coverage
runs-on: ubuntu-latest

18
jsonschema/instance.json Normal file
View File

@ -0,0 +1,18 @@
{
"$schema": "./schema.json",
"people": [
{
"forename": "David",
"surname": "Flanagan",
"email": "david@rawkode.dev",
"employers": [
"Pulumi"
]
}
],
"organizations": [
{
"name": "Pulumi"
}
]
}

27
jsonschema/schema.json Normal file
View File

@ -0,0 +1,27 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"people": {
"type": "array",
"items": {
"$ref": "https://schema.rawkode.dev/person"
},
"links": [
{
"rel": "collection",
"href": "#/organizations/{id}",
"templateRequired": [
"id"
]
}
]
},
"organizations": {
"type": "array",
"items": {
"$ref": "https://schema.rawkode.dev/organization"
}
}
}
}

View File

@ -237,4 +237,19 @@ mod tests {
let schema = json!({"pattern": "\\u"});
assert!(JSONSchema::compile(&schema).is_err())
}
#[test]
fn issue_343() {
let file = std::fs::File::open("schema.json").unwrap();
let reader = std::io::BufReader::new(file);
let schema = serde_json::from_reader(reader).unwrap();
let file = std::fs::File::open("instance.json").unwrap();
let reader = std::io::BufReader::new(file);
let instance = serde_json::from_reader(reader).unwrap();
let compiled = JSONSchema::compile(&schema).expect("A valid schema");
let result = compiled.validate(&instance);
assert!(result.is_ok())
}
}