From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-network 03/10] tests: use Test::Differences to make test assertions
Date: Tue, 3 Feb 2026 17:01:21 +0100 [thread overview]
Message-ID: <20260203160246.353351-15-g.goller@proxmox.com> (raw)
In-Reply-To: <20260203160246.353351-1-g.goller@proxmox.com>
Test::Differences provides a much better output. Instead of dumping the
whole file, eq_or_diff shows a pretty diff table with the changes
side-by-side. It also shows a small context and not the whole
expected/got file. This is very useful when especially when tests fails
on bigger config files.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
debian/control | 1 +
src/test/run_test_dns.pl | 15 +++++++-------
src/test/run_test_ipams.pl | 13 ++++++------
src/test/run_test_subnets.pl | 31 +++++++++++++++--------------
src/test/run_test_vnets_blackbox.pl | 23 +++++++++++++--------
src/test/run_test_zones.pl | 5 +++--
6 files changed, 50 insertions(+), 38 deletions(-)
diff --git a/debian/control b/debian/control
index ee7b2d40dfe2..6fe98822e64c 100644
--- a/debian/control
+++ b/debian/control
@@ -9,6 +9,7 @@ Build-Depends: debhelper-compat (= 13),
libnet-subnet-perl,
libpve-rs-perl (>= 0.11.1),
libtest-mockmodule-perl,
+ libtest-differences-perl,
perl,
pve-cluster (>= 9.0.1),
pve-firewall (>= 5.1.0~),
diff --git a/src/test/run_test_dns.pl b/src/test/run_test_dns.pl
index 26fbfaf035d2..f099da04a777 100755
--- a/src/test/run_test_dns.pl
+++ b/src/test/run_test_dns.pl
@@ -9,6 +9,7 @@ use Net::IP;
use Test::More;
use Test::MockModule;
+use Test::Differences;
use PVE::Network::SDN;
use PVE::Network::SDN::Zones;
@@ -101,7 +102,7 @@ foreach my $path (@plugins) {
$plugin->add_a_record($plugin_config, $zone, $hostname, $ip, 1);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
@@ -114,7 +115,7 @@ foreach my $path (@plugins) {
$plugin->add_ptr_record($plugin_config, $zone, $hostname, $ip, 1);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
@@ -127,7 +128,7 @@ foreach my $path (@plugins) {
$plugin->del_ptr_record($plugin_config, $zone, $ip, 1);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
@@ -167,7 +168,7 @@ foreach my $path (@plugins) {
$plugin->del_a_record($plugin_config, $zone, $hostname, $ip, 1);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
@@ -212,7 +213,7 @@ foreach my $path (@plugins) {
$plugin->del_a_record($plugin_config, $zone, $hostname, $ip, 1);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
@@ -250,7 +251,7 @@ foreach my $path (@plugins) {
$plugin->add_a_record($plugin_config, $zone, $hostname, $ip, 1);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
@@ -264,7 +265,7 @@ foreach my $path (@plugins) {
$plugin->verify_zone($plugin_config, $zone, 1);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
diff --git a/src/test/run_test_ipams.pl b/src/test/run_test_ipams.pl
index 193b34bb98d9..f9c44fe1a3b9 100755
--- a/src/test/run_test_ipams.pl
+++ b/src/test/run_test_ipams.pl
@@ -8,6 +8,7 @@ use File::Slurp;
use Test::More;
use Test::MockModule;
+use Test::Differences;
use PVE::Network::SDN;
use PVE::Network::SDN::Zones;
@@ -120,7 +121,7 @@ foreach my $path (@plugins) {
);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
@@ -133,7 +134,7 @@ foreach my $path (@plugins) {
$plugin->add_next_freeip($plugin_config, $subnetid, $subnet, $hostname, $mac, $description, 1);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
@@ -146,7 +147,7 @@ foreach my $path (@plugins) {
$plugin->del_ip($plugin_config, $subnetid, $subnet, $ip, 1);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
@@ -168,7 +169,7 @@ foreach my $path (@plugins) {
);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
@@ -192,7 +193,7 @@ foreach my $path (@plugins) {
);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
@@ -211,7 +212,7 @@ foreach my $path (@plugins) {
$plugin->add_subnet($plugin_config, $subnetid, $subnet, 1);
if ($@) {
- is($@, $expected, $name);
+ eq_or_diff($@, $expected, $name);
} else {
fail($name);
}
diff --git a/src/test/run_test_subnets.pl b/src/test/run_test_subnets.pl
index d4f8d6616de3..16443bf7ee26 100755
--- a/src/test/run_test_subnets.pl
+++ b/src/test/run_test_subnets.pl
@@ -8,6 +8,7 @@ use File::Slurp;
use Test::More;
use Test::MockModule;
+use Test::Differences;
use PVE::Network::SDN;
use PVE::Network::SDN::Zones;
@@ -147,9 +148,9 @@ foreach my $path (@plugins) {
fail("$name : $@");
} elsif ($ipam) {
$result = $js->encode($plugin->read_db());
- is($result, $expected, $name);
+ eq_or_diff($result, $expected, $name);
} else {
- is(undef, undef, $name);
+ eq_or_diff(undef, undef, $name);
}
## add_ip
@@ -173,9 +174,9 @@ foreach my $path (@plugins) {
fail("$name : $@");
} elsif ($ipam) {
$result = $js->encode($plugin->read_db());
- is($result, $expected, $name);
+ eq_or_diff($result, $expected, $name);
} else {
- is(undef, undef, $name);
+ eq_or_diff(undef, undef, $name);
}
if ($ipam) {
@@ -190,7 +191,7 @@ foreach my $path (@plugins) {
};
if ($@) {
- is(undef, undef, $name);
+ eq_or_diff(undef, undef, $name);
} else {
fail("$name : $@");
}
@@ -225,9 +226,9 @@ foreach my $path (@plugins) {
fail("$name : $@");
} elsif ($ipam) {
$result = $js->encode($plugin->read_db());
- is($result, $expected, $name);
+ eq_or_diff($result, $expected, $name);
} else {
- is(undef, undef, $name);
+ eq_or_diff(undef, undef, $name);
}
## add_next_free
@@ -266,7 +267,7 @@ foreach my $path (@plugins) {
fail("$name : $@");
} elsif ($ipam) {
$result = $js->encode($plugin->read_db());
- is($result, $expected, $name);
+ eq_or_diff($result, $expected, $name);
}
## del_ip
@@ -299,9 +300,9 @@ foreach my $path (@plugins) {
fail("$name : $@");
} elsif ($ipam) {
$result = $js->encode($plugin->read_db());
- is($result, $expected, $name);
+ eq_or_diff($result, $expected, $name);
} else {
- is(undef, undef, $name);
+ eq_or_diff(undef, undef, $name);
}
if ($ipam) {
@@ -314,7 +315,7 @@ foreach my $path (@plugins) {
eval { PVE::Network::SDN::Subnets::del_subnet($zone, $subnetid, $subnet); };
if ($@) {
- is($result, $expected, $name);
+ eq_or_diff($result, $expected, $name);
} else {
fail("$name : $@");
}
@@ -367,9 +368,9 @@ foreach my $path (@plugins) {
if ($@) {
if ($ipam) {
$result = $js->encode($plugin->read_db());
- is($result, $expected, $name);
+ eq_or_diff($result, $expected, $name);
} else {
- is(undef, undef, $name);
+ eq_or_diff(undef, undef, $name);
}
} else {
fail("$name : $@");
@@ -390,9 +391,9 @@ foreach my $path (@plugins) {
fail("$name : $@");
} elsif ($ipam) {
$result = $js->encode($plugin->read_db());
- is($result, $expected, $name);
+ eq_or_diff($result, $expected, $name);
} else {
- is(undef, undef, $name);
+ eq_or_diff(undef, undef, $name);
}
}
diff --git a/src/test/run_test_vnets_blackbox.pl b/src/test/run_test_vnets_blackbox.pl
index 468b1ede17e2..9f4c424f3d2f 100755
--- a/src/test/run_test_vnets_blackbox.pl
+++ b/src/test/run_test_vnets_blackbox.pl
@@ -10,6 +10,7 @@ use NetAddr::IP qw(:lower);
use Test::More;
use Test::MockModule;
+use Test::Differences;
use PVE::Tools qw(extract_param file_set_contents);
@@ -416,7 +417,7 @@ sub test_without_subnet {
my @ips = get_ips_from_mac($mac);
my $num_ips = scalar @ips;
- is($num_ips, 0, "$test_name: No IP allocated in IPAM");
+ eq_or_diff($num_ips, 0, "$test_name: No IP allocated in IPAM");
}
run_test(\&test_without_subnet);
@@ -463,7 +464,7 @@ sub test_nic_join {
my @ips = get_ips_from_mac($mac);
my $num_ips = scalar @ips;
- is($num_ips, $num_subnets, "$test_name: Expecting $num_subnets IPs, found $num_ips");
+ eq_or_diff($num_ips, $num_subnets, "$test_name: Expecting $num_subnets IPs, found $num_ips");
ok(
(all { ($_->{vnet} eq $vnetid && $_->{zone} eq $zoneid) } @ips),
"$test_name: all IPs in correct vnet and zone",
@@ -622,7 +623,7 @@ sub test_nic_join_full_dhcp_range {
my @ips = get_ips_from_mac($mac);
my $num_ips = scalar @ips;
- is($num_ips, 0, "$test_name: No IP allocated in IPAM");
+ eq_or_diff($num_ips, 0, "$test_name: No IP allocated in IPAM");
}
run_test(
@@ -770,9 +771,9 @@ sub test_nic_start {
});
}
my @current_ips = get_ips_from_mac($mac);
- is(get_ip4(@current_ips), $current_ip4, "$test_name: setup current IPv4: $current_ip4")
+ eq_or_diff(get_ip4(@current_ips), $current_ip4, "$test_name: setup current IPv4: $current_ip4")
if defined $current_ip4;
- is(get_ip6(@current_ips), $current_ip6, "$test_name: setup current IPv6: $current_ip6")
+ eq_or_diff(get_ip6(@current_ips), $current_ip6, "$test_name: setup current IPv6: $current_ip6")
if defined $current_ip6;
eval { nic_start($vnetid, $mac, $hostname, $vmid); };
@@ -784,14 +785,20 @@ sub test_nic_start {
my @ips = get_ips_from_mac($mac);
my $num_ips = scalar @ips;
- is($num_ips, $num_expected_ips, "$test_name: Expecting $num_expected_ips IPs, found $num_ips");
+ eq_or_diff(
+ $num_ips,
+ $num_expected_ips,
+ "$test_name: Expecting $num_expected_ips IPs, found $num_ips",
+ );
ok(
(all { ($_->{vnet} eq $vnetid && $_->{zone} eq $zoneid) } @ips),
"$test_name: all IPs in correct vnet and zone",
);
- is(get_ip4(@ips), $current_ip4, "$test_name: still current IPv4: $current_ip4") if $current_ip4;
- is(get_ip6(@ips), $current_ip6, "$test_name: still current IPv6: $current_ip6") if $current_ip6;
+ eq_or_diff(get_ip4(@ips), $current_ip4, "$test_name: still current IPv4: $current_ip4")
+ if $current_ip4;
+ eq_or_diff(get_ip6(@ips), $current_ip6, "$test_name: still current IPv6: $current_ip6")
+ if $current_ip6;
}
run_test(
diff --git a/src/test/run_test_zones.pl b/src/test/run_test_zones.pl
index 917f40a90069..905b2f42e1dc 100755
--- a/src/test/run_test_zones.pl
+++ b/src/test/run_test_zones.pl
@@ -8,6 +8,7 @@ use File::Slurp;
use Test::More;
use Test::MockModule;
+use Test::Differences;
use PVE::Network::SDN;
use PVE::Network::SDN::Zones;
@@ -140,7 +141,7 @@ foreach my $test (@tests) {
diag("got unexpected error - $err");
fail($name);
} else {
- is($result, $expected, $name);
+ eq_or_diff($result, $expected, $name);
}
if ($sdn_config->{controllers}) {
@@ -155,7 +156,7 @@ foreach my $test (@tests) {
diag("got unexpected error - $err");
fail($name);
} else {
- is($config, $expected, $name);
+ eq_or_diff($config, $expected, $name);
}
}
}
--
2.47.3
next prev parent reply other threads:[~2026-02-03 16:04 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-03 16:01 [PATCH docs/manager/network/proxmox{-ve-rs,-perl-rs} 00/23] Generate frr config using jinja templates and rust types Gabriel Goller
2026-02-03 16:01 ` [PATCH proxmox-ve-rs 1/9] ve-config: firewall: cargo fmt Gabriel Goller
2026-02-03 16:01 ` [PATCH proxmox-ve-rs 2/9] frr: add proxmox-frr-templates package that contains templates Gabriel Goller
2026-02-03 16:01 ` [PATCH proxmox-ve-rs 3/9] ve-config: remove FrrConfigBuilder struct Gabriel Goller
2026-02-03 16:01 ` [PATCH proxmox-ve-rs 4/9] sdn-types: support variable-length NET identifier Gabriel Goller
2026-02-03 16:01 ` [PATCH proxmox-ve-rs 5/9] frr: add template serializer and serialize fabrics using templates Gabriel Goller
2026-02-03 16:01 ` [PATCH proxmox-ve-rs 6/9] frr: add isis configuration and templates Gabriel Goller
2026-02-03 16:01 ` [PATCH proxmox-ve-rs 7/9] frr: support custom frr configuration lines Gabriel Goller
2026-02-03 16:01 ` [PATCH proxmox-ve-rs 8/9] frr: add bgp support with templates and serialization Gabriel Goller
2026-02-03 16:01 ` [PATCH proxmox-ve-rs 9/9] frr: store frr template content as a const map Gabriel Goller
2026-02-03 16:01 ` [PATCH proxmox-perl-rs 1/2] sdn: add function to generate the frr config for all daemons Gabriel Goller
2026-02-03 16:01 ` [PATCH proxmox-perl-rs 2/2] sdn: add method to get a frr template Gabriel Goller
2026-02-03 16:01 ` [PATCH pve-network 01/10] sdn: remove duplicate comment line '!' in frr config Gabriel Goller
2026-02-03 16:01 ` [PATCH pve-network 02/10] sdn: tests: add missing comment " Gabriel Goller
2026-02-03 16:01 ` Gabriel Goller [this message]
2026-02-03 16:01 ` [PATCH pve-network 04/10] sdn: write structured frr config that can be rendered using templates Gabriel Goller
2026-02-03 16:01 ` [PATCH pve-network 05/10] tests: rearrange some statements in the frr config Gabriel Goller
2026-02-03 16:01 ` [PATCH pve-network 06/10] sdn: adjust frr.conf.local merging to rust template types Gabriel Goller
2026-02-03 16:01 ` [PATCH pve-network 07/10] cli: add pvesdn cli tool for managing frr template overrides Gabriel Goller
2026-02-03 16:01 ` [PATCH pve-network 08/10] debian: handle user modifications to FRR templates via ucf Gabriel Goller
2026-02-03 16:01 ` [PATCH pve-network 09/10] api: add dry-run endpoint for sdn apply to preview changes Gabriel Goller
2026-02-03 16:01 ` [PATCH pve-network 10/10] test: add test for frr.conf.local merging Gabriel Goller
2026-02-03 16:01 ` [PATCH pve-manager 1/1] sdn: add dry-run view for sdn apply Gabriel Goller
2026-02-03 16:01 ` [PATCH pve-docs 1/1] docs: add man page for the `pvesdn` cli Gabriel Goller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260203160246.353351-15-g.goller@proxmox.com \
--to=g.goller@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox