Skip to content

Commit

Permalink
Test dependencies schema
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jul 23, 2024
1 parent 6b445b8 commit d82b729
Show file tree
Hide file tree
Showing 3 changed files with 375 additions and 2 deletions.
109 changes: 108 additions & 1 deletion schema/v2/dependencies.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,112 @@
],
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false,
"examples": []
"examples": [
{ "postgres": { "version": "14.0" } },
{
"postgres": {
"version": ">= 12.0, < 17.0",
"with": ["xml", "uuid", "perl"]
},
"pipeline": "pgxs",
"packages": {
"build": {
"requires": {
"pkg:generic/awk": 0,
"pkg:generic/perl": "5.20"
},
"recommends": {
"pkg:generic/jq": 0,
"pkg:generic/perl": "5.40"
}
}
}
},
{
"pipeline": "pgrx",
"platforms": [
"linux-amd64",
"linux-amd64v3",
"gnulinux-arm64",
"musllinux-amd64",
"darwin-23.5.0-arm64"
],
"packages": {
"configure": {
"requires": { "pkg:cargo/cargo-pgrx": "==0.11.4" }
},
"test": {
"requires": {
"pkg:postgres/pg_regress": 0,
"pkg:postgres/plpgsql": 0,
"pkg:pgxn/pgtap": "1.1.0"
}
},
"run": {
"requires": {
"pkg:postgres/plperl": 0,
"pkg:pgxn/hostname": 0
}
}
}
},
{
"postgres": {
"version": ">= 15.0, < 16.0"
},
"pipeline": "pgxs",
"platforms": [
"linux-amd64",
"linux-arm64",
"darwin-amd64",
"darwin-arm64"
],
"packages": {
"configure": {
"requires": {
"pkg:cargo/cargo-pgrx": "==0.11.4",
"pkg:generic/bison": 0,
"pkg:generic/cmake": 0,
"pkg:generic/flex": 0,
"pkg:generic/readline": 0,
"pkg:generic/openssl": 0,
"pkg:generic/pkg-config": 0
}
},
"run": {
"requires": {
"pkg:generic/penblas": 0,
"pkg:generic/python3": 0,
"pkg:generic/readline": 0,
"pkg:generic/openssl": 0,
"pkg:generic/bison": 0
},
"recommends": {
"pkg:pypi/pyarrow": "11.0.0",
"pkg:pypi/catboost": 0,
"pkg:pypi/lightgbm": 0,
"pkg:pypi/torch": 0,
"pkg:pypi/langchain": 0
}
}
},
"variations": [
{
"where": {
"platforms": ["linux"]
},
"dependencies": {
"packages": {
"run": {
"recommends": {
"pkg:pypi/auto-gptq": 0,
"pkg:pypi/xformers": 0
}
}
}
}
}
]
}
]
}
12 changes: 11 additions & 1 deletion schema/v2/pipeline.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@
"$id": "https://pgxn.org/meta/v2/pipeline.schema.json",
"title": "Pipeline",
"description": "The build pipeline required to configure, build, test, and install the package provided by the distribution.",
"enum": ["pgxs", "meson", "pgrx", "autoconf", "npm", "cpanm", "go", "cargo"]
"enum": [
"pgxs",
"meson",
"pgrx",
"autoconf",
"cmake",
"npm",
"cpanm",
"go",
"cargo"
]
}
256 changes: 256 additions & 0 deletions tests/v2_schema_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,7 @@ fn test_v2_pipeline() -> Result<(), Box<dyn Error>> {
json!("meson"),
json!("pgrx"),
json!("autoconf"),
json!("cmake"),
json!("npm"),
json!("cpanm"),
json!("go"),
Expand Down Expand Up @@ -1761,3 +1762,258 @@ fn test_v2_pipeline() -> Result<(), Box<dyn Error>> {
}
Ok(())
}

#[test]
fn test_v2_dependencies() -> 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, "dependencies");
let idx = compiler.compile(&id, &mut schemas)?;

for valid in [
("postgres", json!({"postgres": {"version": "14"}})),
(
"pg with",
json!({"postgres": {"version": "14", "with": ["xml"]}}),
),
("any", json!({"platforms": ["any"]})),
("linux", json!({"platforms": ["linux"]})),
("2platform", json!({"platforms": ["linux", "darwin"]})),
("pgxs", json!({"pipeline": "pgxs"})),
("pgrx", json!({"pipeline": "pgrx"})),
(
"configure",
json!({"packages": {
"configure": { "requires": { "pkg:generic/cmake": 0} }
}}),
),
(
"test",
json!({"packages": {
"test": { "requires": { "pkg:pgxn/pgtap": "1.0.0" } }
}}),
),
(
"packages",
json!({"packages": {
"configure": { "requires": { "pkg:generic/cmake": 0 } },
"build": { "recommends": { "pkg:generic/jq": 0 } },
"test": { "requires": { "pkg:pgxn/pgtap": "1.0.0" } },
"run": { "suggests": { "pkg:postgres/hstore": 0 } },
"develop": { "suggests": { "pkg:generic/python": 0 } },
}}),
),
(
"variation",
json!({"variations": [
{
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {"postgres": {"version": "14"}},
}
]}),
),
(
"variations",
json!({"variations": [
{
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {"postgres": {"version": "14"}},
},
{
"where": { "postgres": { "version": ">= 16.0" } },
"dependencies": {
"postgres": { "version": ">= 16.0", "with": ["zstd"] }
}
},
]}),
),
("custom x_", json!({"pipeline": "pgxs", "x_y": 1})),
("custom X_", json!({"pipeline": "pgxs", "X_z": true})),
(
"everything",
json!({
"postgres": {"version": "14", "with": ["xml"]},
"platforms": ["linux", "darwin"],
"pipeline": "pgrx",
"packages": {
"configure": { "requires": { "pkg:generic/cmake": 0 } },
"build": { "recommends": { "pkg:generic/jq": 0 } },
"test": { "requires": { "pkg:pgxn/pgtap": "1.0.0" } },
"run": { "suggests": { "pkg:postgres/hstore": 0 } },
"develop": { "suggests": { "pkg:generic/python": 0 } },
},
"variations": [
{
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {"postgres": {"version": "14"}},
},
]
}),
),
] {
if let Err(e) = schemas.validate(&valid.1, idx) {
panic!("extension {} failed: {e}", valid.0);
}
}

