tests: set test hostname and username for operation log

This makes the tests more hermetic, even though I don't think the
default values (taken from `whoami`) can break any tests (then we
would have already seen them break). Now we just need to make the
operation log's timestamps predictable and then we can start using
operation IDs in snapshot tests.
This commit is contained in:
Martin von Zweigbergk 2022-11-13 23:41:11 -08:00 committed by Martin von Zweigbergk
parent 90ce94e262
commit 8d7a9e729b
4 changed files with 18 additions and 1 deletions

View file

@ -65,6 +65,10 @@ pub fn user_settings() -> UserSettings {
.unwrap()
.set_override("user.email", "test.user@example.com")
.unwrap()
.set_override("operation.hostname", "host.example.com")
.unwrap()
.set_override("operation.username", "test-username")
.unwrap()
.build()
.unwrap();
UserSettings::from_config(config)

View file

@ -78,6 +78,12 @@ fn env_overrides() -> config::Config {
if let Ok(value) = env::var("JJ_TIMESTAMP") {
builder = builder.set_override("user.timestamp", value).unwrap();
}
if let Ok(value) = env::var("JJ_OP_HOSTNAME") {
builder = builder.set_override("operation.hostname", value).unwrap();
}
if let Ok(value) = env::var("JJ_OP_USERNAME") {
builder = builder.set_override("operation.username", value).unwrap();
}
if let Ok(value) = env::var("JJ_EDITOR") {
builder = builder.set_override("ui.editor", value).unwrap();
}

View file

@ -72,6 +72,8 @@ impl TestEnvironment {
cmd.env("JJ_TIMESTAMP", timestamp.to_rfc3339());
cmd.env("JJ_USER", "Test User");
cmd.env("JJ_EMAIL", "test.user@example.com");
cmd.env("JJ_OP_HOSTNAME", "host.example.com");
cmd.env("JJ_OP_USERNAME", "test-username");
cmd
}

View file

@ -97,7 +97,12 @@ fn test_op_log_configurable() {
operation.username = "my-username"
"#,
);
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env
.jj_cmd(&test_env.env_root(), &["init", "repo", "--git"])
.env_remove("JJ_OP_HOSTNAME")
.env_remove("JJ_OP_USERNAME")
.assert()
.success();
let repo_path = test_env.env_root().join("repo");
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);