summaryrefslogtreecommitdiffstats
path: root/t/01distribconf.t
blob: b411bea14632450649ea3ddc65f3263b68b5ceb5 (plain)
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
#!/usr/bin/perl

# $Id$

use strict;
use Test::More;

my %testdpath = (
    'testdata/test' => undef,
    'testdata/test2' => undef,
    'testdata/test3' => undef,
    'http://server/path/' => 'testdata/test/media/media_info/media.cfg',
);

plan tests => 14 + 22 * scalar(keys %testdpath);

use_ok('MDV::Distribconf');

{
ok(my $dconf = MDV::Distribconf->new('/dev/null'), "Can get new MDV::Distribconf");
ok(!$dconf->load(), "loading wrong distrib give error");
}

foreach my $path (keys %testdpath) {
    ok(my $dconf = MDV::Distribconf->new($path), "Can get new MDV::Distribconf");
    if ($testdpath{$path}) {
        $dconf->settree('mandriva');
    } else {
        ok($dconf->load(), "Can load conf");
    }

    is($dconf->getpath(undef, 'root'), $path, "Can get root path");
    like($dconf->getpath(undef, 'media_info'), qr!^/*media/media_info/?$!, "Can get media_info path"); # vim color: */ 
    like($dconf->getpath(undef, 'infodir'), qr!^/*media/media_info/?$!, "Can get infodir"); # vim color: */ 
    like($dconf->getpath(undef, 'mediadir'), qr!^/*media/?$!, "Can get infodir"); # vim color: */ 

    if ($testdpath{$path}) {
        ok($dconf->parse_mediacfg($testdpath{$path}), "can parse media.cfg");
    }

    ok(scalar($dconf->listmedia) == 8, "Can list all media");
    ok((grep { $_ eq 'main' } $dconf->listmedia), "list properly media");

    is($dconf->getvalue(undef, 'version'), '2006.0', "Can get global value");
    is($dconf->getvalue('main', 'version'), '2006.0', "Can get global value via media");
    is($dconf->getvalue('main', 'name'), 'main', "Can get default name");
    is($dconf->getvalue('contrib', 'name'), 'Contrib', "Can get media name");
    is($dconf->getvalue('contrib', 'platform'), 'i586-mandriva-linux-gnu', "Can get media platform");

    is($dconf->getpath(undef, 'root'), $path, "Can get root path");
    like($dconf->getpath(undef, 'media_info'), qr!^/*media/media_info/?$!, "Can get media_info path"); # vim color: */ 
    like($dconf->getfullpath(undef, 'media_info'), qr!^/*$path/+media/media_info/?$!, "Can get media_info fullpath"); # vim color: */
    like($dconf->getpath('main', 'path'), qr!^/*media/+main/?$!, "Can get media path"); # vim color: */
    like($dconf->getfullpath('main', 'path'), qr!^/*$path/*media/+main/?$!, "Can get media fullpath"); # vim color: */
    like($dconf->getpath('main', 'hdlist'), qr!^/*media/+media_info/+hdlist_main.cz$!, "Can get media path"); # vim color: */
    like($dconf->getfullpath('main', 'hdlist'), qr!^/*$path/*media/+media_info/+hdlist_main.cz$!, "Can get media fullpath"); # vim color: */
    like($dconf->getmediapath('main', 'hdlist'), qr!^/*media/+main/+media_info/+hdlist.cz$!, "Can get media path"); # vim color: */
    like($dconf->getfullmediapath('main', 'hdlist'), qr!^/*$path/*media/+main/+media_info/+hdlist.cz$!, "Can get media fullpath"); # vim color: */
}

{
ok(my $dconf = MDV::Distribconf->new('not_exists', 1), "Can get new MDV::Distribconf");
$dconf->settree();
like($dconf->getpath(undef, 'media_info'), qr!^/*media/media_info/?$!, "Can get media_info path"); # vim color: */
}
{
ok(my $dconf = MDV::Distribconf->new('not_exists', 1), "Can get new MDV::Distribconf");
$dconf->settree('manDraKE');
like($dconf->getpath(undef, 'media_info'), qr!^/*Mandrake/base/?$!, "Can get media_info path"); # vim color: */
}
{
ok(my $dconf = MDV::Distribconf->new('not_exists', 1), "Can get new MDV::Distribconf");
$dconf->settree({ 
  mediadir => 'mediadir',
  infodir => 'infodir',
});
like($dconf->getpath(undef, 'media_info'), qr!^/*infodir/?$!, "Can get media_info path"); # vim color: */
}

{
    # test for %{} ${} var
    my $dc = MDV::Distribconf->new('testdata/test3');
    $dc->load();
    is(
        $dc->_expand(undef, '${version}'),
        '2006.0',
        'expand works'
    );
    is(
        $dc->_expand('jpackage', '%{name}'),
        'jpackage',
        'expand works'
    );
    is(
        $dc->_expand('jpackage', '${version}'),
        '2006.0',
        'expand works'
    );
    is(
        $dc->_expand(undef, '%{foo}'),
        '%{foo}',
        'expand works'
    );
    is(
        $dc->getvalue('jpackage', 'hdlist'),
        'hdlist_jpackage.cz',
        'getvalue works'
    );
}