Skip to content

Commit

Permalink
Merge pull request #447 from str4d/ci-run-rage-tests
Browse files Browse the repository at this point in the history
CI: Run rage tests
  • Loading branch information
str4d authored Jan 16, 2024
2 parents 71484d7 + 26a4a46 commit b9e1565
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 24 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ jobs:

steps:
- uses: actions/checkout@v4
- run: cargo fetch
- name: Build tests
run: cargo build --workspace --verbose --exclude rage --all-features --tests
- name: Run tests
run: cargo test --workspace --verbose --exclude rage --all-features
run: >
cargo test
--workspace
--features '
armor
async
cli-common
plugin
ssh
unstable
'
- name: Verify working directory is clean
run: git diff --exit-code

build:
name: Build target ${{ matrix.target }}
Expand Down
32 changes: 22 additions & 10 deletions rage/src/bin/rage/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@ use clap::{builder::Styles, ArgAction, Parser};

use crate::fl;

fn binary_name() -> String {
fn binary_name(suffix: Option<&str>) -> String {
if let Some(arg) = std::env::args_os().next() {
Path::new(&arg)
.file_name()
.expect("is not directory")
.to_string_lossy()
.to_string()
let path = Path::new(&arg);
if let Some(suffix) = suffix {
let stem = path
.file_stem()
.expect("is not directory")
.to_string_lossy();
let extension = path
.extension()
.map(|extension| format!(".{}", extension.to_string_lossy()))
.unwrap_or_default();
format!("{}{}{}", stem, suffix, extension)
} else {
path.file_name()
.expect("is not directory")
.to_string_lossy()
.to_string()
}
} else {
"rage".into()
format!("rage{}", suffix.unwrap_or_default())
}
}

fn usage() -> String {
let binary_name = binary_name();
let binary_name = binary_name(None);
let recipient = fl!("recipient");
let identity = fl!("identity");
let input = fl!("input");
Expand All @@ -39,8 +51,8 @@ pub(crate) fn after_help_content(keygen_name: &str) -> String {
}

fn after_help() -> String {
let binary_name = binary_name();
let keygen_name = format!("{}-keygen", binary_name);
let keygen_name = binary_name(Some("-keygen"));
let binary_name = binary_name(None);
let example_a = format!("$ {} -o key.txt", keygen_name);
let example_a_output = "age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p";
let example_b = format!(
Expand Down
6 changes: 5 additions & 1 deletion rage/tests/cmd/rage-keygen/help.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
bin.name = "rage-keygen"
args = "--help"
stdout = """
Usage: rage-keygen[EXE] [OPTIONS]
Usage: rage-keygen[EXE] [OPTIONS] [INPUT]
Arguments:
[INPUT] Path to a file to read from.
Options:
-h, --help Print this help message and exit.
-V, --version Print version info and exit.
-o, --output <OUTPUT> Write the result to the file at path OUTPUT. Defaults to standard output.
-y Convert an identity file to a recipients file.
"""
stderr = ""
6 changes: 5 additions & 1 deletion rage/tests/cmd/rage-keygen/help_it.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ bin.name = "rage-keygen"
args = "--help"
env.add.LANG = "it"
stdout = """
Usage: rage-keygen[EXE] [OPTIONS]
Usage: rage-keygen[EXE] [OPTIONS] [INPUT]
Arguments:
[INPUT] Path to a file to read from.
Options:
-h, --help Print this help message and exit.
-V, --version Print version info and exit.
-o, --output <OUTPUT> Write the result to the file at path OUTPUT. Defaults to standard output.
-y Convert an identity file to a recipients file.
"""
stderr = ""
8 changes: 4 additions & 4 deletions rage/tests/cmd/rage/help.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Options:
INPUT defaults to standard input, and OUTPUT defaults to standard output.
RECIPIENT can be:
- An age public key, as generated by rage-keygen ("age1...").
- An age public key, as generated by rage-keygen[EXE] ("age1...").
- An SSH public key ("ssh-ed25519 AAAA...", "ssh-rsa AAAA...").
PATH is a path to a file containing age recipients, one per line
Expand All @@ -36,9 +36,9 @@ Passphrase-encrypted age identity files can be used as identity files.
Multiple identities may be provided, and any unused ones will be ignored.
Example:
$ rage-keygen -o key.txt
$ rage-keygen[EXE] -o key.txt
Public key: age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p
$ tar cvz ~/data | rage -r age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p > data.tar.gz.age
$ rage -d -i key.txt -o data.tar.gz data.tar.gz.age
$ tar cvz ~/data | rage[EXE] -r age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p > data.tar.gz.age
$ rage[EXE] -d -i key.txt -o data.tar.gz data.tar.gz.age
"""
stderr = ""
8 changes: 4 additions & 4 deletions rage/tests/cmd/rage/help_it.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ INPUT ha come valore predefinito lo standard input, e OUTPUT ha come
valore predefinito lo standard output.
RECIPIENT può essere:
- Una chiave pubblica age, come generata da rage-keygen ("age1...").
- Una chiave pubblica age, come generata da rage-keygen[EXE] ("age1...").
- Una chiave pubblica SSH ("ssh-ed25519 AAAA...", "ssh-rsa AAAA...").
PATH è il percorso ad un file contenente dei destinatari age,
Expand All @@ -39,9 +39,9 @@ I file di identità possono essere cifrati con age e una passphrase.
Possono essere fornite più identità, quelle inutilizzate verranno ignorate.
Esempio:
$ rage-keygen -o key.txt
$ rage-keygen[EXE] -o key.txt
Chiave pubblica: age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p
$ tar cvz ~/data | rage -r age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p > data.tar.gz.age
$ rage -d -i key.txt -o data.tar.gz data.tar.gz.age
$ tar cvz ~/data | rage[EXE] -r age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p > data.tar.gz.age
$ rage[EXE] -d -i key.txt -o data.tar.gz data.tar.gz.age
"""
stderr = ""

0 comments on commit b9e1565

Please sign in to comment.