diff options
Diffstat (limited to 'config-db/t/10-vendor-os.t')
-rw-r--r-- | config-db/t/10-vendor-os.t | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/config-db/t/10-vendor-os.t b/config-db/t/10-vendor-os.t new file mode 100644 index 00000000..9f7c9f11 --- /dev/null +++ b/config-db/t/10-vendor-os.t @@ -0,0 +1,179 @@ +use Test::More qw(no_plan); + +use lib '/opt/openslx/lib'; + +# basic init +use OpenSLX::ConfigDB; + +my $configDB = OpenSLX::ConfigDB->new; +$configDB->connect(); + +is( + my $vendorOS = $configDB->fetchVendorOSByFilter, undef, + 'no vendor-OS yet (scalar context)' +); +is( + my @vendorOSes = $configDB->fetchVendorOSByFilter, 0, + 'no vendor-OS yet (array context)' +); + +my $inVendorOS1 = { + 'name' => 'vos-1', + 'comment' => '', +}; +is( + my $vendorOS1ID = $configDB->addVendorOS($inVendorOS1), 1, + 'first vendor-OS has ID 1' +); + +my $inVendorOS2 = { + 'name' => 'vos-2.0', + 'comment' => 'batch 2', +}; +my $inVendorOS3 = { + 'name' => 'vos-3.0', + 'comment' => 'batch 2', + 'clone_source' => 'kiwi::test-vos', +}; +ok( + my ($vendorOS2ID, $vendorOS3ID) = $configDB->addVendorOS([ + $inVendorOS2, $inVendorOS3 + ]), + 'add two more vendor-OSes' +); +is($vendorOS2ID, 2, 'vendor-OS 2 should have ID=2'); +is($vendorOS3ID, 3, 'vendor-OS 3 should have ID=3'); + +# fetch vendor-OS 3 by id and check all values +ok(my $vendorOS3 = $configDB->fetchVendorOSByID(3), 'fetch vendor-OS 3'); +is($vendorOS3->{id}, 3, 'vendor-OS 3 - id'); +is($vendorOS3->{name}, 'vos-3.0', 'vendor-OS 3 - name'); +is($vendorOS3->{comment}, 'batch 2', 'vendor-OS 3 - comment'); +is($vendorOS3->{clone_source}, 'kiwi::test-vos', 'vendor-OS 3 - clone_source'); + +# fetch vendor-OS 2 by a filter on id and check all values +ok( + my $vendorOS2 = $configDB->fetchVendorOSByFilter({ id => 2 }), + 'fetch vendor-OS 2 by filter on id' +); +is($vendorOS2->{id}, 2, 'vendor-OS 2 - id'); +is($vendorOS2->{name}, 'vos-2.0', 'vendor-OS 2 - name'); +is($vendorOS2->{comment}, 'batch 2', 'vendor-OS 2 - comment'); +is($vendorOS2->{clone_source}, undef, 'vendor-OS 2 - clone_source'); + +# fetch vendor-OS 1 by filter on name and check all values +ok( + my $vendorOS1 = $configDB->fetchVendorOSByFilter({ name => 'vos-1' }), + 'fetch vendor-OS 1 by filter on name' +); +is($vendorOS1->{id}, 1, 'vendor-OS 1 - id'); +is($vendorOS1->{name}, 'vos-1', 'vendor-OS 1 - name'); +is($vendorOS1->{comment}, '', 'vendor-OS 1 - comment'); +is($vendorOS1->{clone_source}, undef, 'vendor-OS 1 - clone_source'); + +# fetch vendor-OSes 3 & 1 by id +ok( + my @vendorOSes3And1 + = $configDB->fetchVendorOSByID([3, 1]), + 'fetch vendor-OSes 3 & 1 by id' +); +is(@vendorOSes3And1, 2, 'should have got 2 vendor-OSes'); +# now sort by ID and check if we have really got 3 and 1 +@vendorOSes3And1 = sort { $a->{id} cmp $b->{id} } @vendorOSes3And1; +is($vendorOSes3And1[0]->{id}, 1, 'first id should be 1'); +is($vendorOSes3And1[1]->{id}, 3, 'second id should be 3'); + +# fetching vendor-OSes by id without giving any should yield undef +is( + $configDB->fetchVendorOSByID(), undef, + 'fetch vendor-OSes by id without giving any' +); + +# fetching vendor-OSes by filter without giving any should yield all of them +ok( + @vendorOSes = $configDB->fetchVendorOSByFilter(), + 'fetch vendor-OSes by filter without giving any' +); +is(@vendorOSes, 3, 'should have got all three vendor-OSes'); + +# fetch vendor-OSes 2 & 3 by filter on comment +ok( + my @vendorOSes2And3 + = $configDB->fetchVendorOSByFilter({ comment => 'batch 2' }), + 'fetch vendor-OSes 2 & 3 by filter on comment' +); +is(@vendorOSes2And3, 2, 'should have got 2 vendor-OSes'); +# now sort by ID and check if we have really got 2 and 3 +@vendorOSes2And3 = sort { $a->{id} cmp $b->{id} } @vendorOSes2And3; +is($vendorOSes2And3[0]->{id}, 2, 'first id should be 2'); +is($vendorOSes2And3[1]->{id}, 3, 'second id should be 3'); + +# try to fetch with multi-column filter +ok( + ($vendorOS2, $vendorOS3) + = $configDB->fetchVendorOSByFilter({ comment => 'batch 2', id => 2 }), + 'fetching vendor-OS with comment="batch 2" and id=2 should work' +); +is($vendorOS2->{name}, 'vos-2.0', 'should have got vos-2.0'); +is($vendorOS3, undef, 'should not get vos-3.0'); + +# try to fetch multiple occurrences of the same vendor-OS, combined with +# some unknown IDs +ok( + my @vendorOSes1And3 + = $configDB->fetchVendorOSByID([ 1, 21, 4-1, 1, 0, 1, 1 ]), + 'fetch a complex set of vendor-OSes by ID' +); +is(@vendorOSes1And3, 2, 'should have got 2 vendor-OSes'); +# now sort by ID and check if we have really got 1 and 3 +@vendorOSes1And3 = sort { $a->{id} cmp $b->{id} } @vendorOSes1And3; +is($vendorOSes1And3[0]->{id}, 1, 'first id should be 1'); +is($vendorOSes1And3[1]->{id}, 3, 'second id should be 3'); + +# try to fetch a couple of non-existing vendor-OSes by id +is( + $configDB->fetchVendorOSByID(-1), undef, + 'vendor-OS with id -1 should not exist' +); +is( + $configDB->fetchVendorOSByID(0), undef, + 'vendor-OS with id 0 should not exist' +); +is( + $configDB->fetchVendorOSByID(1 << 31 + 1000), undef, + 'trying to fetch another unknown vendor-OS' +); + +# try to fetch a couple of non-existing vendor-OSes by filter +is( + $configDB->fetchVendorOSByFilter({ id => 0 }), undef, + 'fetching vendor-OS with id=0 by filter should fail' +); +is( + $configDB->fetchVendorOSByFilter({ name => 'vos-1.x' }), undef, + 'fetching vendor-OS with name="vos-1.x" should fail' +); +is( + $configDB->fetchVendorOSByFilter({ comment => 'batch 2', id => 1 }), undef, + 'fetching vendor-OS with comment="batch 2" and id=1 should fail' +); + +# rename vendor-OS 1 and then fetch it by its new name +ok($configDB->changeVendorOS(1, { name => q{VOS-'1'} }), 'changing vendor-OS 1'); +ok( + $vendorOS1 = $configDB->fetchVendorOSByFilter({ name => q{VOS-'1'} }), + 'fetching renamed vendor-OS 1' +); +is($vendorOS1->{id}, 1, 'really got vendor-OS number 1'); +is($vendorOS1->{name}, q{VOS-'1'}, q{really got vendor-OS named "VOS-'1'"}); + +# changing a non-existing column should fail +ok( + ! eval { $configDB->changeVendorOS(1, { xname => "xx" }) }, + 'changing unknown colum should fail' +); + +ok($configDB->changeVendorOS(1, { id => 23 }), 'changing id should fail'); + +$configDB->disconnect(); + |