-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jstzd): add config init for client
- Loading branch information
Showing
5 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use jstzd::task::{endpoint::Endpoint, octez_client::OctezClientBuilder}; | ||
use serde_json::Value; | ||
use std::{ | ||
ffi::OsStr, | ||
fs::{read_to_string, remove_file}, | ||
os::unix::ffi::OsStrExt, | ||
path::PathBuf, | ||
}; | ||
use tempfile::{NamedTempFile, TempDir}; | ||
|
||
#[tokio::test] | ||
async fn config_init() { | ||
let temp_dir = TempDir::new().unwrap(); | ||
let expected_base_dir = temp_dir.path().to_path_buf(); | ||
let expected_endpoint: Endpoint = Endpoint::localhost(3000); | ||
let config_file = NamedTempFile::new().unwrap(); | ||
let _ = remove_file(config_file.path()); | ||
let octez_client = OctezClientBuilder::new() | ||
.set_base_dir(expected_base_dir.clone()) | ||
.set_endpoint(expected_endpoint.clone()) | ||
.build() | ||
.unwrap(); | ||
let res = octez_client.config_init(config_file.path()).await; | ||
assert!(res.is_ok()); | ||
let actual: Value = | ||
serde_json::from_str(&read_to_string(config_file).expect("Unable to read file")) | ||
.expect("Unable to parse JSON"); | ||
assert_eq!( | ||
actual["base_dir"], | ||
expected_base_dir.to_str().unwrap().to_owned() | ||
); | ||
assert_eq!(actual["endpoint"], expected_endpoint.to_string()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn command_fails_on_non_utf8_path() { | ||
let invalid_bytes = b"/tmp/\xFF\xFE"; | ||
let invalid_file_path = PathBuf::from(OsStr::from_bytes(invalid_bytes)); | ||
let _ = remove_file(&invalid_file_path); | ||
let octez_client = OctezClientBuilder::new().build().unwrap(); | ||
let res = octez_client.config_init(&invalid_file_path).await; | ||
assert!(res.is_err_and(|e| { e.to_string().contains("non utf-8 path") })); | ||
} |