Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set tracing to output to stderr #138

Merged
merged 4 commits into from
Oct 22, 2024
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased

- Set tracing writer to write to `stderr` instead of `stdout` [#138](https://github.com/holochain/lair/pull/138)
- The `lair-keystore` binary now exits with an error (exit code `1`) if and error occurs [#138](https://github.com/holochain/lair/pull/138)

## 0.5.2

- enables some basic tracing [#135](https://github.com/holochain/lair/pull/135)
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/lair_keystore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pretty_assertions = { workspace = true }
sqlformat = { workspace = true }

[dev-dependencies]
assert_cmd = { workspace = true }
criterion = { workspace = true }
tempdir = { workspace = true }

Expand Down
7 changes: 3 additions & 4 deletions crates/lair_keystore/src/bin/lair-keystore-bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ async fn exec() -> LairResult<()> {
tracing::subscriber::set_global_default(
tracing_subscriber::FmtSubscriber::builder()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_writer(std::io::stderr)
.compact()
.finish(),
)
Expand Down Expand Up @@ -223,8 +224,6 @@ async fn exec() -> LairResult<()> {
}

#[tokio::main(flavor = "multi_thread")]
async fn main() {
if let Err(e) = exec().await {
eprintln!("{e}");
}
async fn main() -> LairResult<()> {
exec().await
}
cdunster marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 29 additions & 0 deletions crates/lair_keystore/tests/client_commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
mod common;

use assert_cmd::Command;
use common::create_config;
use lair_keystore::dependencies::*;
use std::{fs::File, io::Write};

#[tokio::test(flavor = "multi_thread")]
async fn test_url_command_only_outputs_connection_url() {
let tmp_dir = tempdir::TempDir::new("lair keystore test").unwrap();
let passphrase = sodoken::BufRead::from(&b"passphrase"[..]);

let config = create_config(&tmp_dir, passphrase.clone()).await;
let config_path = tmp_dir.path().join("lair-keystore-config.yaml");
let mut config_file =
File::create_new(config_path).expect("test config file already exists");

config_file
.write_all(config.to_string().as_bytes())
.expect("failed to write config to file");

let mut cmd = Command::cargo_bin("lair-keystore").unwrap();
cmd.env("RUST_LOG", "trace"); // Enable all logging levels to make sure nothing gets printed to stdout
cmd.arg(format!("--lair-root={}", tmp_dir.path().display()));
cmd.arg("url");

let expected_stdout = format!("{}\n", config.connection_url);
cmd.assert().success().stdout(expected_stdout);
}
Loading