ok/jj
1
0
Fork 0
forked from mirrors/jj

tests: avoid hardcoding commit/operation ids when possible

Hardcoded ids cannot be updated with `insta`.
This commit is contained in:
Martin von Zweigbergk 2023-05-21 00:17:39 -07:00 committed by Martin von Zweigbergk
parent 0e18757610
commit a72898000f
3 changed files with 19 additions and 18 deletions

View file

@ -77,12 +77,10 @@ fn test_edit_current_wc_commit_missing() {
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["edit", "@-"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
5c52832c3483 second
@ 69542c1984c1 first
000000000000
"###);
let wc_id = test_env.jj_cmd_success(&repo_path, &["log", "--no-graph", "-T=commit_id", "-r=@"]);
let wc_child_id =
test_env.jj_cmd_success(&repo_path, &["log", "--no-graph", "-T=commit_id", "-r=@+"]);
// Make the Git backend fail to read the current working copy commit
let commit_object_path = repo_path
.join(".jj")
@ -90,16 +88,13 @@ fn test_edit_current_wc_commit_missing() {
.join("store")
.join("git")
.join("objects")
.join("69")
.join("542c1984c1f9d91f7c6c9c9e6941782c944bd9");
.join(&wc_id[..2])
.join(&wc_id[2..]);
std::fs::remove_file(commit_object_path).unwrap();
// Pass --ignore-working-copy to avoid triggering the error at snapshot time
let assert = test_env
.jj_cmd(
&repo_path,
&["edit", "--ignore-working-copy", "5c52832c3483"],
)
.jj_cmd(&repo_path, &["edit", "--ignore-working-copy", &wc_child_id])
.assert()
.code(255);
insta::assert_snapshot!(get_stderr_string(&assert), @r###"

View file

@ -193,18 +193,22 @@ fn test_git_colocated_branches() {
);
// Update the branch in Git
let target_id = test_env.jj_cmd_success(
&workspace_root,
&["log", "--no-graph", "-T=commit_id", "-r=description(foo)"],
);
git_repo
.reference(
"refs/heads/master",
Oid::from_str("1e6f0b403ed2ff9713b5d6b1dc601e4804250cda").unwrap(),
Oid::from_str(&target_id).unwrap(),
true,
"test",
)
.unwrap();
insta::assert_snapshot!(get_log_output(&test_env, &workspace_root), @r###"
Working copy now at: eb08b363bb5e (no description set)
Working copy now at: 096dc80da670 (no description set)
Parent commit : 230dd059e1b0 (no description set)
@ eb08b363bb5ef8ee549314260488980d7bbe8f63
@ 096dc80da67094fbaa6683e2a205dddffa31f9a8
1e6f0b403ed2ff9713b5d6b1dc601e4804250cda master foo
230dd059e1b059aefc0da06a2e5a7dbf22362f22 HEAD@git
@ -265,8 +269,8 @@ fn test_git_colocated_fetch_deleted_or_moved_branch() {
test_env.jj_cmd_success(&origin_path, &["describe", "C_to_move", "-m", "moved C"]);
let stdout = test_env.jj_cmd_success(&clone_path, &["git", "fetch"]);
insta::assert_snapshot!(stdout, @"");
// 929e and 8d4e are abandoned, as the corresponding branches were deleted or
// moved on the remote (#864)
// "original C" and "B_to_delete" are abandoned, as the corresponding branches
// were deleted or moved on the remote (#864)
insta::assert_snapshot!(get_log_output(&test_env, &clone_path), @r###"
04fd29df05638156b20044b3b6136b42abcb09ab C_to_move moved C
@ 0335878796213c3a701f1c9c34dcae242bee4131

View file

@ -14,6 +14,7 @@
use std::path::Path;
use itertools::Itertools;
use regex::Regex;
use crate::common::{get_stdout_string, TestEnvironment};
@ -45,8 +46,9 @@ fn test_op_log() {
56b94dfc38e7 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
initialize repo
"###);
let add_workspace_id = "a99a3fd5c51e";
let initialize_repo_id = "56b94dfc38e7";
let op_log_lines = stdout.lines().collect_vec();
let add_workspace_id = op_log_lines[3].split(' ').nth(2).unwrap();
let initialize_repo_id = op_log_lines[5].split(' ').nth(2).unwrap();
// Can load the repo at a specific operation ID
insta::assert_snapshot!(get_log_output(&test_env, &repo_path, initialize_repo_id), @r###"