tests/identity_test.rs
Ref: Size: 4.4 KiB
mod common;
use common::TestRepo;
// ===========================================================================
// Whoami command
// ===========================================================================
#[test]
fn test_whoami_shows_name_and_email() {
let repo = TestRepo::new("Alice", "alice@example.com");
let out = repo.run_ok(&["whoami"]);
assert!(out.contains("Alice"), "should show user name");
assert!(out.contains("alice@example.com"), "should show user email");
}
#[test]
fn test_whoami_shows_signing_key() {
let repo = TestRepo::new("Alice", "alice@example.com");
let out = repo.run_ok(&["whoami"]);
// Signing key is set up by TestRepo::new, so we should see a public key
assert!(
out.contains("Signing key:"),
"should show signing key label: {}",
out
);
}
#[test]
fn test_whoami_no_aliases_initially() {
let repo = TestRepo::new("Alice", "alice@example.com");
let out = repo.run_ok(&["whoami"]);
assert!(
out.contains("Aliases: (none)"),
"should show no aliases: {}",
out
);
}
// ===========================================================================
// Identity alias add
// ===========================================================================
#[test]
fn test_identity_alias_add() {
let repo = TestRepo::new("Alice", "alice@example.com");
let out = repo.run_ok(&["identity", "alias", "alice@work.com"]);
assert!(out.contains("alice@work.com"), "should confirm alias added");
}
#[test]
fn test_identity_alias_shows_in_whoami() {
let repo = TestRepo::new("Alice", "alice@example.com");
repo.run_ok(&["identity", "alias", "alice@work.com"]);
let out = repo.run_ok(&["whoami"]);
assert!(
out.contains("alice@work.com"),
"whoami should show alias: {}",
out
);
}
#[test]
fn test_identity_alias_add_multiple() {
let repo = TestRepo::new("Alice", "alice@example.com");
repo.run_ok(&["identity", "alias", "alice@work.com"]);
repo.run_ok(&["identity", "alias", "alice@personal.org"]);
let out = repo.run_ok(&["identity", "list"]);
assert!(out.contains("alice@work.com"), "should list first alias");
assert!(out.contains("alice@personal.org"), "should list second alias");
}
#[test]
fn test_identity_alias_duplicate_rejected() {
let repo = TestRepo::new("Alice", "alice@example.com");
repo.run_ok(&["identity", "alias", "alice@work.com"]);
let out = repo.run_ok(&["identity", "alias", "alice@work.com"]);
assert!(
out.contains("already"),
"should indicate alias already exists: {}",
out
);
}
#[test]
fn test_identity_alias_cannot_add_primary_email() {
let repo = TestRepo::new("Alice", "alice@example.com");
let err = repo.run_err(&["identity", "alias", "alice@example.com"]);
assert!(
err.contains("primary email"),
"should reject aliasing primary email: {}",
err
);
}
// ===========================================================================
// Identity list
// ===========================================================================
#[test]
fn test_identity_list_shows_primary_and_aliases() {
let repo = TestRepo::new("Alice", "alice@example.com");
repo.run_ok(&["identity", "alias", "alice@work.com"]);
let out = repo.run_ok(&["identity", "list"]);
assert!(out.contains("alice@example.com"), "should show primary email");
assert!(out.contains("alice@work.com"), "should show alias");
}
// ===========================================================================
// Identity alias remove
// ===========================================================================
#[test]
fn test_identity_alias_remove() {
let repo = TestRepo::new("Alice", "alice@example.com");
repo.run_ok(&["identity", "alias", "alice@work.com"]);
let out = repo.run_ok(&["identity", "unalias", "alice@work.com"]);
assert!(out.contains("alice@work.com"), "should confirm removal");
let list_out = repo.run_ok(&["identity", "list"]);
assert!(
!list_out.contains("alice@work.com"),
"alias should be gone: {}",
list_out
);
}
#[test]
fn test_identity_alias_remove_nonexistent_errors() {
let repo = TestRepo::new("Alice", "alice@example.com");
let err = repo.run_err(&["identity", "unalias", "nobody@example.com"]);
assert!(
err.contains("not found"),
"should error on nonexistent alias: {}",
err
);
}