Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cataggar committed Oct 10, 2023
1 parent 0bf7d90 commit 2e70d51
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 33 deletions.
14 changes: 1 addition & 13 deletions services/autorust/codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,11 @@ pub fn gen_crate(package_name: &str, spec: &SpecReadme, run_config: &RunConfig,

let src_folder = io::join(output_folder, "src")?;
let lib_rs_path = &io::join(&src_folder, "lib.rs")?;
let tests_rs_path = &io::join(&src_folder, "tests.rs")?;
let tests_rs_path_exists = tests_rs_path.exists();
let tmp_tests_rs_path = &io::join(output_folder, "tests.rs.tmp")?;

if tests_rs_path_exists {
fs::rename(tests_rs_path, tmp_tests_rs_path)?;
}

if src_folder.exists() {
fs::remove_dir_all(&src_folder)?;
}

if tests_rs_path_exists {
fs::create_dir_all(&src_folder)?;
fs::rename(tmp_tests_rs_path, tests_rs_path)?;
}

let readme_path = io::join(output_folder, "README.md")?;
if readme_path.exists() {
std::fs::remove_file(&readme_path)?;
Expand Down Expand Up @@ -97,7 +85,7 @@ pub fn gen_crate(package_name: &str, spec: &SpecReadme, run_config: &RunConfig,
let default_tag = cargo_toml::get_default_tag(tags, default_tag_name);

cargo_toml::create(package_name, tags, default_tag, has_xml, &cargo_toml_path)?;
lib_rs::create(tags, lib_rs_path, false, tests_rs_path_exists)?;
lib_rs::create(tags, lib_rs_path, false)?;
let readme = ReadmeMd {
package_name,
readme_url: readme_md::url(spec.readme().as_str()),
Expand Down
22 changes: 4 additions & 18 deletions services/autorust/codegen/src/lib_rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ use camino::Utf8Path;
use proc_macro2::{Ident, TokenStream};
use quote::{quote, ToTokens};

pub fn create(tags: &[&Tag], path: &Utf8Path, print_writing_file: bool, tests_rs_path_exists: bool) -> Result<()> {
write_file(
path,
&create_body(tags, tests_rs_path_exists)?.into_token_stream(),
print_writing_file,
)
pub fn create(tags: &[&Tag], path: &Utf8Path, print_writing_file: bool) -> Result<()> {
write_file(path, &create_body(tags)?.into_token_stream(), print_writing_file)
}

struct Feature {
Expand All @@ -19,10 +15,9 @@ struct Feature {

struct BodyCode {
pub features: Vec<Feature>,
pub tests_rs_path_exists: bool,
}

fn create_body(tags: &[&Tag], tests_rs_path_exists: bool) -> Result<BodyCode> {
fn create_body(tags: &[&Tag]) -> Result<BodyCode> {
let features: Vec<Feature> = tags
.iter()
.map(|tag| {
Expand All @@ -31,10 +26,7 @@ fn create_body(tags: &[&Tag], tests_rs_path_exists: bool) -> Result<BodyCode> {
Ok(Feature { feature_name, mod_name })
})
.collect::<Result<_>>()?;
Ok(BodyCode {
features,
tests_rs_path_exists,
})
Ok(BodyCode { features })
}

impl ToTokens for BodyCode {
Expand All @@ -58,11 +50,5 @@ impl ToTokens for BodyCode {
#![allow(clippy::derive_partial_eq_without_eq)]
#cfgs
});
if self.tests_rs_path_exists {
tokens.extend(quote! {
#[cfg(test)]
mod tests;
})
}
}
}
4 changes: 2 additions & 2 deletions services/mgmt/vmware/tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ fn test_list_dhcp_configurations_deserialization() -> anyhow::Result<()> {
let dhcp = &dhcp_list.value[0];
ensure!(dhcp.proxy_resource.resource.name == Some("dhcp1".to_string()));
match &dhcp.properties {
Some(WorkloadNetworkDhcpEntityUnion::Server(server)) =>{
Some(WorkloadNetworkDhcpEntityUnion::Server(server)) => {
ensure!(server.workload_network_dhcp_entity.display_name.as_deref() == Some("dhcpConfigurations1"));
ensure!(server.workload_network_dhcp_entity.segments.len() == 2);
ensure!(server.server_address.as_deref() == Some("40.1.5.1/24"));
ensure!(server.lease_time == Some(86400));
ensure!(server.workload_network_dhcp_entity.revision == Some(1));
},
}
_ => bail!("expected Server"),
}
Ok(())
Expand Down

0 comments on commit 2e70d51

Please sign in to comment.