for invalid in [
("array", json!([])),
("string", json!("web")),
("empty string", json!("")),
("true", json!(true)),
("false", json!(false)),
("null", json!(null)),
("empty object", json!({})),
("only x_", json!({"x_y": 0})),
("only X_", json!({"X_y": 0})),
("bare x_", json!({"pipeline": "pgxs", "x_": 0})),
("bare X_", json!({"pipeline": "pgxs", "x_": 0})),
("unknown", json!({"pipeline": "pgxs", "foo": 0})),
// postgres
("postgres array", json!({"postgres": ["2.0.0"]})),
("postgres empty", json!({"postgres": {}})),
("postgres string", json!({"postgres": ""})),
("postgres bool", json!({"postgres": true})),
("postgres number", json!({"postgres": 42})),
("postgres null", json!({"postgres": null})),
(
"postgres version array",
json!({"postgres": {"version": ["2.0.0"]}}),
),
(
"postgres version empty",
json!({"postgres": {"version": [""]}}),
),
(
"postgres version bool",
json!({"postgres": {"version": [true]}}),
),
(
"postgres version number",
json!({"postgres": {"version": [42]}}),
),
(
"postgres version null",
json!({"postgres": {"version": [null]}}),
),
(
"postgres version invalid",
json!({"postgres": {"version": "x.y.z"}}),
),
("postgres with empty", json!({"postgres": {"with": []}})),
("postgres with null", json!({"postgres": {"with": null}})),
("postgres with bool", json!({"postgres": {"with": true}})),
("postgres with number", json!({"postgres": {"with": 42}})),
("postgres with object", json!({"postgres": {"with": {}}})),
(
"postgres with empty string item",
json!({"postgres": {"with": [""]}}),
),
(
"postgres with short string item",
json!({"postgres": {"with": ["x"]}}),
),
(
"postgres with null item",
json!({"postgres": {"with": [null]}}),
),
(
"postgres with bool item",
json!({"postgres": {"with": [false]}}),
),
(
"postgres with number item",
json!({"postgres": {"with": [42]}}),
),
(
"postgres with array item",
json!({"postgres": {"with": [["xml"]]}}),
),
(
"postgres with object item",
json!({"postgres": {"with": {}}}),
),
// platforms
("platforms empty", json!({"platforms": []})),
("platforms object", json!({"platforms": {}})),
("platforms string", json!({"platforms": ""})),
("platforms bool", json!({"platforms": true})),
("platforms number", json!({"platforms": 42})),
("platforms null", json!({"platforms": null})),
("platforms empty string", json!({"platforms": [""]})),
("platforms short string", json!({"platforms": ["x"]})),
("platforms item array", json!({"platforms": [[]]})),
("platforms item object", json!({"platforms": [{}]})),
("platforms item empty string", json!({"platforms": [""]})),
("platforms item bool", json!({"platforms": [true]})),
("platforms item number", json!({"platforms": [42]})),
("platforms item null", json!({"platforms": [null]})),
// pipeline
("pipeline empty", json!({"pipeline": ""})),
("pipeline invalid", json!({"pipeline": "nope"})),
("pipeline object", json!({"pipeline": {}})),
("pipeline bool", json!({"pipeline": true})),
("pipeline number", json!({"pipeline": 42})),
("pipeline null", json!({"pipeline": null})),
// packages
("packages array", json!({"packages": []})),
("packages empty", json!({"packages": {}})),
("packages string", json!({"packages": ""})),
("packages bool", json!({"packages": true})),
("packages number", json!({"packages": 42})),
("packages null", json!({"packages": null})),
// configure
(
"packages configure array",
json!({"packages": {"configure": []}}),
),
("packages build empty", json!({"packages": {"build": {}}})),
("packages test string", json!({"packages": {"test": "hi"}})),
("packages run bool", json!({"packages": {"run": true}})),
("packages run null", json!({"packages": {"run": null}})),
(
"packages develop number",
json!({"packages": {"develop": 42}}),
),
// variations
("variations empty", json!({"variations": []})),
("variations object", json!({"variations": {}})),
("variations string", json!({"variations": ""})),
("variations bool", json!({"variations": true})),
("variations number", json!({"variations": 42})),
("variations null", json!({"variations": null})),
(
"nested where variations",
json!({"variations": [
{
"where": {
"platforms": ["darwin", "bsd"],
"variations": {"pipeline": "pgxs"},
},
"dependencies": {
"postgres": {"version": "14"},
},
}
]}),
),
(
"nested dependencies variations",
json!({"variations": [
{
"where": { "platforms": ["darwin", "bsd"] },
"dependencies": {
"postgres": {"version": "14"},
"variations": {"pipeline": "pgxs"},
},
}
]}),
),
] {
if schemas.validate(&invalid.1, idx).is_ok() {
panic!("{} unexpectedly passed!", invalid.0)
}
}

Ok(())
}

0 comments on commit d82b729

Please sign in to comment.