forked from mirrors/jj
sign: Skip gpg tests if gpg is not installed
This adds a guard to the gpg signing tests which will skip the test if `gpg` is not installed on the system. This is done in order to avoid requiring all collaborators to have setup all the tools on their local machines that are required to test commit signing.
This commit is contained in:
parent
9f05aa8c46
commit
f97e929cbf
1 changed files with 18 additions and 1 deletions
|
@ -3,7 +3,7 @@ use std::fs::Permissions;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::prelude::PermissionsExt;
|
use std::os::unix::prelude::PermissionsExt;
|
||||||
use std::process::Stdio;
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
use insta::assert_debug_snapshot;
|
use insta::assert_debug_snapshot;
|
||||||
|
@ -75,6 +75,15 @@ impl GpgEnvironment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! gpg_guard {
|
||||||
|
() => {
|
||||||
|
if Command::new("gpg").arg("--version").status().is_err() {
|
||||||
|
eprintln!("Skipping test because gpg is not installed on the system");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn backend(env: &GpgEnvironment) -> GpgBackend {
|
fn backend(env: &GpgEnvironment) -> GpgBackend {
|
||||||
// don't really need faked time for current tests,
|
// don't really need faked time for current tests,
|
||||||
// but probably will need it for end-to-end cli tests
|
// but probably will need it for end-to-end cli tests
|
||||||
|
@ -87,6 +96,8 @@ fn backend(env: &GpgEnvironment) -> GpgBackend {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn gpg_signing_roundtrip() {
|
fn gpg_signing_roundtrip() {
|
||||||
|
gpg_guard!();
|
||||||
|
|
||||||
let env = GpgEnvironment::new().unwrap();
|
let env = GpgEnvironment::new().unwrap();
|
||||||
let backend = backend(&env);
|
let backend = backend(&env);
|
||||||
let data = b"hello world";
|
let data = b"hello world";
|
||||||
|
@ -111,6 +122,8 @@ fn gpg_signing_roundtrip() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn gpg_signing_roundtrip_explicit_key() {
|
fn gpg_signing_roundtrip_explicit_key() {
|
||||||
|
gpg_guard!();
|
||||||
|
|
||||||
let env = GpgEnvironment::new().unwrap();
|
let env = GpgEnvironment::new().unwrap();
|
||||||
let backend = backend(&env);
|
let backend = backend(&env);
|
||||||
let data = b"hello world";
|
let data = b"hello world";
|
||||||
|
@ -142,6 +155,8 @@ fn gpg_signing_roundtrip_explicit_key() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unknown_key() {
|
fn unknown_key() {
|
||||||
|
gpg_guard!();
|
||||||
|
|
||||||
let env = GpgEnvironment::new().unwrap();
|
let env = GpgEnvironment::new().unwrap();
|
||||||
let backend = backend(&env);
|
let backend = backend(&env);
|
||||||
let signature = br"-----BEGIN PGP SIGNATURE-----
|
let signature = br"-----BEGIN PGP SIGNATURE-----
|
||||||
|
@ -173,6 +188,8 @@ fn unknown_key() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_signature() {
|
fn invalid_signature() {
|
||||||
|
gpg_guard!();
|
||||||
|
|
||||||
let env = GpgEnvironment::new().unwrap();
|
let env = GpgEnvironment::new().unwrap();
|
||||||
let backend = backend(&env);
|
let backend = backend(&env);
|
||||||
let signature = br"-----BEGIN PGP SIGNATURE-----
|
let signature = br"-----BEGIN PGP SIGNATURE-----
|
||||||
|
|
Loading…
Reference in a new issue