From 5d39fc30d41dcddafb699878037534fb511d7eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Sun, 23 Aug 2026 11:08:59 -0300 Subject: [PATCH] test(utils): cover comma-list membership --- xCAT-test/unit/utils_comma_list.t | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 xCAT-test/unit/utils_comma_list.t diff --git a/xCAT-test/unit/utils_comma_list.t b/xCAT-test/unit/utils_comma_list.t new file mode 100644 index 000000000..4a9e98373 --- /dev/null +++ b/xCAT-test/unit/utils_comma_list.t @@ -0,0 +1,39 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../../perl-xCAT"; + +use Test::More; + +use xCAT::Utils; + +my @cases = ( + [undef, 'pdu', 0, 'undefined list does not match'], + ['', 'pdu', 0, 'empty list does not match'], + ['pdu', undef, 0, 'undefined target does not match'], + ['pdu', 'pdu', 1, 'single value matches'], + ['pdu,openbmc', 'openbmc', 1, 'comma-list value matches'], + [' pdu , openbmc ', 'pdu', 1, 'leading and trailing item whitespace is ignored'], + [' pdu , openbmc ', 'openbmc', 1, 'whitespace is ignored for later items'], + ['0', '0', 1, 'defined zero matches'], + ['not-pdu', 'pdu', 0, 'hyphenated prefix is not a match'], + ['pdu-extra', 'pdu', 0, 'hyphenated suffix is not a match'], + ['pdu.extra', 'pdu', 0, 'dotted suffix is not a match'], + ['.pdu,pdu.,-pdu,pdu-', '.pdu', 1, 'leading punctuation matches exactly'], + ['.pdu,pdu.,-pdu,pdu-', 'pdu.', 1, 'trailing punctuation matches exactly'], + ['.pdu,pdu.,-pdu,pdu-', '-pdu', 1, 'leading hyphen matches exactly'], + ['.pdu,pdu.,-pdu,pdu-', 'pdu-', 1, 'trailing hyphen matches exactly'], +); + +foreach my $case (@cases) { + my ($list, $value, $expected, $description) = @$case; + is( + xCAT::Utils->comma_list_contains($list, $value), + $expected, + $description, + ); +} + +done_testing();