Skip to content

Commit

Permalink
Test variations
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jul 23, 2024
1 parent d82b729 commit 5a3f838
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions tests/v2_schema_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2017,3 +2017,133 @@ fn test_v2_dependencies() -> Result<(), Box<dyn Error>> {

Ok(())
}

#[test]
fn test_v2_variations() -> Result<(), Box<dyn Error>> {
// Load the schemas and compile the maintainer schema.
let mut compiler = new_compiler("schema/v2")?;
let mut schemas = Schemas::new();
let id = id_for(SCHEMA_VERSION, "variations");
let idx = compiler.compile(&id, &mut schemas)?;

for valid in [
(
"one",
json!([{
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {"postgres": {"version": "14"}},
}]),
),
(
"two",
json!([
{
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {"postgres": {"version": "14"}},
},
{
"where": { "postgres": { "version": ">= 16.0" } },
"dependencies": {
"postgres": { "version": ">= 16.0", "with": ["zstd"] }
}
},
]),
),
(
"with x_",
json!([{
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {"postgres": {"version": "14"}},
"x_y": true,
}]),
),
(
"with X_",
json!([{
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {"postgres": {"version": "14"}},
"X_y": 42,
}]),
),
] {
if let Err(e) = schemas.validate(&valid.1, idx) {
panic!("extension {} failed: {e}", valid.0);
}
}

for invalid in [
("empty", json!([])),
("string", json!("web")),
("empty string", json!("")),
("true", json!(true)),
("false", json!(false)),
("null", json!(null)),
("object", json!({})),
("only x_", json!({"x_y": 0})),
("only X_", json!({"X_y": 0})),
(
"no dependencies",
json!({"where": { "platforms": ["darwin", "bsd"] }}),
),
(
"no where",
json!({"dependencies": { "platforms": ["darwin", "bsd"] }}),
),
(
"bare x_",
json!([{
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {"postgres": {"version": "14"}},
"x_": true,
}]),
),
(
"bare X_",
json!([{
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {"postgres": {"version": "14"}},
"X_": 42,
}]),
),
(
"unknown x_",
json!([{
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {"postgres": {"version": "14"}},
"foo": true,
}]),
),
(
"nested where",
json!([{
"where": {
"platforms": ["darwin", "bsd"],
"variations": {
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {"postgres": {"version": "14"}},
},
},
"dependencies": {"postgres": {"version": "14"}},
}]),
),
(
"nested dependencies",
json!([{
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {
"postgres": {"version": "14"},
"variations": {
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {"postgres": {"version": "14"}},
},
},
}]),
),
] {
if schemas.validate(&invalid.1, idx).is_ok() {
panic!("{} unexpectedly passed!", invalid.0)
}
}

Ok(())
}

0 comments on commit 5a3f838

Please sign in to comment.