From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH network 4/4] tests: use Test::Differences to make test assertions
Date: Fri, 19 Sep 2025 11:41:20 +0200 [thread overview]
Message-ID: <20250919094122.73373-9-g.goller@proxmox.com> (raw)
In-Reply-To: <20250919094122.73373-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 | 17 ++++++++--------
src/test/run_test_zones.pl | 5 +++--
6 files changed, 44 insertions(+), 38 deletions(-)
diff --git a/debian/control b/debian/control
index b45d12621aab..0501391ef282 100644
--- a/debian/control
+++ b/debian/control
@@ -8,6 +8,7 @@ Build-Depends: debhelper-compat (= 13),
libnet-subnet-perl,
libpve-rs-perl (>= 0.10.3),
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..a7025dc36e75 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,14 @@ 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
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
prev parent reply other threads:[~2025-09-19 9:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-19 9:41 [pve-devel] [RFC network/ve-rs 0/8] Template-based FRR config generation Gabriel Goller
2025-09-19 9:41 ` [pve-devel] [PATCH ve-rs 1/4] frr: add templates and structs to represent the frr config Gabriel Goller
2025-09-19 9:41 ` [pve-devel] [PATCH ve-rs 2/4] sdn-types: forward serialize to display for NET Gabriel Goller
2025-09-19 9:41 ` [pve-devel] [PATCH ve-rs 3/4] ve-config: fabrics: use new proxmox-frr structs to generate frr config Gabriel Goller
2025-09-19 9:41 ` [pve-devel] [PATCH ve-rs 4/4] tests: always prepend the frr delimiter/comment "!" to the block Gabriel Goller
2025-09-19 9:41 ` [pve-devel] [PATCH network 1/4] sdn: remove duplicate comment line '!' in frr config Gabriel Goller
2025-09-19 9:41 ` [pve-devel] [PATCH network 2/4] sdn: add trailing newline " Gabriel Goller
2025-09-19 9:41 ` [pve-devel] [PATCH network 3/4] sdn: tests: add missing comment '!' " Gabriel Goller
2025-09-19 9:41 ` Gabriel Goller [this message]
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=20250919094122.73373-9-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