-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speed up the schema definition tests in CI. (#146)
### What The OpenAPI schema definition tests can take several minutes to run, for two reasons: 1. The tests call `cargo run`, which can trigger recompilation of all dependencies if they haven't been built for this specific target before. 2. On CI, the tests were running in "debug" mode, which means they couldn't make use of the shared build cache, and were taking a few minutes as opposed to, well, less time than that. ### How I have made sure the tests run in release mode on CI (and added `cargo nextest` so things are consistent with the other test jobs). I rewrote the schema definition generator to expose a helper function which can be called directly by tests, rather than using `cargo` to rebuild and rerun the program. I also removed the Rust cache used by the formatting job because it doesn't actually compile code, which can mean that it ends up writing an empty cache, forcing all other jobs to recompile.
- Loading branch information
1 parent
8602578
commit d2b901d
Showing
3 changed files
with
22 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
use std::io; | ||
|
||
use ndc_postgres::configuration::RawConfiguration; | ||
use schemars::{gen::SchemaSettings, schema::RootSchema}; | ||
|
||
fn main() { | ||
let schema: RootSchema = SchemaSettings::openapi3() | ||
.into_generator() | ||
.into_root_schema_for::<RawConfiguration>(); | ||
fn main() -> io::Result<()> { | ||
let schema = generate_schema(); | ||
serde_json::to_writer_pretty(io::stdout(), &schema)?; | ||
Ok(()) | ||
} | ||
|
||
println!("{}", serde_json::to_string_pretty(&schema).unwrap()); | ||
fn generate_schema() -> RootSchema { | ||
SchemaSettings::openapi3() | ||
.into_generator() | ||
.into_root_schema_for::<RawConfiguration>() | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::process::Command; | ||
use super::*; | ||
|
||
#[test] | ||
fn main() { | ||
let command_output = Command::new("cargo") | ||
.arg("run") | ||
.arg("--bin") | ||
.arg("openapi-generator") | ||
.output() | ||
.expect("Failed to run schema generation") | ||
.stdout; | ||
|
||
let generated_schema: String = | ||
String::from_utf8(command_output).expect("Failed to read snapshot"); | ||
fn main() -> io::Result<()> { | ||
let generated_schema = generate_schema(); | ||
let generated_schema_json = serde_json::to_string_pretty(&generated_schema)?; | ||
|
||
insta::assert_snapshot!(generated_schema); | ||
insta::assert_snapshot!(generated_schema_json); | ||
Ok(()) | ||
} | ||
} |