2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-21 07:08:12 +00:00
Files
xcat-core/xCAT-test/unit/tableutils_delete_rows.t
Vinícius Ferrão 67ada58599 test(tableutils): cover the delete of rows from several tables
delete_rows must delete the rows of the keys from every table that
opens. When a named table does not open, first, last or between two
tables, it must return that table and delete no row.
2026-10-14 13:14:42 -03:00

48 lines
1.7 KiB
Perl

#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
use File::Path qw(make_path);
use File::Temp qw(tempdir);
use Test::More;
my $fixture = tempdir(CLEANUP => 1);
make_path("$fixture/db");
local $ENV{XCATCFG} = "SQLite:$fixture/db";
require xCAT::Table;
require xCAT::TableUtils;
for my $table (qw(nodehm noderes)) {
xCAT::Table->new($table, -create => 1)->setAttribs({ node => $_ }, { comments => "row of $_" }) for qw(n1 n2 n3);
}
sub nodes {
my ($table) = @_;
return join(',', sort map { $_->{node} } xCAT::Table->new($table)->getAllAttribs('node'));
}
sub delete_rows {
my @args = @_;
my $missing = eval { xCAT::TableUtils->delete_rows(@args) };
return ($missing, $@);
}
my ($missing, $error) = delete_rows({ node => 'n1' }, 'nodehm', 'noderes');
is($error, '', 'rows are deleted from tables that open');
is($missing, undef, 'no table is reported when every table opens');
is(nodes('nodehm'), 'n2,n3', 'the row of the key is deleted from the first table');
is(nodes('noderes'), 'n2,n3', 'the row of the key is deleted from the last table');
for my $case ([ 'between two tables', 'nodehm', 'notatable', 'noderes' ], [ 'first', 'notatable', 'nodehm', 'noderes' ],
[ 'last', 'nodehm', 'noderes', 'notatable' ]) {
my ($label, @tables) = @$case;
($missing, $error) = delete_rows({ node => 'n2' }, @tables);
is($error, '', "a missing table named $label does not die");
is($missing, 'notatable', "a missing table named $label is returned");
is(nodes('nodehm'), 'n2,n3', "nodehm keeps its rows when a missing table is named $label");
is(nodes('noderes'), 'n2,n3', "noderes keeps its rows when a missing table is named $label");
}
done_testing();