From bf6beb5f4374938b20af65af76003376d9ea0ffd Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Fri, 9 Nov 2007 15:54:04 +0000 Subject: * started to work on configDB-tests git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1407 95ad53e4-c205-0410-b2fa-d234c58c8868 --- config-db/t/01-basics.t | 20 +++++ config-db/t/10-vendor-os.t | 179 +++++++++++++++++++++++++++++++++++++++++++ config-db/t/run-all-tests.pl | 32 ++++++++ 3 files changed, 231 insertions(+) create mode 100644 config-db/t/01-basics.t create mode 100644 config-db/t/10-vendor-os.t create mode 100755 config-db/t/run-all-tests.pl (limited to 'config-db/t') diff --git a/config-db/t/01-basics.t b/config-db/t/01-basics.t new file mode 100644 index 00000000..fdc7a052 --- /dev/null +++ b/config-db/t/01-basics.t @@ -0,0 +1,20 @@ +use Test::More qw(no_plan); + +use lib '/opt/openslx/lib'; + +# basic stuff +use_ok(OpenSLX::ConfigDB); + +# connecting and disconnecting +ok(my $configDB = OpenSLX::ConfigDB->new, 'can create object'); +isa_ok($configDB, 'OpenSLX::ConfigDB'); + +{ + # create a second object - should work and yield different objects + ok(my $configDB2 = OpenSLX::ConfigDB->new, 'can create another object'); + cmp_ok($configDB, 'ne', $configDB2, 'should have two different objects now'); +} + +ok($configDB->connect(), 'connecting'); +ok($configDB->disconnect(), 'disconnecting'); + 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(); + diff --git a/config-db/t/run-all-tests.pl b/config-db/t/run-all-tests.pl new file mode 100755 index 00000000..6cebdac1 --- /dev/null +++ b/config-db/t/run-all-tests.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +use Test::Harness; + +# add the development paths to perl's search path for modules: +use FindBin; +use lib "$FindBin::RealBin/../"; +use lib "$FindBin::RealBin/../../lib"; + +use OpenSLX::Basics; + +use OpenSLX::MetaDB::SQLite; + +# make sure a specific test-db will be used +$cmdlineConfig{'private-path'} = $ENV{SLX_PRIVATE_PATH} = '/tmp/slx-db-test'; +$cmdlineConfig{'db-name'} = $ENV{SLX_DB_NAME} = 'slx-test'; +$cmdlineConfig{'db-type'} = $ENV{SLX_DB_TYPE} = 'SQLite'; + +openslxInit(); + +# remove the test-db if it already exists +my $metaDB = OpenSLX::MetaDB::SQLite->new(); +if ($metaDB->databaseExists()) { + print "removing leftovers of slx-test-db\n"; + $metaDB->dropDatabase(); +} +runtests(glob("*.t")); + +$metaDB->dropDatabase(); -- cgit v1.2.3-55-g7522