~ubuntu-branches/ubuntu/vivid/zentyal-core/vivid-proposed

« back to all changes in this revision

Viewing changes to src/EBox/t/Module.t

  • Committer: Package Import Robot
  • Author(s): Jorge Salamero Sanz
  • Date: 2012-08-28 10:03:33 UTC
  • Revision ID: package-import@ubuntu.com-20120828100333-oz3n5kpav4z0tl27
Tags: 2.3.21+quantal1
New upstream release for Quantal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
use strict;
2
 
use warnings;
3
 
 
4
 
use Test::More qw(no_plan);
5
 
use Test::Exception;
6
 
 
7
 
use lib '../..';
8
 
use EBox::Module;
9
 
use EBox::TestStubs qw(fakeEBoxModule);
10
 
 
11
 
 
12
 
EBox::TestStubs::activateTestStubs();
13
 
fakeEBoxModule(name => 'testMod');
14
 
backupDirTest();
15
 
createBackupDirTest();
16
 
setAsChangedTest();
17
 
noTemplateFileTest();
18
 
 
19
 
sub backupDirTest
20
 
{
21
 
  my $mod = EBox::Global->modInstance('testMod');
22
 
 
23
 
  my @cases = (
24
 
               ['/' => '/testMod.bak'],
25
 
               ['/var/lib/zentyal/backups' => '/var/lib/zentyal/backups/testMod.bak'],
26
 
               ['/var/lib/zentyal/backups/' => '/var/lib/zentyal/backups/testMod.bak'],
27
 
               # with repetition:
28
 
               ['/var/lib/zentyal/backups/testMod.bak' => '/var/lib/zentyal/backups/testMod.bak'],
29
 
               ['/var/lib/zentyal/backups/testMod.bak/' => '/var/lib/zentyal/backups/testMod.bak'],
30
 
               ['/var/lib/zentyal/backups/testMod.bak/testMod.bak' => '/var/lib/zentyal/backups/testMod.bak'],
31
 
              );
32
 
 
33
 
  foreach my $case_r (@cases) {
34
 
    my ($dir, $expectedBackupDir) = @{ $case_r };
35
 
 
36
 
    is $mod->backupDir($dir), $expectedBackupDir, "Checking backupDir($dir) eq $expectedBackupDir";
37
 
  }
38
 
}
39
 
 
40
 
sub createBackupDirTest
41
 
{
42
 
  my $dir = '/tmp/ebox.module.backupdir.test';
43
 
  system "rm -rf $dir";
44
 
  mkdir $dir;
45
 
 
46
 
  my $mod = EBox::Global->modInstance('testMod');
47
 
 
48
 
  my @cases = (
49
 
               ["$dir" => "$dir/testMod.bak"],
50
 
               ["$dir" => "$dir/testMod.bak"], # check that can be called two times in a row
51
 
               ["$dir/testMod.bak" => "$dir/testMod.bak"], 
52
 
               ["$dir/testMod.bak/" => "$dir/testMod.bak"], 
53
 
               ["$dir/testMod.bak/testMod.bak" => "$dir/testMod.bak"], 
54
 
              );
55
 
 
56
 
  foreach my $case_r (@cases) {
57
 
    my ($dir, $expectedBackupDir) = @{ $case_r };
58
 
 
59
 
    lives_and( sub { is $mod->_createBackupDir($dir), $expectedBackupDir } , "Testing _createBackupDir($dir)" );
60
 
    my $dirExists =  (-d $expectedBackupDir);
61
 
    ok $dirExists, "Checking that the backup directory  $dir is in place";
62
 
  }
63
 
 
64
 
}
65
 
 
66
 
sub setAsChangedTest
67
 
{
68
 
  EBox::TestStubs::setEBoxModule('global' => 'EBox::Global');
69
 
 
70
 
  my $global = EBox::Global->getInstance();
71
 
  (! $global->modIsChanged('testMod')) or die "Module must not be changed";
72
 
 
73
 
  lives_and (
74
 
 
75
 
             sub {  
76
 
               my $mod = $global->modInstance('testMod');
77
 
               $mod->setAsChanged();
78
 
 
79
 
               ok $global->modIsChanged('testMod');
80
 
             },
81
 
             'Module was marked as changed'
82
 
            );
83
 
}
84
 
 
85
 
 
86
 
 
87
 
sub noTemplateFileTest
88
 
{
89
 
    EBox::TestStubs::setEBoxConfigKeys(tmp => '/tmp', stubs => '/tmp');
90
 
 
91
 
    my $mod = EBox::Global->modInstance('testMod');
92
 
    dies_ok {
93
 
        $mod->writeConfFile(
94
 
                            '/tmp/whatever',
95
 
                            'inexistentTemplate.mas',
96
 
                            []
97
 
 
98
 
                           );
99
 
    } 'Checking that writeConfFile dies when supplied with a inexistent template file';
100
 
 
101
 
}
102
 
 
103
 
1;