Skip to content

Commit

Permalink
test: test install w/ revision
Browse files Browse the repository at this point in the history
  • Loading branch information
bezhermoso committed Jan 13, 2025
1 parent 308a284 commit 1c1a0e1
Showing 1 changed file with 183 additions and 0 deletions.
183 changes: 183 additions & 0 deletions tests/cli_install_subcommand_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod utils;

use std::{process::Command, str};

use crate::utils::{setup, write_to_file};
use anyhow::Result;

Expand Down Expand Up @@ -164,3 +166,184 @@ fn test_cli_install_subcommand_with_setup_quiet_flag() -> Result<()> {
cleanup()?;
Ok(())
}

#[test]
fn test_cli_install_subcommand_with_tag_revision() -> Result<()> {
// -------
// Arrange
// -------
let (config_path, repo_path, command_vec, cleanup) =
setup("test_cli_install_subcommand_with_tag_revision", "install")?;
let config_content = r##"[[items]]
path = "https://github.com/tinted-theming/tinted-jqp"
name = "tinted-jqp"
themes-dir = "themes"
revision = "tinty-test-tag-01"
"##;
write_to_file(&config_path, config_content)?;

let mut repo_path = repo_path.clone();
repo_path.push("repos");
repo_path.push("tinted-jqp");

// ---
// Act
// ---
let (_, _) = utils::run_command(command_vec).unwrap();

let output = Command::new("git")
.current_dir(repo_path)
.args(vec!["rev-parse", "--verify", "HEAD"])
.output()
.expect("Failed to execute git rev-parse --verify HEAD");

let stdout = str::from_utf8(&output.stdout).expect("Not valid UTF-8");

// ------
// Assert
// ------
let expected_revision = "b6c6a7803c2669022167c9cfc5efb3dc3928507d";
let has_match = stdout.lines().any(|line| line == expected_revision);
cleanup()?;
assert!(
has_match == true,
"Expected revision {} not found",
expected_revision,
);

Ok(())
}

#[test]
fn test_cli_install_subcommand_with_branch_revision() -> Result<()> {
// -------
// Arrange
// -------
let (config_path, repo_path, command_vec, cleanup) = setup(
"test_cli_install_subcommand_with_branch_revision",
"install",
)?;
let config_content = r##"[[items]]
path = "https://github.com/tinted-theming/tinted-jqp"
name = "tinted-jqp"
themes-dir = "themes"
revision = "tinty-test-01"
"##;
write_to_file(&config_path, config_content)?;

// ---
// Act
// ---
let (_, _) = utils::run_command(command_vec).unwrap();

let mut repo_path = repo_path.clone();
repo_path.push("repos");
repo_path.push("tinted-jqp");

let output = Command::new("git")
.current_dir(repo_path)
.args(vec!["rev-parse", "--verify", "HEAD"])
.output()
.expect("Failed to execute git rev-parse --verify HEAD");

let stdout = str::from_utf8(&output.stdout).expect("Not valid UTF-8");

// ------
// Assert
// ------
let expected_revision = "43b36ed5eadad59a5027e442330d2485b8607b34";
let has_match = stdout.lines().any(|line| line == expected_revision);
cleanup()?;
assert!(
has_match == true,
"Expected revision {} not found",
expected_revision,
);

Ok(())
}

#[test]
fn test_cli_install_subcommand_with_commit_sha1_revision() -> Result<()> {
// -------
// Arrange
// -------
let (config_path, repo_path, command_vec, cleanup) = setup(
"test_cli_install_subcommand_with_commit_sha1_revision",
"install",
)?;
let config_content = r##"[[items]]
path = "https://github.com/tinted-theming/tinted-jqp"
name = "tinted-jqp"
themes-dir = "themes"
revision = "f998d17414a7218904bb5b4fdada5daa2b2d9d5e"
"##;
write_to_file(&config_path, config_content)?;

// ---
// Act
// ---
let (_, _) = utils::run_command(command_vec).unwrap();

let mut repo_path = repo_path.clone();
repo_path.push("repos");
repo_path.push("tinted-jqp");

let output = Command::new("git")
.current_dir(repo_path)
.args(vec!["rev-parse", "--verify", "HEAD"])
.output()
.expect("Failed to execute git rev-parse --verify HEAD");

let stdout = str::from_utf8(&output.stdout).expect("Not valid UTF-8");

// ------
// Assert
// ------
// This SHA1 is only reachable through the tinted-test-01 branch, but is not the tip of that
// branch.
let expected_revision = "f998d17414a7218904bb5b4fdada5daa2b2d9d5e";
let has_match = stdout.lines().any(|line| line == expected_revision);
cleanup()?;
assert!(
has_match == true,
"Expected revision {} not found",
expected_revision,
);

Ok(())
}

#[test]
fn test_cli_install_subcommand_with_non_existent_revision() -> Result<()> {
// -------
// Arrange
// -------
let (config_path, repo_path, command_vec, cleanup) = setup(
"test_cli_install_subcommand_with_non_existent_revision",
"install",
)?;
let config_content = r##"[[items]]
path = "https://github.com/tinted-theming/tinted-jqp"
name = "tinted-jqp"
themes-dir = "themes"
revision = "invalid-revision"
"##;
write_to_file(&config_path, config_content)?;

// ---
// Act
// ---
let (_, stderr) = utils::run_command(command_vec).unwrap();

// ------
// Assert
// ------
cleanup()?;
assert!(
stderr.contains("cannot resolve invalid-revision"),
"Expected revision not found",
);

Ok(())
}

0 comments on commit 1c1a0e1

Please sign in to comment.