Skip to content

Commit

Permalink
Update tests to handle new ID field
Browse files Browse the repository at this point in the history
  - Removed stdout table comparisons
  - Checking for the presence of values instead of
    actual formatting
  • Loading branch information
dwdozier committed Mar 15, 2024
1 parent 4eb544b commit f2fd2ff
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 331 deletions.
1 change: 1 addition & 0 deletions src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ fn proc_param_list(
for rule in entry.rules {
let mut row: Vec<String>;
row = vec![
entry.id.clone(),
entry.key.clone(),
entry.param_type.to_string(),
rule.rule_type.to_string(),
Expand Down
6 changes: 3 additions & 3 deletions src/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::cli::{
use crate::database::{OpenApiConfig, ProjectDetails, Projects};
use crate::table::Table;
use crate::utils::{
error_message, get_uuid_from_url, parse_key_value_pairs, user_confirm, warn_missing_subcommand,
warning_message, DEL_CONFIRM,
error_message, get_project_uuid_from_url, parse_key_value_pairs, user_confirm,
warn_missing_subcommand, warning_message, DEL_CONFIRM,
};
use clap::ArgMatches;
use color_eyre::eyre::Result;
Expand Down Expand Up @@ -71,7 +71,7 @@ fn proc_proj_list(
entry.id,
entry.name,
entry.parent_name,
get_uuid_from_url(&entry.parent_url.clone()),
get_project_uuid_from_url(&entry.parent_url).unwrap_or_default(),
entry.description,
];
if show_times {
Expand Down
6 changes: 3 additions & 3 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn proc_param_type_list(
.collect::<Vec<String>>();
println!("{}", list.join("\n"));
} else if show_rules {
let mut hdr = vec!["Name", "Parent", "Rule Type", "Constraint"];
let mut hdr = vec!["ID", "Name", "Parent", "Rule Type", "Constraint"];
if show_times {
hdr.push("Created At");
hdr.push("Modified At");
Expand All @@ -90,8 +90,8 @@ fn proc_param_type_list(
}
table.render(fmt)?;
} else {
let mut hdr = vec!["Name", "Parent", "Rules", "Description"];
let mut props = vec!["name", "parent-name", "rule-count", "description"];
let mut hdr = vec!["ID", "Name", "Parent", "Rules", "Description"];
let mut props = vec!["id", "name", "parent-name", "rule-count", "description"];
if show_times {
hdr.push("Created At");
hdr.push("Modified At");
Expand Down
21 changes: 8 additions & 13 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub const FILE_READ_ERR: &str = "Failed to read value from file.";
pub const ISO8601: &str = "%Y-%m-%dT%H:%M:%S%.6fZ";
pub const SEPARATOR: &str = "=========================";
pub const API_KEY_PAGE: &str = "\"API Access\"";
pub const UUID_LEN: usize = 36;

#[derive(Clone, Debug)]
pub enum ApplicationError {
Expand Down Expand Up @@ -215,20 +216,14 @@ pub fn parse_tag(input: Option<&str>) -> Option<String> {
}
}

pub fn get_uuid_from_url(url: &str) -> String {
if let Ok(url) = Url::parse(url) {
let path_segments: Vec<_> = url.path_segments().unwrap().collect();
if let Some(uuid_segment) = path_segments.get(3) {
if uuid_segment.len() == 36 {
uuid_segment.to_string()
} else {
"".to_string()
}
} else {
"".to_string()
}
pub fn get_project_uuid_from_url(url: &str) -> Option<String> {
let url = Url::parse(url).ok()?;
let path_segments: Vec<_> = url.path_segments()?.collect();
let uuid_segment = path_segments.get(3)?;
if uuid_segment.len() == UUID_LEN {
Some(uuid_segment.to_string())
} else {
"".to_string()
None
}
}

Expand Down
Loading

0 comments on commit f2fd2ff

Please sign in to comment.