Skip to content

Commit

Permalink
Factorize api spec verification tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Mar 17, 2023
1 parent ec49f73 commit 4007a09
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 217 deletions.
102 changes: 48 additions & 54 deletions mithril-aggregator/src/http_server/routes/certificate_routes.rs
Expand Up @@ -123,15 +123,14 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&Null,
&response,
);
}

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

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&Null,
&response,
);
}

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

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&Null,
&response,
);
}

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

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&Null,
&response,
);
}

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

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&Null,
&response,
);
}

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

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&Null,
&response,
);
}
}
34 changes: 16 additions & 18 deletions mithril-aggregator/src/http_server/routes/epoch_routes.rs
Expand Up @@ -118,15 +118,14 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&Null,
&response,
);
}

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

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&Null,
&response,
);
}
}
68 changes: 32 additions & 36 deletions mithril-aggregator/src/http_server/routes/signatures_routes.rs
Expand Up @@ -105,15 +105,14 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&message,
&response,
);
}

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

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&message,
&response,
);
}

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

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&message,
&response,
);
}

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

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&message,
&response,
);
}
}
68 changes: 32 additions & 36 deletions mithril-aggregator/src/http_server/routes/signer_routes.rs
Expand Up @@ -163,15 +163,14 @@ mod tests {
.reply(&setup_router(Arc::new(dependency_manager)))
.await;

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&signer,
&response,
);
}

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

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&signer,
&response,
);
}

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

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&signer,
&response,
);
}

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

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));
}
APISpec::verify_conformity(
APISpec::get_all_spec_files(),
method,
path,
"application/json",
&signer,
&response,
);
}
}

0 comments on commit 4007a09

Please sign in to comment.