Skip to content

Commit

Permalink
Add tests for sign command
Browse files Browse the repository at this point in the history
  • Loading branch information
julienvincent committed Feb 15, 2024
1 parent fc57957 commit f9bf749
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/tests/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ mod test_revset_output;
mod test_root;
mod test_shell_completion;
mod test_show_command;
mod test_sign_command;
mod test_sparse_command;
mod test_split_command;
mod test_squash_command;
Expand Down
117 changes: 117 additions & 0 deletions cli/tests/test_sign_command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright 2023 The Jujutsu Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::common::TestEnvironment;

#[test]
fn test_sign() {
let test_env = TestEnvironment::default();

test_env.add_config(
r#"
[signing]
show-signatures = true
sign-all = false
backend = "mock"
"#,
);

test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "init"]);

let show_no_sig = test_env.jj_cmd_success(&repo_path, &["show", "-r", "@-"]);

insta::assert_snapshot!(show_no_sig, @r###"
Commit ID: 9f2e994e4ee015d1b91f6676bc2de9531efb98fd
Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu
Author: Test User <[email protected]> (2001-02-03 04:05:07.000 +07:00)
Committer: Test User <[email protected]> (2001-02-03 04:05:08.000 +07:00)
init
"###);

let (_, stderr) = test_env.jj_cmd_ok(&repo_path, &["sign", "-r", "@-"]);
insta::assert_snapshot!(stderr, @r###"
Rebased 1 descendant commits
Working copy now at: rlvkpnrz b162855d (empty) (no description set)
Parent commit : qpvuntsm [✓︎] 5aab9df2 (empty) init
Commit was signed: qpvuntsm [✓︎] 5aab9df2 (empty) init
"###);

let show_with_sig = test_env.jj_cmd_success(&repo_path, &["show", "-r", "@-"]);

insta::assert_snapshot!(show_with_sig, @r###"
Commit ID: 5aab9df27eb838f225ae554edd56a11b3ecd13df
Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu
Author: Test User <[email protected]> (2001-02-03 04:05:07.000 +07:00)
Committer: Test User <[email protected]> (2001-02-03 04:05:10.000 +07:00)
Signature: Good mock signature
init
"###);
}

#[test]
fn test_sig_drop() {
let test_env = TestEnvironment::default();

test_env.add_config(
r#"
[signing]
show-signatures = true
sign-all = false
backend = "mock"
"#,
);

test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "init"]);

let show_no_sig = test_env.jj_cmd_success(&repo_path, &["show", "-r", "@-"]);
insta::assert_snapshot!(show_no_sig, @r###"
Commit ID: 9f2e994e4ee015d1b91f6676bc2de9531efb98fd
Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu
Author: Test User <[email protected]> (2001-02-03 04:05:07.000 +07:00)
Committer: Test User <[email protected]> (2001-02-03 04:05:08.000 +07:00)
init
"###);

test_env.jj_cmd_ok(&repo_path, &["sign", "-r", "@-"]);

let show_with_sig = test_env.jj_cmd_success(&repo_path, &["show", "-r", "@-"]);
insta::assert_snapshot!(show_with_sig, @r###"
Commit ID: 5aab9df27eb838f225ae554edd56a11b3ecd13df
Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu
Author: Test User <[email protected]> (2001-02-03 04:05:07.000 +07:00)
Committer: Test User <[email protected]> (2001-02-03 04:05:10.000 +07:00)
Signature: Good mock signature
init
"###);

test_env.jj_cmd_ok(&repo_path, &["sign", "-r", "@-", "--drop"]);

let show_with_sig = test_env.jj_cmd_success(&repo_path, &["show", "-r", "@-"]);
insta::assert_snapshot!(show_with_sig, @r###"
Commit ID: a37490e69293173538209a45786d10c63c8960d7
Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu
Author: Test User <[email protected]> (2001-02-03 04:05:07.000 +07:00)
Committer: Test User <[email protected]> (2001-02-03 04:05:12.000 +07:00)
init
"###);
}

0 comments on commit f9bf749

Please sign in to comment.