api-macro: schema tests for async fns

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-01-08 11:01:55 +01:00
parent 943bc4de52
commit 5b652dbad8

View File

@ -32,6 +32,24 @@ pub async fn number(num: u32) -> Result<u32, Error> {
Ok(num)
}
#[test]
fn number_schema_check() {
const TEST_METHOD: ::proxmox::api::ApiMethod = ::proxmox::api::ApiMethod::new(
&::proxmox::api::ApiHandler::Async(&api_function_number),
&::proxmox::api::schema::ObjectSchema::new(
"Return the number...",
&[(
"num",
false,
&::proxmox::api::schema::IntegerSchema::new("The version to upgrade to").schema(),
)],
),
)
.protected(false);
assert_eq!(TEST_METHOD, API_METHOD_NUMBER);
}
#[api(
input: {
properties: {
@ -51,3 +69,28 @@ pub async fn more_async_params(param: Value) -> Result<(), Error> {
let _ = param;
Ok(())
}
#[test]
fn more_async_params_schema_check() {
const TEST_METHOD: ::proxmox::api::ApiMethod = ::proxmox::api::ApiMethod::new(
&::proxmox::api::ApiHandler::Async(&api_function_more_async_params),
&::proxmox::api::schema::ObjectSchema::new(
"Return the number...",
&[
(
"bar",
false,
&::proxmox::api::schema::StringSchema::new("The great Bar").schema(),
),
(
"foo",
false,
&::proxmox::api::schema::StringSchema::new("The great Foo").schema(),
),
],
),
)
.protected(false);
assert_eq!(TEST_METHOD, API_METHOD_MORE_ASYNC_PARAMS);
}