Skip to content

Commit

Permalink
test: Add a test case for #343
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Feb 25, 2022
1 parent 778b424 commit 9d391bf
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
23 changes: 22 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- run: pre-commit run --all-files
working-directory: ./bindings/python

test-stable:
test-drafts:
strategy:
fail-fast: false
matrix:
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions jsonschema/instance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "./schema.json",
"people": [
{
"forename": "David",
"surname": "Flanagan",
"email": "[email protected]",
"employers": [
"Pulumi"
]
}
],
"organizations": [
{
"name": "Pulumi"
}
]
}
27 changes: 27 additions & 0 deletions jsonschema/schema.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
15 changes: 15 additions & 0 deletions jsonschema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

0 comments on commit 9d391bf

Please sign in to comment.