tsk-22: Add function to parse env variable to a vector of strings #25
@@ -7,7 +7,7 @@ pub struct EnvVar {
|
|||||||
pub key: String,
|
pub key: String,
|
||||||
pub value: String,
|
pub value: String,
|
||||||
pub has_delimiter: bool,
|
pub has_delimiter: bool,
|
||||||
pub delimiter: char
|
pub delimiter: char,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_envvar(key: &str, value: &str) -> EnvVar {
|
pub fn init_envvar(key: &str, value: &str) -> EnvVar {
|
||||||
|
@@ -2,8 +2,14 @@
|
|||||||
/// extract it into some strings
|
/// extract it into some strings
|
||||||
pub fn delimitize(var: &crate::EnvVar) -> Result<Vec<String>, std::io::Error> {
|
pub fn delimitize(var: &crate::EnvVar) -> Result<Vec<String>, std::io::Error> {
|
||||||
if var.has_delimiter {
|
if var.has_delimiter {
|
||||||
Ok(var.value.split(var.delimiter).map(|c| c.parse::<String>().unwrap()).collect())
|
Ok(var
|
||||||
|
.value
|
||||||
|
.split(var.delimiter)
|
||||||
|
.map(|c| c.parse::<String>().unwrap())
|
||||||
|
.collect())
|
||||||
} else {
|
} else {
|
||||||
Err(std::io::Error::other("Environment variable does not have a delimiter"))
|
Err(std::io::Error::other(
|
||||||
|
"Environment variable does not have a delimiter",
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -116,11 +116,21 @@ mod tests {
|
|||||||
result
|
result
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(result.has_delimiter, true, "The {} variable has an issue finding the delimiter", result.key);
|
assert_eq!(
|
||||||
|
result.has_delimiter, true,
|
||||||
|
"The {} variable has an issue finding the delimiter",
|
||||||
|
result.key
|
||||||
|
);
|
||||||
|
|
||||||
match icarus_envy::utility::delimitize(&result) {
|
match icarus_envy::utility::delimitize(&result) {
|
||||||
Ok(allowed_origins) => {
|
Ok(allowed_origins) => {
|
||||||
assert_eq!(allowed_origins.len(), 2, "The amount of allowed origins does not match. {} {}", allowed_origins.len(), 2)
|
assert_eq!(
|
||||||
|
allowed_origins.len(),
|
||||||
|
2,
|
||||||
|
"The amount of allowed origins does not match. {} {}",
|
||||||
|
allowed_origins.len(),
|
||||||
|
2
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
assert!(false, "Error: {:?}", err)
|
assert!(false, "Error: {:?}", err)
|
||||||
|
Reference in New Issue
Block a user