Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move test generated clients into a buildable crate #638

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
target/

progenitor-impl/tests/output/Cargo.lock
37 changes: 37 additions & 0 deletions progenitor-impl/tests/output/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[workspace]

[package]
name = "test-output"
version = "0.1.0"
edition = "2021"

[dependencies]
base64 = "0.21"
chrono = { version = "0.4", features = ["serde"] }
clap = { version = "4", features = ["string"] }
futures = "0.3"
httpmock = "0.7"
progenitor-client = { path = "../../../progenitor-client" }
rand = { version = "0.8", features = ["serde1"] }
regex = "1.10"
regress = "0.7"
reqwest = "0.11"
schemars = { version = "0.8", features = ["chrono", "uuid1"] }
serde = { features = ["derive"], version = "1" }
serde_json = "1"
uuid = { features = ["serde", "v4"], version = "1" }

[lints.rust]
unused_imports = "allow"
unused_variables= "allow"

[lints.clippy]
needless_lifetimes = "allow"
redundant_field_names = "allow"
vec_init_then_push = "allow"
clone_on_copy = "allow"
unnecessary_to_owned = "allow"
to_string_in_format_args = "allow"
len_zero = "allow"
ptr_arg = "allow"
too_many_arguments = "allow"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sdk::*;
use crate::buildomat_builder::*;
pub struct Cli<T: CliOverride = ()> {
client: Client,
over: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod operations {
#![doc = r" wrappers for each operation. Each can be converted to"]
#![doc = r" its inner type with a call to `into_inner()`. This can"]
#![doc = r" be used to explicitly deviate from permitted values."]
use sdk::*;
use crate::buildomat_builder::*;
pub struct ControlHoldWhen(httpmock::When);
impl ControlHoldWhen {
pub fn new(inner: httpmock::When) -> Self {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sdk::*;
use crate::keeper_builder::*;
pub struct Cli<T: CliOverride = ()> {
client: Client,
over: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod operations {
#![doc = r" wrappers for each operation. Each can be converted to"]
#![doc = r" its inner type with a call to `into_inner()`. This can"]
#![doc = r" be used to explicitly deviate from permitted values."]
use sdk::*;
use crate::keeper_builder::*;
pub struct EnrolWhen(httpmock::When);
impl EnrolWhen {
pub fn new(inner: httpmock::When) -> Self {
Expand Down
34 changes: 34 additions & 0 deletions progenitor-impl/tests/output/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pub mod buildomat_builder;
pub mod buildomat_builder_tagged;
pub mod buildomat_cli;
//pub mod buildomat_httpmock;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out due to #637

pub mod buildomat_positional;
pub mod keeper_builder;
pub mod keeper_builder_tagged;
pub mod keeper_cli;
pub mod keeper_httpmock;
pub mod keeper_positional;
pub mod nexus_builder;
pub mod nexus_builder_tagged;
pub mod nexus_cli;
pub mod nexus_httpmock;
pub mod nexus_positional;
pub mod param_collision_builder;
pub mod param_collision_builder_tagged;
pub mod param_collision_cli;
pub mod param_collision_httpmock;
pub mod param_collision_positional;
pub mod param_overrides_builder;
pub mod param_overrides_builder_tagged;
pub mod param_overrides_cli;
pub mod param_overrides_httpmock;
pub mod param_overrides_positional;
pub mod propolis_server_builder;
pub mod propolis_server_builder_tagged;
pub mod propolis_server_cli;
//pub mod propolis_server_httpmock;
pub mod propolis_server_positional;
pub mod test_default_params_builder;
pub mod test_default_params_positional;
pub mod test_freeform_response;
pub mod test_renamed_parameters;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sdk::*;
use crate::nexus_builder::*;
pub struct Cli<T: CliOverride = ()> {
client: Client,
over: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod operations {
#![doc = r" wrappers for each operation. Each can be converted to"]
#![doc = r" its inner type with a call to `into_inner()`. This can"]
#![doc = r" be used to explicitly deviate from permitted values."]
use sdk::*;
use crate::nexus_builder::*;
pub struct DiskViewByIdWhen(httpmock::When);
impl DiskViewByIdWhen {
pub fn new(inner: httpmock::When) -> Self {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sdk::*;
use crate::param_collision_builder::*;
pub struct Cli<T: CliOverride = ()> {
client: Client,
over: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod operations {
#![doc = r" wrappers for each operation. Each can be converted to"]
#![doc = r" its inner type with a call to `into_inner()`. This can"]
#![doc = r" be used to explicitly deviate from permitted values."]
use sdk::*;
use crate::param_collision_builder::*;
pub struct KeyGetWhen(httpmock::When);
impl KeyGetWhen {
pub fn new(inner: httpmock::When) -> Self {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sdk::*;
use crate::param_overrides_builder::*;
pub struct Cli<T: CliOverride = ()> {
client: Client,
over: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod operations {
#![doc = r" wrappers for each operation. Each can be converted to"]
#![doc = r" its inner type with a call to `into_inner()`. This can"]
#![doc = r" be used to explicitly deviate from permitted values."]
use sdk::*;
use crate::param_overrides_builder::*;
pub struct KeyGetWhen(httpmock::When);
impl KeyGetWhen {
pub fn new(inner: httpmock::When) -> Self {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sdk::*;
use crate::propolis_server_builder::*;
pub struct Cli<T: CliOverride = ()> {
client: Client,
over: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod operations {
#![doc = r" wrappers for each operation. Each can be converted to"]
#![doc = r" its inner type with a call to `into_inner()`. This can"]
#![doc = r" be used to explicitly deviate from permitted values."]
use sdk::*;
use crate::propolis_server_builder::*;
pub struct InstanceGetWhen(httpmock::When);
impl InstanceGetWhen {
pub fn new(inner: httpmock::When) -> Self {
Expand Down
21 changes: 13 additions & 8 deletions progenitor-impl/tests/test_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ fn reformat_code(content: TokenStream) -> String {
fn verify_apis(openapi_file: &str) {
let mut in_path = PathBuf::from("../sample_openapi");
in_path.push(openapi_file);
let openapi_stem = openapi_file.split('.').next().unwrap();
let openapi_stem =
openapi_file.split('.').next().unwrap().replace('-', "_");

let spec = load_api(in_path);

// Positional generation.
let mut generator = Generator::default();
let output = generate_formatted(&mut generator, &spec);
expectorate::assert_contents(
format!("tests/output/{}-positional.out", openapi_stem),
format!("tests/output/src/{}_positional.rs", openapi_stem),
&output,
);

Expand All @@ -82,7 +83,7 @@ fn verify_apis(openapi_file: &str) {
);
let output = generate_formatted(&mut generator, &spec);
expectorate::assert_contents(
format!("tests/output/{}-builder.out", openapi_stem),
format!("tests/output/src/{}_builder.rs", openapi_stem),
&output,
);

Expand All @@ -94,21 +95,25 @@ fn verify_apis(openapi_file: &str) {
);
let output = generate_formatted(&mut generator, &spec);
expectorate::assert_contents(
format!("tests/output/{}-builder-tagged.out", openapi_stem),
format!("tests/output/src/{}_builder_tagged.rs", openapi_stem),
&output,
);

// CLI generation.
let tokens = generator.cli(&spec, "sdk").unwrap();
let tokens = generator
.cli(&spec, &format!("crate::{openapi_stem}_builder"))
.unwrap();
let output = reformat_code(tokens);

expectorate::assert_contents(
format!("tests/output/{}-cli.out", openapi_stem),
format!("tests/output/src/{}_cli.rs", openapi_stem),
&output,
);

// httpmock generation.
let code = generator.httpmock(&spec, "sdk").unwrap();
let code = generator
.httpmock(&spec, &format!("crate::{openapi_stem}_builder"))
.unwrap();

// TODO pending #368
let output = rustfmt_wrapper::rustfmt_config(
Expand All @@ -122,7 +127,7 @@ fn verify_apis(openapi_file: &str) {

let output = progenitor_impl::space_out_items(output).unwrap();
expectorate::assert_contents(
format!("tests/output/{}-httpmock.out", openapi_stem),
format!("tests/output/src/{}_httpmock.rs", openapi_stem),
&output,
);
}
Expand Down
8 changes: 4 additions & 4 deletions progenitor-impl/tests/test_specific.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn test_renamed_parameters() {
let mut generator = Generator::default();
let output = generate_formatted(&mut generator, &spec);
expectorate::assert_contents(
format!("tests/output/{}.out", "test_renamed_parameters"),
format!("tests/output/src/{}.rs", "test_renamed_parameters"),
&output,
)
}
Expand Down Expand Up @@ -115,7 +115,7 @@ fn test_freeform_response() {
let mut generator = Generator::default();
let output = generate_formatted(&mut generator, &spec);
expectorate::assert_contents(
format!("tests/output/{}.out", "test_freeform_response"),
format!("tests/output/src/{}.rs", "test_freeform_response"),
&output,
)
}
Expand Down Expand Up @@ -169,7 +169,7 @@ fn test_default_params() {
let mut generator = Generator::default();
let output = generate_formatted(&mut generator, &spec);
expectorate::assert_contents(
format!("tests/output/{}.out", "test_default_params_positional"),
format!("tests/output/src/{}.rs", "test_default_params_positional"),
&output,
);

Expand All @@ -178,7 +178,7 @@ fn test_default_params() {
);
let output = generate_formatted(&mut generator, &spec);
expectorate::assert_contents(
format!("tests/output/{}.out", "test_default_params_builder"),
format!("tests/output/src/{}.rs", "test_default_params_builder"),
&output,
);
}
Loading