mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-17 08:06:38 +00:00
Add logging to unit testing
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
cb418fda11
commit
fd5b78c337
3 changed files with 28 additions and 0 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -361,6 +361,7 @@ dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"tracing-subscriber",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -4124,8 +4125,10 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sharded-slab",
|
"sharded-slab",
|
||||||
|
"smallvec",
|
||||||
"thread_local",
|
"thread_local",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
|
"tracing-log",
|
||||||
"tracing-serde",
|
"tracing-serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -25,3 +25,4 @@ url = "2.3.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
binstalk-downloader = { version = "0.10.3", path = "../binstalk-downloader" }
|
binstalk-downloader = { version = "0.10.3", path = "../binstalk-downloader" }
|
||||||
|
tracing-subscriber = "0.3"
|
||||||
|
|
|
@ -210,6 +210,8 @@ mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use compact_str::{CompactString, ToCompactString};
|
use compact_str::{CompactString, ToCompactString};
|
||||||
use std::{env, num::NonZeroU16};
|
use std::{env, num::NonZeroU16};
|
||||||
|
use tracing::subscriber::set_global_default;
|
||||||
|
use tracing_subscriber::{filter::LevelFilter, fmt::fmt};
|
||||||
|
|
||||||
mod cargo_binstall_v0_20_1 {
|
mod cargo_binstall_v0_20_1 {
|
||||||
use super::{CompactString, GhRelease, GhRepo};
|
use super::{CompactString, GhRelease, GhRepo};
|
||||||
|
@ -305,6 +307,24 @@ mod test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn init_logger() {
|
||||||
|
// Disable time, target, file, line_num, thread name/ids to make the
|
||||||
|
// output more readable
|
||||||
|
let subscriber = fmt()
|
||||||
|
.without_time()
|
||||||
|
.with_target(false)
|
||||||
|
.with_file(false)
|
||||||
|
.with_line_number(false)
|
||||||
|
.with_thread_names(false)
|
||||||
|
.with_thread_ids(false)
|
||||||
|
.with_test_writer()
|
||||||
|
.with_max_level(LevelFilter::DEBUG)
|
||||||
|
.finish();
|
||||||
|
|
||||||
|
// Setup global subscriber
|
||||||
|
set_global_default(subscriber).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
/// Mark this as an async fn so that you won't accidentally use it in
|
/// Mark this as an async fn so that you won't accidentally use it in
|
||||||
/// sync context.
|
/// sync context.
|
||||||
async fn create_client() -> Vec<GhApiClient> {
|
async fn create_client() -> Vec<GhApiClient> {
|
||||||
|
@ -327,6 +347,8 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn test_specific_release(release: &GhRelease, artifacts: &[&str]) {
|
async fn test_specific_release(release: &GhRelease, artifacts: &[&str]) {
|
||||||
|
init_logger();
|
||||||
|
|
||||||
for client in create_client().await {
|
for client in create_client().await {
|
||||||
eprintln!("In client {client:?}");
|
eprintln!("In client {client:?}");
|
||||||
|
|
||||||
|
@ -371,6 +393,8 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_gh_api_client_cargo_binstall_no_such_release() {
|
async fn test_gh_api_client_cargo_binstall_no_such_release() {
|
||||||
|
init_logger();
|
||||||
|
|
||||||
for client in create_client().await {
|
for client in create_client().await {
|
||||||
let release = GhRelease {
|
let release = GhRelease {
|
||||||
repo: GhRepo {
|
repo: GhRepo {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue