Skip to content
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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ uuid = { version = "1.18.1", features = ["v4"] }
camino = "1.1.12"
regex = "1"
linkme = "0.3.30"
paste = "1.0"

[lints]
workspace = true
50 changes: 50 additions & 0 deletions crates/integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,56 @@ pub static INTEGRATION_TESTS: [IntegrationTest];
#[distributed_slice]
pub static PARAMETERIZED_INTEGRATION_TESTS: [ParameterizedIntegrationTest];

/// Register an integration test with less boilerplate.
///
/// This macro generates the static registration for an integration test function.
///
/// # Examples
///
/// ```ignore
/// fn test_basic_functionality() -> Result<()> {
/// let output = run_bcvk(&["some", "args"])?;
/// output.assert_success("test");
/// Ok(())
/// }
/// integration_test!(test_basic_functionality);
/// ```
#[macro_export]
macro_rules! integration_test {
($fn_name:ident) => {
::paste::paste! {
#[distributed_slice($crate::INTEGRATION_TESTS)]
static [<$fn_name:upper>]: $crate::IntegrationTest =
$crate::IntegrationTest::new(stringify!($fn_name), $fn_name);
}
};
}

/// Register a parameterized integration test with less boilerplate.
///
/// This macro generates the static registration for a parameterized integration test function.
///
/// # Examples
///
/// ```ignore
/// fn test_with_image(image: &str) -> Result<()> {
/// let output = run_bcvk(&["command", image])?;
/// output.assert_success("test");
/// Ok(())
/// }
/// parameterized_integration_test!(test_with_image);
/// ```
#[macro_export]
macro_rules! parameterized_integration_test {
($fn_name:ident) => {
::paste::paste! {
#[distributed_slice($crate::PARAMETERIZED_INTEGRATION_TESTS)]
static [<$fn_name:upper>]: $crate::ParameterizedIntegrationTest =
$crate::ParameterizedIntegrationTest::new(stringify!($fn_name), $fn_name);
}
};
}

/// Create a test suffix from an image name by replacing invalid characters with underscores
///
/// Replaces all non-alphanumeric characters with `_` to create a predictable, filesystem-safe
Expand Down
35 changes: 8 additions & 27 deletions crates/integration-tests/src/tests/libvirt_base_disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
//! - base-disks prune command

use color_eyre::Result;
use integration_tests::integration_test;
use linkme::distributed_slice;

use regex::Regex;
use std::process::Command;

use crate::{get_bck_command, get_test_image, run_bcvk, IntegrationTest, INTEGRATION_TESTS};

#[distributed_slice(INTEGRATION_TESTS)]
static TEST_BASE_DISK_CREATION_AND_REUSE: IntegrationTest = IntegrationTest::new(
"test_base_disk_creation_and_reuse",
test_base_disk_creation_and_reuse,
);
use crate::{get_bck_command, get_test_image, run_bcvk};

