File: 01.2-backup_globals.t

package info (click to toggle)
libpgobject-util-dbadmin-perl 1.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 176 kB
  • sloc: perl: 435; makefile: 6; sql: 3
file content (77 lines) | stat: -rw-r--r-- 3,363 bytes parent folder | download | duplicates (4)
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
use warnings;
use strict;

use Test::More;
use Test::Exception;
use PGObject::Util::DBAdmin;
use File::Temp;

plan skip_all => 'DB_TESTING not set' unless $ENV{DB_TESTING};
plan tests => 21;

# Constructor

my $dbh;
my $db;
my $temp;
my $backup_file;

ok($db = PGObject::Util::DBAdmin->new(
     username => 'postgres',
     password => undef,
     dbname   => 'pgobject_test_db',
     host     => 'localhost',
     port     => '5432'
), 'Created db admin object');

# Drop db if exists
eval { $db->drop };


# Test backup_globals to auto-generated temp file
ok($backup_file = $db->backup_globals(
    tempdir => 't/var/',
), 'backup_globals outputs to auto-generated file');
ok(-f $backup_file, 'backup_globals output to auto-generated file exists');
ok($backup_file =~ m|^t/var/|, 'backup_globals output to auto-generated file respects tempdir parameter');
cmp_ok(-s $backup_file, '>', 0, 'backup_globals output to auto-generated file has size > 0');
is((stat($backup_file))[2] & 07777, 0600, 'backup_globals output to auto-generated file has permissions 0600');
unlink $backup_file;


# Test backup_globals to not-existing specified file
$temp = File::Temp->new->filename;
ok(!-f $temp, 'backup_globals non-existent specified file does not exist');
ok($backup_file = $db->backup_globals(
    file => $temp,
), 'backup_globals outputs to non-existent specified file');
ok(-f $backup_file, 'backup_globals output to non-existent specified file exists');
ok($temp =~ m/^$backup_file$/, 'backup_globals output to non-existent specified file respects file parameter');
cmp_ok(-s $backup_file, '>', 0, 'backup_globals output to non-existent specified file has size > 0');
is((stat($backup_file))[2] & 07777, 0600, 'backup_globals output to non-existent specified file has permissions 0600');
unlink $backup_file;

# Test backup_globals to overwrite existing specified file with 'wrong' permssions
# Makes sure that file is written and permissions are unchanged
$temp = File::Temp->new;
chmod 0777, $temp->filename; # Give it wrong permissions
is((stat($temp->filename))[2] & 07777, 0777, 'specified backup_globals output file created with permissions 0777');
ok($backup_file = $db->backup_globals(
    file => $temp->filename,
), 'backup_globals outputs to existing specified file with permissions 0777');
ok($temp->filename =~ m/^$backup_file$/, 'backup_globals output to existing specified file respects file parameter');
cmp_ok(-s $backup_file, '>', 0, 'backup_globals output to existing specified file with permissions 0777 has size > 0');
is((stat($backup_file))[2] & 07777, 0777, 'backup_globals output to existing specified file retains permissions 0777');
undef $temp;

# Test backup_globals to overwrite existing specified file with 'right' permssions
# Make sure file is written and 'correct' 0600 permissions are retained
$temp = File::Temp->new;
is((stat($temp->filename))[2] & 07777, 0600, 'specified backup_globals output file created with permissions 0600');
ok($backup_file = $db->backup_globals(
    file => $temp->filename,
), 'backup globals outut to existing specified file with permissions 0600');
cmp_ok(-s $backup_file, '>', 0, 'backup_globals to existing specified file with permissions 0600 has size > 0');
is((stat($backup_file))[2] & 07777, 0600, 'backup_globals output to existing specified file retains permissions 0600');
undef $temp;