public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-network v2 3/9] tests: use Test::Differences to make test assertions
Date: Mon,  2 Mar 2026 13:55:31 +0100	[thread overview]
Message-ID: <20260302125701.196916-13-g.goller@proxmox.com> (raw)
In-Reply-To: <20260302125701.196916-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





  parent reply	other threads:[~2026-03-02 12:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-02 12:55 [PATCH manager/network/proxmox{-ve-rs,-perl-rs} v2 00/19] Generate frr config using jinja templates and rust types Gabriel Goller
2026-03-02 12:55 ` [PATCH proxmox-ve-rs v2 1/8] ve-config: firewall: cargo fmt Gabriel Goller
2026-03-02 12:55 ` [PATCH proxmox-ve-rs v2 2/8] frr: add proxmox-frr-templates package that contains templates Gabriel Goller
2026-03-02 12:55 ` [PATCH proxmox-ve-rs v2 3/8] ve-config: remove FrrConfigBuilder struct Gabriel Goller
2026-03-02 12:55 ` [PATCH proxmox-ve-rs v2 4/8] sdn-types: support variable-length NET identifier Gabriel Goller
2026-03-02 12:55 ` [PATCH proxmox-ve-rs v2 5/8] frr: add template serializer and serialize fabrics using templates Gabriel Goller
2026-03-02 12:55 ` [PATCH proxmox-ve-rs v2 6/8] frr: add isis configuration and templates Gabriel Goller
2026-03-02 12:55 ` [PATCH proxmox-ve-rs v2 7/8] frr: support custom frr configuration lines Gabriel Goller
2026-03-02 12:55 ` [PATCH proxmox-ve-rs v2 8/8] frr: add bgp support with templates and serialization Gabriel Goller
2026-03-02 12:55 ` [PATCH proxmox-perl-rs v2 1/1] sdn: add function to generate the frr config for all daemons Gabriel Goller
2026-03-02 12:55 ` [PATCH pve-network v2 1/9] sdn: remove duplicate comment line '!' in frr config Gabriel Goller
2026-03-02 12:55 ` [PATCH pve-network v2 2/9] sdn: tests: add missing comment " Gabriel Goller
2026-03-02 12:55 ` Gabriel Goller [this message]
2026-03-02 12:55 ` [PATCH pve-network v2 4/9] sdn: write structured frr config that can be rendered using templates Gabriel Goller
2026-03-02 12:55 ` [PATCH pve-network v2 5/9] tests: rearrange some statements in the frr config Gabriel Goller
2026-03-02 12:55 ` [PATCH pve-network v2 6/9] sdn: adjust frr.conf.local merging to rust template types Gabriel Goller
2026-03-03 15:19   ` Stefan Hanreich
2026-03-04 14:37     ` Gabriel Goller
2026-03-02 12:55 ` [PATCH pve-network v2 7/9] api: add dry-run endpoint for sdn apply to preview changes Gabriel Goller
2026-03-02 12:55 ` [PATCH pve-network v2 8/9] test: add test for frr.conf.local merging Gabriel Goller
2026-03-02 12:55 ` [PATCH pve-network v2 9/9] test: bgp: add some various integration tests Gabriel Goller
2026-03-02 12:55 ` [PATCH pve-manager v2 1/1] sdn: add dry-run diff view for sdn apply 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=20260302125701.196916-13-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal