From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 9CCFE1FF137 for ; Tue, 03 Feb 2026 17:04:18 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9E92325962; Tue, 3 Feb 2026 17:03:36 +0100 (CET) From: Gabriel Goller 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 Message-ID: <20260203160246.353351-15-g.goller@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203160246.353351-1-g.goller@proxmox.com> References: <20260203160246.353351-1-g.goller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1770134497237 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.003 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: ERTMQFGFS2ZRD2WGYURQZAWDQE2PMNPG X-Message-ID-Hash: ERTMQFGFS2ZRD2WGYURQZAWDQE2PMNPG X-MailFrom: g.goller@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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