Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add tests for install-receipts from sh #776

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cargo-dist/templates/installer/installer.ps1.j2
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function Invoke-Installer($bin_paths) {
$dest_dir = Join-Path $root "bin"

# The replace call here ensures proper escaping is inlined into the receipt
$receipt = $receipt.Replace('AXO_CARGO_HOME', $root.replace("\", "\\"))
$receipt = $receipt.Replace('AXO_CARGO_HOME', $dest_dir.replace("\", "\\"))
{% elif install_path.kind == "HomeSubdir" %}
# Install to this subdir of the user's home dir
$dest_dir = if (($base_dir = $HOME)) {
Expand Down
4 changes: 2 additions & 2 deletions cargo-dist/templates/installer/installer.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -288,7 +288,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")
{% elif install_path.kind == "HomeSubdir" %}
# Install to this subdir of the user's home dir
# In this case we want to be late-bound, as $HOME is reliable/nice.
Expand Down
47 changes: 47 additions & 0 deletions cargo-dist/tests/gallery/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ impl DistResult {
tempdir.join(".bash_profile"),
tempdir.join(".zshrc"),
];
let receipt_file = tempdir.join(format!(".config/{app_name}/{app_name}-receipt.json"));
let expected_bin_dir = Utf8PathBuf::from(expected_bin_dir);
let bin_dir = tempdir.join(&expected_bin_dir);
let env_dir = if expected_bin_dir
Expand Down Expand Up @@ -439,6 +440,52 @@ impl DistResult {
"bin path wasn't right"
);
}

// Check that the install receipt works
{
use serde::Deserialize;

#[derive(Deserialize)]
#[allow(dead_code)]
struct InstallReceipt {
binaries: Vec<String>,
install_prefix: String,
provider: InstallReceiptProvider,
source: InstallReceiptSource,
version: String,
}
#[derive(Deserialize)]
#[allow(dead_code)]
struct InstallReceiptProvider {
source: String,
version: String,
}
#[derive(Deserialize)]
#[allow(dead_code)]
struct InstallReceiptSource {
app_name: String,
name: String,
owner: String,
release_type: String,
}

assert!(receipt_file.exists());
let receipt_src =
SourceFile::load_local(receipt_file).expect("couldn't load receipt file");
let receipt: InstallReceipt = receipt_src.deserialize_json().unwrap();
assert_eq!(receipt.source.app_name, app_name);
assert_eq!(
receipt.binaries,
ctx.repo
.bins
.iter()
.map(|s| s.to_owned())
.collect::<Vec<_>>()
);
let receipt_bin_dir = receipt.install_prefix.trim_end_matches('/').to_owned();
let expected_bin_dir = bin_dir.to_string().trim_end_matches('/').to_owned();
assert_eq!(receipt_bin_dir, expected_bin_dir);
}
}
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions cargo-dist/tests/snapshots/akaikatana_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -297,7 +297,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down Expand Up @@ -1028,7 +1028,7 @@ function Invoke-Installer($bin_paths) {
$dest_dir = Join-Path $root "bin"

# The replace call here ensures proper escaping is inlined into the receipt
$receipt = $receipt.Replace('AXO_CARGO_HOME', $root.replace("\", "\\"))
$receipt = $receipt.Replace('AXO_CARGO_HOME', $dest_dir.replace("\", "\\"))

$dest_dir = New-Item -Force -ItemType Directory -Path $dest_dir
Write-Information "Installing to $dest_dir"
Expand Down
4 changes: 2 additions & 2 deletions cargo-dist/tests/snapshots/akaikatana_musl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -309,7 +309,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down
6 changes: 3 additions & 3 deletions cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -297,7 +297,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down Expand Up @@ -1028,7 +1028,7 @@ function Invoke-Installer($bin_paths) {
$dest_dir = Join-Path $root "bin"

# The replace call here ensures proper escaping is inlined into the receipt
$receipt = $receipt.Replace('AXO_CARGO_HOME', $root.replace("\", "\\"))
$receipt = $receipt.Replace('AXO_CARGO_HOME', $dest_dir.replace("\", "\\"))

$dest_dir = New-Item -Force -ItemType Directory -Path $dest_dir
Write-Information "Installing to $dest_dir"
Expand Down
6 changes: 3 additions & 3 deletions cargo-dist/tests/snapshots/axolotlsay_abyss.snap
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -297,7 +297,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down Expand Up @@ -1029,7 +1029,7 @@ function Invoke-Installer($bin_paths) {
$dest_dir = Join-Path $root "bin"

# The replace call here ensures proper escaping is inlined into the receipt
$receipt = $receipt.Replace('AXO_CARGO_HOME', $root.replace("\", "\\"))
$receipt = $receipt.Replace('AXO_CARGO_HOME', $dest_dir.replace("\", "\\"))

$dest_dir = New-Item -Force -ItemType Directory -Path $dest_dir
Write-Information "Installing to $dest_dir"
Expand Down
6 changes: 3 additions & 3 deletions cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -297,7 +297,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down Expand Up @@ -1029,7 +1029,7 @@ function Invoke-Installer($bin_paths) {
$dest_dir = Join-Path $root "bin"

# The replace call here ensures proper escaping is inlined into the receipt
$receipt = $receipt.Replace('AXO_CARGO_HOME', $root.replace("\", "\\"))
$receipt = $receipt.Replace('AXO_CARGO_HOME', $dest_dir.replace("\", "\\"))

$dest_dir = New-Item -Force -ItemType Directory -Path $dest_dir
Write-Information "Installing to $dest_dir"
Expand Down
6 changes: 3 additions & 3 deletions cargo-dist/tests/snapshots/axolotlsay_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -297,7 +297,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down Expand Up @@ -1029,7 +1029,7 @@ function Invoke-Installer($bin_paths) {
$dest_dir = Join-Path $root "bin"

# The replace call here ensures proper escaping is inlined into the receipt
$receipt = $receipt.Replace('AXO_CARGO_HOME', $root.replace("\", "\\"))
$receipt = $receipt.Replace('AXO_CARGO_HOME', $dest_dir.replace("\", "\\"))

$dest_dir = New-Item -Force -ItemType Directory -Path $dest_dir
Write-Information "Installing to $dest_dir"
Expand Down
6 changes: 3 additions & 3 deletions cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -297,7 +297,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down Expand Up @@ -1029,7 +1029,7 @@ function Invoke-Installer($bin_paths) {
$dest_dir = Join-Path $root "bin"

# The replace call here ensures proper escaping is inlined into the receipt
$receipt = $receipt.Replace('AXO_CARGO_HOME', $root.replace("\", "\\"))
$receipt = $receipt.Replace('AXO_CARGO_HOME', $dest_dir.replace("\", "\\"))

$dest_dir = New-Item -Force -ItemType Directory -Path $dest_dir
Write-Information "Installing to $dest_dir"
Expand Down
4 changes: 2 additions & 2 deletions cargo-dist/tests/snapshots/axolotlsay_musl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -309,7 +309,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down
4 changes: 2 additions & 2 deletions cargo-dist/tests/snapshots/axolotlsay_musl_no_gnu.snap
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -309,7 +309,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -297,7 +297,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down Expand Up @@ -1029,7 +1029,7 @@ function Invoke-Installer($bin_paths) {
$dest_dir = Join-Path $root "bin"

# The replace call here ensures proper escaping is inlined into the receipt
$receipt = $receipt.Replace('AXO_CARGO_HOME', $root.replace("\", "\\"))
$receipt = $receipt.Replace('AXO_CARGO_HOME', $dest_dir.replace("\", "\\"))

$dest_dir = New-Item -Force -ItemType Directory -Path $dest_dir
Write-Information "Installing to $dest_dir"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -297,7 +297,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down Expand Up @@ -983,7 +983,7 @@ function Invoke-Installer($bin_paths) {
$dest_dir = Join-Path $root "bin"

# The replace call here ensures proper escaping is inlined into the receipt
$receipt = $receipt.Replace('AXO_CARGO_HOME', $root.replace("\", "\\"))
$receipt = $receipt.Replace('AXO_CARGO_HOME', $dest_dir.replace("\", "\\"))

$dest_dir = New-Item -Force -ItemType Directory -Path $dest_dir
Write-Information "Installing to $dest_dir"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ download_binary_and_run_installer() {
esac

# Replace the placeholder binaries with the calculated array from above
RECEIPT="$(echo "$RECEIPT" | sed s,'"CARGO_DIST_BINS"',"$_bins_js_array",)"
RECEIPT="$(echo "$RECEIPT" | sed s/'"CARGO_DIST_BINS"'/"$_bins_js_array"/)"

# download the archive
local _url="$ARTIFACT_DOWNLOAD_URL/$_artifact_name"
Expand Down Expand Up @@ -297,7 +297,7 @@ install() {
err "could not find your CARGO_HOME or HOME dir to install binaries to"
fi
# Replace the temporary cargo home with the calculated one
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_home,")
RECEIPT=$(echo "$RECEIPT" | sed "s,AXO_CARGO_HOME,$_install_dir,")

say "installing to $_install_dir"
ensure mkdir -p "$_install_dir"
Expand Down Expand Up @@ -983,7 +983,7 @@ function Invoke-Installer($bin_paths) {
$dest_dir = Join-Path $root "bin"

# The replace call here ensures proper escaping is inlined into the receipt
$receipt = $receipt.Replace('AXO_CARGO_HOME', $root.replace("\", "\\"))
$receipt = $receipt.Replace('AXO_CARGO_HOME', $dest_dir.replace("\", "\\"))

$dest_dir = New-Item -Force -ItemType Directory -Path $dest_dir
Write-Information "Installing to $dest_dir"
Expand Down
Loading