Skip to content
Merged
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
62 changes: 60 additions & 2 deletions pkgs/id/src/currency_poc/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ pub fn verify_pinned_version(binary: &PathBuf) -> Result<()> {
.output()
.with_context(|| format!("running {} version", binary.display()))?;
let text = String::from_utf8_lossy(&output.stdout);
if !output.status.success() || !text.contains(TIGERBEETLE_PINNED_VERSION) {
let reported_version = text
.lines()
.next()
.and_then(|line| line.trim().strip_prefix("TigerBeetle version "));
if !output.status.success() || reported_version != Some(TIGERBEETLE_PINNED_VERSION) {
bail!(
"tigerbeetle binary at {} reports {:?}, expected pinned version {} \
"tigerbeetle binary at {} reports {:?}, expected exact pinned version {} \
(acquire it from {})",
binary.display(),
text.trim(),
Expand Down Expand Up @@ -152,6 +156,60 @@ impl Drop for TestCluster {
mod tests {
use super::*;

#[cfg(unix)]
fn stub_binary(version_output: &str, exit_code: i32) -> (tempfile::TempDir, PathBuf) {
use std::os::unix::fs::PermissionsExt;

let dir = tempfile::tempdir().expect("temporary directory");
fs::write(dir.path().join("version-output"), version_output).expect("write output");
let binary = dir.path().join("tigerbeetle");
fs::write(
&binary,
format!(
"#!/bin/sh\n[ \"$1\" = version ] || exit 2\ncat \"$(dirname \"$0\")/version-output\"\nexit {exit_code}\n"
),
)
.expect("write stub executable");
let mut permissions = fs::metadata(&binary).expect("stub metadata").permissions();
permissions.set_mode(0o755);
fs::set_permissions(&binary, permissions).expect("make stub executable");
(dir, binary)
}

#[cfg(unix)]
#[test]
fn accepts_exact_reported_version() {
let (_dir, binary) = stub_binary("TigerBeetle version 0.17.9\n", 0);

assert!(verify_pinned_version(&binary).is_ok());
}

#[cfg(unix)]
#[test]
fn rejects_nonexact_reported_versions() {
for output in [
"TigerBeetle version 0.17.99\n",
"TigerBeetle version 0.17.90\n",
"TigerBeetle version 0.16.0\n",
"TigerBeetle build deadbee0.17.9custom\n",
] {
let (_dir, binary) = stub_binary(output, 0);

assert!(
verify_pinned_version(&binary).is_err(),
"should reject version output {output:?}"
);
}
}

#[cfg(unix)]
#[test]
fn rejects_nonzero_version_command_even_when_version_matches() {
let (_dir, binary) = stub_binary("TigerBeetle version 0.17.9\n", 1);

assert!(verify_pinned_version(&binary).is_err());
}

/// Step-0 smoke test: the pinned binary formats and starts a
/// single-replica cluster and stops cleanly. Ignored by default —
/// it needs the pinned TigerBeetle binary (see module docs).
Expand Down
Loading