File: 04_bzip2.t

package info (click to toggle)
liborlite-mirror-perl 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312 kB
  • sloc: perl: 2,347; sql: 8; makefile: 2
file content (93 lines) | stat: -rw-r--r-- 2,550 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl

# Tests the basic functionality of SQLite.

use strict;

BEGIN {
	$|  = 1;
	$^W = 1;
}

use Test::More tests => 26;
use File::Spec::Functions ':ALL';
use File::Remove 'clear';
use IO::Compress::Bzip2 ();
use URI::file           ();
use t::lib::Test;

# Flush any existing mirror database file
clear(mirror_db('ORLite::Mirror::Test'));

# Set up the file
my $file = test_db();
my $dbh  = create_ok(
	catfile(qw{ t 02_basics.sql }),
	"dbi:SQLite:$file",
);
my $archive = $file . '.bz2';
clear($archive);
IO::Compress::Bzip2::bzip2( $file => $archive )
	or die('Failed to compress test script');

# Convert the file into a URI
my $uri = URI::file->new_abs($archive)->as_string;

# Create the test package
eval <<"END_PERL"; die $@ if $@;
package ORLite::Mirror::Test;

use strict;
use vars qw{\$VERSION};
BEGIN {
	\$VERSION = '1.00';
}

use ORLite::Mirror {
	url   => '$uri',
	prune => 1,
	array => 0,
};

1;

END_PERL

ok( ORLite::Mirror::Test->can('dbh'), 'Created database methods' );
ok( ! ORLite::Mirror::Test->can('commit'), 'Did not create transaction methods' );

# Check the ->count method
is( ORLite::Mirror::Test::TableOne->count, 3, 'Found 3 rows' );
is( ORLite::Mirror::Test::TableOne->count('where col2 = ?', 'bar'), 2, 'Condition count works' );

# Fetch the rows (list context)
SCOPE: {
	my @ones = ORLite::Mirror::Test::TableOne->select('order by col1');
	is( scalar(@ones), 3, 'Got 3 objects' );
	isa_ok( $ones[0], 'ORLite::Mirror::Test::TableOne' );
	isa_ok( $ones[1], 'ORLite::Mirror::Test::TableOne' );
	isa_ok( $ones[2], 'ORLite::Mirror::Test::TableOne' );
	is( $ones[0]->col1, 1,     '->col1 ok' );
	is( $ones[1]->col1, 2,     '->col1 ok' );
	is( $ones[2]->col1, 3,     '->col1 ok' );
	is( $ones[0]->col2, 'foo', '->col2 ok' );
	is( $ones[1]->col2, 'bar', '->col2 ok' );
	is( $ones[2]->col2, 'bar', '->col2 ok' );
}

# Fetch the rows (scalar context)
SCOPE: {
	my $ones = ORLite::Mirror::Test::TableOne->select('order by col1');
	is( scalar(@$ones), 3, 'Got 3 objects' );
	isa_ok( $ones->[0], 'ORLite::Mirror::Test::TableOne' );
	isa_ok( $ones->[1], 'ORLite::Mirror::Test::TableOne' );
	isa_ok( $ones->[2], 'ORLite::Mirror::Test::TableOne' );
	is( $ones->[0]->col1, 1,     '->col1 ok' );
	is( $ones->[1]->col1, 2,     '->col1 ok' );
	is( $ones->[2]->col1, 3,     '->col1 ok' );
	is( $ones->[0]->col2, 'foo', '->col2 ok' );
	is( $ones->[1]->col2, 'bar', '->col2 ok' );
	is( $ones->[2]->col2, 'bar', '->col2 ok' );

	ok( ! ORLite::Mirror::Test::TableOne->can('delete'), 'Did not add data manipulation methods' );
}