From b27afb64e9d2b18e524ef3c957baa530ed5f9904 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Fri, 28 Dec 2007 17:55:25 +0000 Subject: * completed basic tests and started to work on tests for aggregated values (attributes) git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1436 95ad53e4-c205-0410-b2fa-d234c58c8868 --- config-db/OpenSLX/ConfigDB.pm | 12 ++- config-db/OpenSLX/DBSchema.pm | 1 + config-db/t/20-client_system_ref.t | 69 ++++++++++++- config-db/t/21-group_system_ref.t | 192 +++++++++++++++++++++++++++++++++++++ config-db/t/22-group_client_ref.t | 183 +++++++++++++++++++++++++++++++++++ config-db/t/25-attributes.t | 172 +++++++++++++++++++++++++++++++++ config-db/t/29-transaction.t | 55 +++++++++++ 7 files changed, 681 insertions(+), 3 deletions(-) create mode 100644 config-db/t/21-group_system_ref.t create mode 100644 config-db/t/22-group_client_ref.t create mode 100644 config-db/t/25-attributes.t create mode 100644 config-db/t/29-transaction.t (limited to 'config-db') diff --git a/config-db/OpenSLX/ConfigDB.pm b/config-db/OpenSLX/ConfigDB.pm index 9030311d..f4f9b0e2 100644 --- a/config-db/OpenSLX/ConfigDB.pm +++ b/config-db/OpenSLX/ConfigDB.pm @@ -1246,6 +1246,9 @@ sub setClientIDsOfSystem my $systemID = shift; my $clientIDs = _aref(shift); + # associating a client to the default system makes no sense + return 0 if $systemID == 0; + my @uniqueClientIDs = _unique(@$clientIDs); return $self->{'meta-db'}->setClientIDsOfSystem( @@ -1355,6 +1358,9 @@ sub setGroupIDsOfSystem my $systemID = shift; my $groupIDs = _aref(shift); + # associating a group to the default system makes no sense + return 0 if $systemID == 0; + my @uniqueGroupIDs = _unique(@$groupIDs); return $self->{'meta-db'}->setGroupIDsOfSystem($systemID, \@uniqueGroupIDs); @@ -1558,7 +1564,8 @@ sub setSystemIDsOfClient my $clientID = shift; my $systemIDs = _aref(shift); - my @uniqueSystemIDs = _unique(@$systemIDs); + # filter out the default system, as no client should be associated to it + my @uniqueSystemIDs = grep { $_ > 0; } _unique(@$systemIDs); return $self->{'meta-db'}->setSystemIDsOfClient( $clientID, \@uniqueSystemIDs @@ -1972,7 +1979,8 @@ sub setSystemIDsOfGroup my $groupID = shift; my $systemIDs = _aref(shift); - my @uniqueSystemIDs = _unique(@$systemIDs); + # filter out the default system, as no group should be associated to it + my @uniqueSystemIDs = grep { $_ > 0; } _unique(@$systemIDs); return $self->{'meta-db'}->setSystemIDsOfGroup($groupID, \@uniqueSystemIDs); } diff --git a/config-db/OpenSLX/DBSchema.pm b/config-db/OpenSLX/DBSchema.pm index 81a68399..6600edca 100644 --- a/config-db/OpenSLX/DBSchema.pm +++ b/config-db/OpenSLX/DBSchema.pm @@ -260,6 +260,7 @@ if ($lang =~ m[^\w\w_(\w\w)]) { { # add default system 'id' => 0, 'name' => '<<>>', + 'hidden' => 1, 'comment' => 'internal system that holds default values', # system-only attributes: 'attr_ramfs_nicmods' diff --git a/config-db/t/20-client_system_ref.t b/config-db/t/20-client_system_ref.t index ab7a3b2a..646050e3 100644 --- a/config-db/t/20-client_system_ref.t +++ b/config-db/t/20-client_system_ref.t @@ -111,7 +111,7 @@ is( ); is( @systemIDs = sort($configDB->fetchSystemIDsOfClient(1)), - 0, "client 1 should have no more system-IDs" + 0, "client 1 should have no system-IDs" ); is( @systemIDs = sort($configDB->fetchSystemIDsOfClient(3)), @@ -119,6 +119,15 @@ is( ); is($systemIDs[0], 1, "first system of client 3 should have ID 1"); +ok( + $configDB->addSystemIDsToClient(1, [0]), + 'associating the default system should have no effect' +); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfClient(1)), + 0, "client 1 should still have no system-ID" +); + ok( $configDB->removeClientIDsFromSystem(1, [1]), 'removing an unassociated client-ID should have no effect' @@ -135,4 +144,62 @@ is( @clientIDs = sort($configDB->fetchClientIDsOfSystem(1)), 0, "system 1 should have no more client-ID" ); + +$configDB->addSystem({ + 'name' => 'sys-4', + 'export_id' => 1, + 'comment' => 'shortlived', +}); +ok( + $configDB->addClientIDsToSystem(4, [0]), + 'default client has been associated to system 4' +); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfClient(0)), + 1, "default client should have one system-ID" +); +is($systemIDs[0], 4, "first system of default client should have ID 4"); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfClient(1)), + 0, "client 1 should have no system-ID" +); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfClient(3)), + 0, "client 3 should have no system-ID" +); +is( + @clientIDs = sort($configDB->fetchClientIDsOfSystem(0)), + 0, "default system should have no client-IDs" +); +is( + @clientIDs = sort($configDB->fetchClientIDsOfSystem(1)), + 0, "system 1 should have no client-ID" +); +is( + @clientIDs = sort($configDB->fetchClientIDsOfSystem(3)), + 0, "system 3 should have no client-IDs" +); +is( + @clientIDs = sort($configDB->fetchClientIDsOfSystem(4)), + 1, "system 4 should have one client-ID" +); +is($clientIDs[0], 0, "first client of system 4 should have ID 0"); + +ok( + $configDB->removeSystemIDsFromClient(0, [6]), + 'removing an unassociated system-ID should have no effect' +); +is( + @clientIDs = sort($configDB->fetchSystemIDsOfClient(0)), + 1, "default client should have one system-ID" +); +ok( + $configDB->removeSystem(4), + 'removing a system should drop client associations, too' +); +is( + @clientIDs = sort($configDB->fetchSystemIDsOfClient(0)), + 0, "default client should have no more system-ID" +); + $configDB->disconnect(); diff --git a/config-db/t/21-group_system_ref.t b/config-db/t/21-group_system_ref.t new file mode 100644 index 00000000..e9023feb --- /dev/null +++ b/config-db/t/21-group_system_ref.t @@ -0,0 +1,192 @@ +use Test::More qw(no_plan); + +use lib '/opt/openslx/lib'; + +# basic init +use OpenSLX::ConfigDB; + +my $configDB = OpenSLX::ConfigDB->new; +$configDB->connect(); + +# fetch groups & systems +my @groups = sort { $a->{id} <=> $b->{id} } $configDB->fetchGroupByFilter(); +is(@groups, 2, 'should have got 2 groups (1 and 3)'); +my $group1 = shift @groups; +my $group3 = shift @groups; + +my @systems = sort { $a->{id} <=> $b->{id} } $configDB->fetchSystemByFilter(); +is(@systems, 3, 'should have got 3 systems (default, 1 and 3)'); +my $defaultSystem = shift @systems; +my $system1 = shift @systems; +my $system3 = shift @systems; + +foreach my $group ($group1, $group3) { + is( + my @systemIDs = $configDB->fetchSystemIDsOfGroup($group->{id}), + 0, "group $group->{id} has no system-IDs yet" + ); +} + +foreach my $system ($defaultSystem, $system1, $system3) { + is( + my @groupIDs = $configDB->fetchGroupIDsOfSystem($system->{id}), + 0, "system $system->{id} has no group-IDs yet" + ); +} + +ok( + $configDB->addSystemIDsToGroup(1, [3]), + 'system-ID 3 has been associated to group 1' +); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfGroup(1)), + 1, "group 1 should have one system-ID" +); +is($systemIDs[0], 3, "first system of group 1 should have ID 3"); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfGroup(3)), + 0, "group 3 should have no system-ID" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(0)), + 0, "default system should have no group-IDs" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(1)), + 0, "system 1 should have no group-IDs" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(3)), + 1, "system 3 should have one group-ID" +); +is($groupIDs[0], 1, "first group of system 3 should have ID 1"); + +ok( + $configDB->addSystemIDsToGroup(3, [1,3,3,1,3]), + 'system-IDs 1 and 3 have been associated to group 3' +); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfGroup(1)), + 1, "group 1 should have one system-ID" +); +is($systemIDs[0], 3, "first system of group 1 should have ID 3"); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfGroup(3)), + 2, "group 3 should have two system-IDs" +); +is($systemIDs[0], 1, "first system of group 3 should have ID 1"); +is($systemIDs[1], 3, "second system of group 3 should have ID 3"); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(0)), + 0, "default system should have no group-ID" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(1)), + 1, "system 1 should have one group-ID" +); +is($groupIDs[0], 3, "first group of system 1 should have ID 3"); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(3)), + 2, "system 3 should have two group-IDs" +); +is($groupIDs[0], 1, "first group of system 3 should have ID 1"); +is($groupIDs[1], 3, "second group of system 3 should have ID 3"); + +ok( + $configDB->setGroupIDsOfSystem(3, []), + 'group-IDs of system 3 have been set to empty array' +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(3)), + 0, "system 3 should have no group-IDs" +); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfGroup(1)), + 0, "group 1 should have no more system-IDs" +); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfGroup(3)), + 1, "group 3 should have one system-ID" +); +is($systemIDs[0], 1, "first system of group 3 should have ID 1"); + +ok( + $configDB->addSystemIDsToGroup(1, [0]), + 'associating the default system should have no effect' +); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfGroup(1)), + 0, "group 1 should still have no system-ID" +); + +ok( + $configDB->removeGroupIDsFromSystem(1, [1]), + 'removing an unassociated group-ID should have no effect' +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(1)), + 1, "system 1 should have one group-ID" +); +ok( + $configDB->removeGroupIDsFromSystem(1, [3]), + 'removing an associated group-ID should work' +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(1)), + 0, "system 1 should have no more group-ID" +); + +$configDB->addSystem({ + 'name' => 'sys-5', + 'export_id' => 1, + 'comment' => 'shortlived', +}); +ok( + $configDB->addGroupIDsToSystem(5, [3]), + 'default group has been associated to system 5' +); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfGroup(1)), + 0, "group 1 should have no system-ID" +); +is( + @systemIDs = sort($configDB->fetchSystemIDsOfGroup(3)), + 1, "group 3 should have no system-ID" +); +is($systemIDs[0], 5, "first system of group 3 should have ID 5"); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(0)), + 0, "default system should have no group-IDs" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(1)), + 0, "system 1 should have no group-ID" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(3)), + 0, "system 3 should have no group-IDs" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfSystem(5)), + 1, "system 5 should have one group-ID" +); +is($groupIDs[0], 3, "first group of system 5 should have ID 3"); + +ok( + $configDB->removeSystemIDsFromGroup(3, [6]), + 'removing an unassociated system-ID should have no effect' +); +is( + @groupIDs = sort($configDB->fetchSystemIDsOfGroup(3)), + 1, "group 3 should have one system-ID" +); +ok( + $configDB->removeSystem(5), + 'removing a system should drop group associations, too' +); +is( + @groupIDs = sort($configDB->fetchSystemIDsOfGroup(3)), + 0, "group 3 should have no more system-ID" +); + +$configDB->disconnect(); diff --git a/config-db/t/22-group_client_ref.t b/config-db/t/22-group_client_ref.t new file mode 100644 index 00000000..240fcd61 --- /dev/null +++ b/config-db/t/22-group_client_ref.t @@ -0,0 +1,183 @@ +use Test::More qw(no_plan); + +use lib '/opt/openslx/lib'; + +# basic init +use OpenSLX::ConfigDB; + +my $configDB = OpenSLX::ConfigDB->new; +$configDB->connect(); + +# fetch groups & clients +my @groups = sort { $a->{id} <=> $b->{id} } $configDB->fetchGroupByFilter(); +is(@groups, 2, 'should have got 2 groups (1 and 3)'); +my $group1 = shift @groups; +my $group3 = shift @groups; + +my @clients = sort { $a->{id} <=> $b->{id} } $configDB->fetchClientByFilter(); +is(@clients, 3, 'should have got 3 clients (default, 1 and 3)'); +my $defaultClient = shift @clients; +my $client1 = shift @clients; +my $client3 = shift @clients; + +foreach my $group ($group1, $group3) { + is( + my @clientIDs = $configDB->fetchClientIDsOfGroup($group->{id}), + 0, "group $group->{id} has no client-IDs yet" + ); +} + +foreach my $client ($defaultClient, $client1, $client3) { + is( + my @groupIDs = $configDB->fetchGroupIDsOfClient($client->{id}), + 0, "client $client->{id} has no group-IDs yet" + ); +} + +ok( + $configDB->addClientIDsToGroup(1, [3]), + 'client-ID 3 has been associated to group 1' +); +is( + @clientIDs = sort($configDB->fetchClientIDsOfGroup(1)), + 1, "group 1 should have one client-ID" +); +is($clientIDs[0], 3, "first client of group 1 should have ID 3"); +is( + @clientIDs = sort($configDB->fetchClientIDsOfGroup(3)), + 0, "group 3 should have no client-ID" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(0)), + 0, "default client should have no group-IDs" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(1)), + 0, "client 1 should have no group-IDs" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(3)), + 1, "client 3 should have one group-ID" +); +is($groupIDs[0], 1, "first group of client 3 should have ID 1"); + +ok( + $configDB->addClientIDsToGroup(3, [1,3,3,1,3]), + 'client-IDs 1 and 3 have been associated to group 3' +); +is( + @clientIDs = sort($configDB->fetchClientIDsOfGroup(1)), + 1, "group 1 should have one client-ID" +); +is($clientIDs[0], 3, "first client of group 1 should have ID 3"); +is( + @clientIDs = sort($configDB->fetchClientIDsOfGroup(3)), + 2, "group 3 should have two client-IDs" +); +is($clientIDs[0], 1, "first client of group 3 should have ID 1"); +is($clientIDs[1], 3, "second client of group 3 should have ID 3"); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(0)), + 0, "default client should have no group-ID" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(1)), + 1, "client 1 should have one group-ID" +); +is($groupIDs[0], 3, "first group of client 1 should have ID 3"); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(3)), + 2, "client 3 should have two group-IDs" +); +is($groupIDs[0], 1, "first group of client 3 should have ID 1"); +is($groupIDs[1], 3, "second group of client 3 should have ID 3"); + +ok( + $configDB->setGroupIDsOfClient(3, []), + 'group-IDs of client 3 have been set to empty array' +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(3)), + 0, "client 3 should have no group-IDs" +); +is( + @clientIDs = sort($configDB->fetchClientIDsOfGroup(1)), + 0, "group 1 should have no more client-IDs" +); +is( + @clientIDs = sort($configDB->fetchClientIDsOfGroup(3)), + 1, "group 3 should have one client-ID" +); +is($clientIDs[0], 1, "first client of group 3 should have ID 1"); + +ok( + $configDB->removeGroupIDsFromClient(1, [1]), + 'removing an unassociated group-ID should have no effect' +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(1)), + 1, "client 1 should have one group-ID" +); +ok( + $configDB->removeGroupIDsFromClient(1, [3]), + 'removing an associated group-ID should work' +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(1)), + 0, "client 1 should have no more group-ID" +); + +$configDB->addClient({ + 'name' => 'cli-4', + 'mac' => '01:01:01:02:02:02', + 'comment' => 'shortlived', +}); +ok( + $configDB->addGroupIDsToClient(4, [3]), + 'default group has been associated to client 4' +); +is( + @clientIDs = sort($configDB->fetchClientIDsOfGroup(1)), + 0, "group 1 should have no client-ID" +); +is( + @clientIDs = sort($configDB->fetchClientIDsOfGroup(3)), + 1, "group 3 should have one client-ID" +); +is($clientIDs[0], 4, "first client of group 3 should have ID 1"); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(0)), + 0, "default client should have no group-IDs" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(1)), + 0, "client 1 should have no group-ID" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(3)), + 0, "client 3 should have no group-IDs" +); +is( + @groupIDs = sort($configDB->fetchGroupIDsOfClient(4)), + 1, "client 4 should have one group-ID" +); +is($groupIDs[0], 3, "first group of client 4 should have ID 3"); + +ok( + $configDB->removeClientIDsFromGroup(3, [6]), + 'removing an unassociated client-ID should have no effect' +); +is( + @groupIDs = sort($configDB->fetchClientIDsOfGroup(3)), + 1, "group 3 should have one client-ID" +); +ok( + $configDB->removeClient(4), + 'removing a client should drop group associations, too' +); +is( + @groupIDs = sort($configDB->fetchClientIDsOfGroup(3)), + 0, "group 3 should have no more client-ID" +); + +$configDB->disconnect(); diff --git a/config-db/t/25-attributes.t b/config-db/t/25-attributes.t new file mode 100644 index 00000000..35c9d537 --- /dev/null +++ b/config-db/t/25-attributes.t @@ -0,0 +1,172 @@ +use Test::More qw(no_plan); + +use lib '/opt/openslx/lib'; + +# basic init +use OpenSLX::ConfigDB; + +my $configDB = OpenSLX::ConfigDB->new; +$configDB->connect(); + +my $defaultAttrs = { # mostly copied from DBSchema + 'attr_ramfs_fsmods' => '', + 'attr_ramfs_miscmods' => '', + 'attr_ramfs_nicmods' => 'forcedeth e1000 e100 tg3 via-rhine r8169 pcnet32', + 'attr_ramfs_screen' => '', + + 'attr_automnt_dir' => '', + 'attr_automnt_src' => '', + 'attr_country' => 'de', + 'attr_dm_allow_shutdown' => 'user', + 'attr_hw_graphic' => '', + 'attr_hw_monitor' => '', + 'attr_hw_mouse' => '', + 'attr_late_dm' => 'no', + 'attr_netbios_workgroup' => 'slx-network', + 'attr_nis_domain' => '', + 'attr_nis_servers' => '', + 'attr_sane_scanner' => '', + 'attr_scratch' => '', + 'attr_slxgrp' => '', + 'attr_start_alsasound' => 'yes', + 'attr_start_atd' => 'no', + 'attr_start_cron' => 'no', + 'attr_start_dreshal' => 'yes', + 'attr_start_ntp' => 'initial', + 'attr_start_nfsv4' => 'no', + 'attr_start_printer' => 'no', + 'attr_start_samba' => 'may', + 'attr_start_snmp' => 'no', + 'attr_start_sshd' => 'yes', + 'attr_start_syslog' => 'yes', + 'attr_start_x' => 'yes', + 'attr_start_xdmcp' => 'kdm', + 'attr_tex_enable' => 'no', + 'attr_timezone' => 'Europe/Berlin', + 'attr_tvout' => 'no', + 'attr_vmware' => 'no', +}; +ok( + $configDB->changeSystem(0, $defaultAttrs), + 'attributes of default system have been set' +); +my $defaultSystem = $configDB->fetchSystemByID(0); + +my $system1 = $configDB->fetchSystemByID(1); +my $sys1Attrs = { + 'attr_ramfs_fsmods' => 'squashfs', + 'attr_ramfs_nicmods' => 'forcedeth e1000 r8169', + 'attr_start_x' => 'no', + 'attr_start_xdmcp' => '', +}; +ok( + $configDB->changeSystem(1, $sys1Attrs), + 'attributes of system 1 have been set' +); +my $changedSystem1 = $configDB->fetchSystemByID(1); +foreach my $key (keys %$changedSystem1) { + is( + $changedSystem1->{$key}, + exists $sys1Attrs->{$key} ? $sys1Attrs->{$key} : $system1->{$key}, + "checking value for $key of system 1" + ); +} + +my $system3 = $configDB->fetchSystemByID(3); +my $sys3Attrs = { + 'attr_automnt_dir' => '1', + 'attr_automnt_src' => '2', + 'attr_country' => '3', + 'attr_dm_allow_shutdown' => '4', + 'attr_hw_graphic' => '5', + 'attr_hw_monitor' => '6', + 'attr_hw_mouse' => '7', + 'attr_late_dm' => '8', + 'attr_netbios_workgroup' => '9', + 'attr_nis_domain' => '10', + 'attr_nis_servers' => '11', + 'attr_sane_scanner' => '12', + 'attr_scratch' => '13', + 'attr_slxgrp' => '14', + 'attr_start_alsasound' => '15', + 'attr_start_atd' => '16', + 'attr_start_cron' => '17', + 'attr_start_dreshal' => '18', + 'attr_start_ntp' => '19', + 'attr_start_nfsv4' => '20', + 'attr_start_printer' => '21', + 'attr_start_samba' => '22', + 'attr_start_snmp' => '23', + 'attr_start_sshd' => '24', + 'attr_start_syslog' => '25', + 'attr_start_x' => '26', + 'attr_start_xdmcp' => '27', + 'attr_tex_enable' => '28', + 'attr_timezone' => '29', + 'attr_tvout' => '30', + 'attr_vmware' => '31', +}; +ok( + $configDB->changeSystem(3, $sys3Attrs), + 'attributes of system 3 have been set' +); +my $changedSystem3 = $configDB->fetchSystemByID(3); +foreach my $key (keys %$changedSystem3) { + is( + $changedSystem3->{$key}, + exists $sys3Attrs->{$key} ? $sys3Attrs->{$key} : $system3->{$key}, + "checking value for $key of system 3" + ); +} + +my $defaultClient = $configDB->fetchClientByID(0); +my $defaultClientAttrs = { + # pretend the whole computer centre has been warped to London ;-) + 'attr_timezone' => 'Europe/London', +}; +ok( + $configDB->changeClient(0, $defaultClientAttrs), + 'attributes of default client have been set' +); +my $changedDefaultClient = $configDB->fetchClientByID(0); +foreach my $key (keys %$changedDefaultClient) { + is( + $changedDefaultClient->{$key}, + exists $defaultClientAttrs->{$key} + ? $defaultClientAttrs->{$key} + : $defaultClient->{$key}, + "checking value for $key of default client" + ); +} + +# check merging of default attributes, the order should be: +# default system attributes overruled by system attributes overruled by +# default client attributes +$system1 = $changedSystem1; +$system3 = $changedSystem3; +$defaultClient = $changedDefaultClient; +my $shouldBeAttrs1 = { %$defaultSystem }; +foreach my $key (keys %$system1) { + next if !$configDB->isAttribute($key); + if (defined $system1->{$key} && length($system1->{$key})) { + $shouldBeAttrs1->{$key} = $system1->{$key}; + } +} +foreach my $key (keys %$defaultClient) { + next if !$configDB->isAttribute($key); + if (defined $defaultClient->{$key} && length($defaultClient->{$key})) { + $shouldBeAttrs1->{$key} = $defaultClient->{$key}; + } +} + +my $mergedSystem1 = $configDB->fetchSystemByID(1); +ok( + $configDB->mergeAttributes($mergedSystem1), + 'merging default attributes for system 1' +); +is_deeply( + $mergedSystem1, $shouldBeAttrs1, + 'checking merged attributes for system 1' +); + +$configDB->disconnect(); diff --git a/config-db/t/29-transaction.t b/config-db/t/29-transaction.t new file mode 100644 index 00000000..89b0df83 --- /dev/null +++ b/config-db/t/29-transaction.t @@ -0,0 +1,55 @@ +use Test::More qw(no_plan); + +use lib '/opt/openslx/lib'; + +# basic init +use OpenSLX::ConfigDB; + +my $configDB = OpenSLX::ConfigDB->new; +$configDB->connect(); + +my @vendorOSes = $configDB->fetchVendorOSByFilter(); +my @exports = $configDB->fetchExportByFilter(); +my @systems = $configDB->fetchSystemByFilter(); +my @clients = $configDB->fetchClientByFilter(); +my @groups = $configDB->fetchGroupByFilter(); + +ok($configDB->startTransaction(), 'starting a transaction'); + +ok($configDB->emptyDatabase(), 'emptying the DB'); + +ok($configDB->rollbackTransaction(), 'rolling back the transaction'); + +my @vendorOSes2 = $configDB->fetchVendorOSByFilter(); +my @exports2 = $configDB->fetchExportByFilter(); +my @systems2 = $configDB->fetchSystemByFilter(); +my @clients2 = $configDB->fetchClientByFilter(); +my @groups2 = $configDB->fetchGroupByFilter(); + +is( + scalar @vendorOSes2, scalar @vendorOSes, "should still have all vendor-OSes" +); +is(scalar @exports2, scalar @exports, "should still have all exports"); +is(scalar @systems2, scalar @systems, "should still have all systems"); +is(scalar @clients2, scalar @clients, "should still have all clients"); +is(scalar @groups2, scalar @groups, "should still have all groups"); + +ok($configDB->startTransaction(), 'starting a transaction'); + +ok($configDB->emptyDatabase(), 'emptying the DB'); + +ok($configDB->commitTransaction(), 'committing the transaction'); + +my @vendorOSes3 = $configDB->fetchVendorOSByFilter(); +my @exports3 = $configDB->fetchExportByFilter(); +my @systems3 = $configDB->fetchSystemByFilter(); +my @clients3 = $configDB->fetchClientByFilter(); +my @groups3 = $configDB->fetchGroupByFilter(); + +is(scalar @vendorOSes3, 0, "should have no vendor-OSes"); +is(scalar @exports3, 0, "should have no exports"); +is(scalar @systems3, 1, "should have one system (default)"); +is(scalar @clients3, 1, "should have one client (default)"); +is(scalar @groups3, 0, "should have no groups"); + +$configDB->disconnect(); -- cgit v1.2.3-55-g7522