Skip to content

Commit

Permalink
Update all APISpec tests
Browse files Browse the repository at this point in the history
And add multiple specs files support
  • Loading branch information
jpraynaud committed Mar 16, 2023
1 parent b224c02 commit daaceb3
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 178 deletions.
98 changes: 54 additions & 44 deletions mithril-aggregator/src/http_server/routes/certificate_routes.rs
Expand Up @@ -86,8 +86,6 @@ mod handlers {

#[cfg(test)]
mod tests {
const API_SPEC_FILE: &str = "../openapi.yaml";

use crate::http_server::SERVER_BASE_PATH;
use mithril_common::store::adapter::FailStoreAdapter;
use mithril_common::test_utils::apispec::APISpec;
Expand Down Expand Up @@ -125,13 +123,15 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}

#[tokio::test]
Expand All @@ -147,13 +147,15 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}

#[tokio::test]
Expand All @@ -168,13 +170,15 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}

#[tokio::test]
Expand All @@ -195,13 +199,15 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}

#[tokio::test]
Expand All @@ -217,13 +223,15 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}

#[tokio::test]
Expand All @@ -244,12 +252,14 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}
}
34 changes: 18 additions & 16 deletions mithril-aggregator/src/http_server/routes/epoch_routes.rs
Expand Up @@ -84,8 +84,6 @@ mod handlers {

#[cfg(test)]
mod tests {
const API_SPEC_FILE: &str = "../openapi.yaml";

use crate::http_server::SERVER_BASE_PATH;
use mithril_common::test_utils::apispec::APISpec;
use serde_json::Value::Null;
Expand Down Expand Up @@ -120,13 +118,15 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}

#[tokio::test]
Expand All @@ -141,12 +141,14 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&Null)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}
}
65 changes: 36 additions & 29 deletions mithril-aggregator/src/http_server/routes/signatures_routes.rs
Expand Up @@ -56,7 +56,6 @@ mod handlers {

#[cfg(test)]
mod tests {
const API_SPEC_FILE: &str = "../openapi.yaml";

use crate::http_server::SERVER_BASE_PATH;
use mithril_common::messages::RegisterSignatureMessage;
Expand Down Expand Up @@ -106,13 +105,15 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&message)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&message)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}

#[tokio::test]
Expand All @@ -137,13 +138,15 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&message)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&message)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}

#[tokio::test]
Expand All @@ -170,13 +173,15 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&message)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&message)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}

#[tokio::test]
Expand All @@ -203,12 +208,14 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&message)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&message)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}
}
66 changes: 36 additions & 30 deletions mithril-aggregator/src/http_server/routes/signer_routes.rs
Expand Up @@ -116,8 +116,6 @@ mod handlers {

#[cfg(test)]
mod tests {
const API_SPEC_FILE: &str = "../openapi.yaml";

use mithril_common::crypto_helper::ProtocolRegistrationError;
use mithril_common::messages::RegisterSignerMessage;
use mithril_common::test_utils::apispec::APISpec;
Expand Down Expand Up @@ -165,13 +163,15 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&signer)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&signer)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}

#[tokio::test]
Expand All @@ -196,13 +196,15 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&signer)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&signer)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}

#[tokio::test]
Expand Down Expand Up @@ -230,13 +232,15 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&signer)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&signer)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}

#[tokio::test]
Expand All @@ -263,12 +267,14 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

APISpec::from_file(API_SPEC_FILE)
.method(method)
.path(path)
.validate_request(&signer)
.unwrap()
.validate_response(&response)
.expect("OpenAPI error");
for spec_file in APISpec::get_all_spec_files() {
APISpec::from_file(&spec_file)
.method(method)
.path(path)
.validate_request(&signer)
.unwrap()
.validate_response(&response)
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
}
}
}

0 comments on commit daaceb3

Please sign in to comment.