/// Test that base disk is created and reused for multiple VMs
fn test_base_disk_creation_and_reuse() -> Result<()> {
Expand Down Expand Up @@ -99,10 +95,7 @@ fn test_base_disk_creation_and_reuse() -> Result<()> {
println!("✓ Base disk creation and reuse test passed");
Ok(())
}

#[distributed_slice(INTEGRATION_TESTS)]
static TEST_BASE_DISKS_LIST_COMMAND: IntegrationTest =
IntegrationTest::new("test_base_disks_list_command", test_base_disks_list_command);
integration_test!(test_base_disk_creation_and_reuse);

/// Test base-disks list command
fn test_base_disks_list_command() -> Result<()> {
Expand Down Expand Up @@ -143,12 +136,7 @@ fn test_base_disks_list_command() -> Result<()> {
}
Ok(())
}

#[distributed_slice(INTEGRATION_TESTS)]
static TEST_BASE_DISKS_LIST_SHOWS_TIMESTAMP: IntegrationTest = IntegrationTest::new(
"test_base_disks_list_shows_timestamp",
test_base_disks_list_shows_timestamp,
);
integration_test!(test_base_disks_list_command);

/// Test base-disks list shows creation timestamp
fn test_base_disks_list_shows_timestamp() -> Result<()> {
Expand Down Expand Up @@ -218,12 +206,7 @@ fn test_base_disks_list_shows_timestamp() -> Result<()> {
}
Ok(())
}

#[distributed_slice(INTEGRATION_TESTS)]
static TEST_BASE_DISKS_PRUNE_DRY_RUN: IntegrationTest = IntegrationTest::new(
"test_base_disks_prune_dry_run",
test_base_disks_prune_dry_run,
);
integration_test!(test_base_disks_list_shows_timestamp);

/// Test base-disks prune command with dry-run
fn test_base_disks_prune_dry_run() -> Result<()> {
Expand Down Expand Up @@ -260,10 +243,7 @@ fn test_base_disks_prune_dry_run() -> Result<()> {
}
Ok(())
}

#[distributed_slice(INTEGRATION_TESTS)]
static TEST_VM_DISK_REFERENCES_BASE: IntegrationTest =
IntegrationTest::new("test_vm_disk_references_base", test_vm_disk_references_base);
integration_test!(test_base_disks_prune_dry_run);

/// Test that VM disks reference base disks correctly
fn test_vm_disk_references_base() -> Result<()> {
Expand Down Expand Up @@ -336,6 +316,7 @@ fn test_vm_disk_references_base() -> Result<()> {
println!("✓ VM disk reference test passed");
Ok(())
}
integration_test!(test_vm_disk_references_base);

/// Helper function to cleanup domain and its disk
fn cleanup_domain(domain_name: &str) {
Expand Down
35 changes: 7 additions & 28 deletions crates/integration-tests/src/tests/libvirt_port_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@
//! - Actual network connectivity through forwarded ports

use color_eyre::Result;
use integration_tests::integration_test;
use linkme::distributed_slice;
use std::process::Command;

use crate::{
get_bck_command, get_test_image, run_bcvk, IntegrationTest, INTEGRATION_TESTS,
LIBVIRT_INTEGRATION_TEST_LABEL,
};
use std::process::Command;

#[distributed_slice(INTEGRATION_TESTS)]
static TEST_LIBVIRT_PORT_FORWARD_PARSING: IntegrationTest = IntegrationTest::new(
"test_libvirt_port_forward_parsing",
test_libvirt_port_forward_parsing,
);
use crate::{get_bck_command, get_test_image, run_bcvk, LIBVIRT_INTEGRATION_TEST_LABEL};

/// Test port forwarding argument parsing
fn test_libvirt_port_forward_parsing() -> Result<()> {
Expand Down Expand Up @@ -63,12 +56,7 @@ fn test_libvirt_port_forward_parsing() -> Result<()> {
println!("✓ Port forwarding argument parsing validated");
Ok(())
}

#[distributed_slice(INTEGRATION_TESTS)]
static TEST_LIBVIRT_PORT_FORWARD_INVALID: IntegrationTest = IntegrationTest::new(
"test_libvirt_port_forward_invalid",
test_libvirt_port_forward_invalid,
);
integration_test!(test_libvirt_port_forward_parsing);

/// Test port forwarding error handling for invalid formats
fn test_libvirt_port_forward_invalid() -> Result<()> {
Expand Down Expand Up @@ -134,12 +122,7 @@ fn test_libvirt_port_forward_invalid() -> Result<()> {
println!("✓ Port forwarding error handling validated");
Ok(())
}

#[distributed_slice(INTEGRATION_TESTS)]
static TEST_LIBVIRT_PORT_FORWARD_XML: IntegrationTest = IntegrationTest::new(
"test_libvirt_port_forward_xml",
test_libvirt_port_forward_xml,
);
integration_test!(test_libvirt_port_forward_invalid);

/// Test that port forwarding is correctly configured in domain XML
fn test_libvirt_port_forward_xml() -> Result<()> {
Expand Down Expand Up @@ -247,12 +230,7 @@ fn test_libvirt_port_forward_xml() -> Result<()> {
println!("✓ Port forwarding XML configuration test passed");
Ok(())
}

#[distributed_slice(INTEGRATION_TESTS)]
static TEST_LIBVIRT_PORT_FORWARD_CONNECTIVITY: IntegrationTest = IntegrationTest::new(
"test_libvirt_port_forward_connectivity",
test_libvirt_port_forward_connectivity,
);
integration_test!(test_libvirt_port_forward_xml);

/// Test actual network connectivity through forwarded ports
fn test_libvirt_port_forward_connectivity() -> Result<()> {
Expand Down Expand Up @@ -437,6 +415,7 @@ fn test_libvirt_port_forward_connectivity() -> Result<()> {
println!("✓ Port forwarding connectivity test passed");
Ok(())
}
integration_test!(test_libvirt_port_forward_connectivity);

/// Helper function to cleanup domain
fn cleanup_domain(domain_name: &str) {
Expand Down
Loading