summaryrefslogtreecommitdiffstats
path: root/src/config-db/t/10-vendor-os.t
blob: a71ee4acf4b1ece17d5c82293c76b32dfc6bf518 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
use Test::More qw(no_plan);

use strict;
use warnings;

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)'
);

my $wrongVendorOS = {
    'comment' => 'test',
};
ok(
    ! eval { my $vendorOSID = $configDB->addVendorOS($wrongVendorOS); },
    'trying to insert an unnamed vendor-OS should fail'
);

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 nothing at all should succeed
ok($configDB->changeVendorOS(1), 'changing nothing at all in vendor-OS 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');

# test adding & removing of installed plugins
is(
    my @plugins = $configDB->fetchInstalledPlugins(3), 
    0, 'there should be no installed plugins'
);
ok($configDB->addInstalledPlugin(3, 'Example'), 'adding installed plugin');
is(
    @plugins = $configDB->fetchInstalledPlugins(3), 
    1,
    'should have 1 installed plugin'
);
is(
    $configDB->addInstalledPlugin(3, 'Example'), 1, 
    'adding plugin again should work (but do not harm, just update the attrs)'
);
is(
    @plugins = $configDB->fetchInstalledPlugins(3), 
    1,
    'should still have 1 installed plugin'
);
is($plugins[0]->{plugin_name}, 'Example', 'should have got plugin "Example"');
ok($configDB->addInstalledPlugin(3, 'Test'), 'adding a second plugin');
is(
    @plugins = $configDB->fetchInstalledPlugins(3), 
    2,
    'should have 2 installed plugin'
);
ok(
    !$configDB->removeInstalledPlugin(3, 'xxx'), 
    'removing unknown plugin should fail'
);
ok(
    @plugins = $configDB->fetchInstalledPlugins(3, 'Example'), 
    'fetching specific plugin'
);
is($plugins[0]->{plugin_name}, 'Example', 'should have got plugin "Example"');
ok(
    @plugins = $configDB->fetchInstalledPlugins(3, 'Test'), 
    'fetching another specific plugin'
);
is($plugins[0]->{plugin_name}, 'Test', 'should have got plugin "Test"');
is(
    @plugins = $configDB->fetchInstalledPlugins(3, 'xxx'), 0,
    'fetching unknown specific plugin'
);
ok($configDB->removeInstalledPlugin(3, 'Example'), 'removing installed plugin');
is(
    @plugins = $configDB->fetchInstalledPlugins(3), 
    1,
    'should have 1 installed plugin'
);
ok($configDB->removeInstalledPlugin(3, 'Test'), 'removing second plugin');
is(
    @plugins = $configDB->fetchInstalledPlugins(3), 
    0,
    'should have no installed plugins'
);

# now remove a vendor-OS and check if that worked
ok($configDB->removeVendorOS(3), 'removing vendor-OS 3 should be ok');
is($configDB->fetchVendorOSByID(3, 'id'), undef, 'vendor-OS 3 should be gone');
is($configDB->fetchVendorOSByID(1)->{id}, 1, 'vendor-OS 1 should still exist');
is($configDB->fetchVendorOSByID(2)->{id}, 2, 'vendor-OS 2 should still exist');

$configDB->disconnect();