fix(test): fix race condition in CLI test

This commit is contained in:
Jon Seager 2025-11-26 16:28:00 +00:00
parent 4358fa63dc
commit 65e1e141ea
No known key found for this signature in database

View file

@ -57,21 +57,26 @@ fn test_revoke_token_with_authentication() {
let tokens: serde_json::Value = let tokens: serde_json::Value =
serde_json::from_str(&list_stdout).expect("Should parse token list as JSON"); serde_json::from_str(&list_stdout).expect("Should parse token list as JSON");
// Find a token to revoke // Find the token to revoke by name
let tokens_array = tokens.as_array().expect("Should be an array"); let tokens_array = tokens.as_array().expect("Should be an array");
if let Some(first_token) = tokens_array.first() { let token_to_revoke = tokens_array
let token_id = first_token["id"].as_i64().expect("Token should have ID"); .iter()
.find(|t| t["name"].as_str() == Some("test-revoke-token"))
.expect("Should find token to revoke");
let revoke_output = run_brewlog( let token_id = token_to_revoke["id"]
&["revoke-token", "--id", &token_id.to_string()], .as_i64()
&[("BREWLOG_TOKEN", &token)], .expect("Token should have ID");
);
assert!( let revoke_output = run_brewlog(
revoke_output.status.success(), &["revoke-token", "--id", &token_id.to_string()],
"Should be able to revoke token" &[("BREWLOG_TOKEN", &token)],
); );
}
assert!(
revoke_output.status.success(),
"Should be able to revoke token"
);
} }
#[test] #[test]