Skip to content
Open
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
107 changes: 107 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ openssl = { version = '0.10', features = ["vendored"] }

[dev-dependencies]
tempfile = "3"
assert_cmd = "1"
predicates = "1"
40 changes: 36 additions & 4 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ fn organizations_from_dir(dir: &Path) -> impl Iterator<Item = Organization> {
.into_iter()
.filter_map(|r| r.ok())
.filter(|e| e.file_type().is_file())
.map(|e| e.path().try_into())
.filter_map(|r| match r {
.filter_map(|e| match e.path().try_into() {
Ok(organization) => Some(organization),
Err(e) => {
error!("{:?}", e);
Err(err) => {
warn!("Could not parse {:?} as an Organization ({:?})", e.path(), err);
None
}
})
Expand All @@ -53,3 +52,36 @@ fn default_profile_location() -> Result<PathBuf, Error> {
None => bail!("The environment variable HOME must be set."),
}
}

#[cfg(test)]
mod tests {
use super::*;

use assert_cmd::prelude::*;
use tempfile::tempdir;

use std::process::Command;
use std::fs::File;
use std::io::Write;

#[test]
fn test_bad_organization_in_dir() {
let tmp_dir = tempdir().unwrap();

let file_path = tmp_dir.path().join("my-bad-org.toml");

let mut tmp_file = File::create(file_path).unwrap();
writeln!(tmp_file, "Not parseable as toml").unwrap();

assert_eq!(organizations_from_dir(tmp_dir.path()).count(), 0);

let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
let assert = cmd
.env("OKTAWS_HOME", tmp_dir.path())
.assert();
assert
.failure()
.code(1)
.stderr(predicates::str::is_match(r#" WARN oktaws::config > Could not parse ".+/my-bad-org.toml" as an Organization \(Error \{ inner: ErrorInner \{ kind: Wanted \{ expected: "an equals", found: "an identifier" \}, line: Some\(0\), col: 4, at: Some\(4\), message: "", key: \[\] \} \}\)\nError: ErrorMessage \{ msg: "No organizations found called \*" }\n"#).unwrap());
}
}