File: uuid.t

package info (click to toggle)
libdbix-class-uuidcolumns-perl 0.02006-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 264 kB
  • sloc: perl: 2,251; sql: 3; makefile: 2
file content (115 lines) | stat: -rw-r--r-- 3,634 bytes parent folder | download | duplicates (3)
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
#!perl -wT
# $Id$
use strict;
use warnings;

BEGIN {
    use lib 't/lib';
    use DBIC::Test tests => 14;
};

my $schema = DBIC::Test->init_schema;
my $row;

$row = $schema->resultset('Test')->create({ });
ok DBIC::Test::is_uuid( $row->id ), 'got something that looks like a UUID from Auto';

DBIC::Test::Schema::Test->uuid_class('CustomUUIDMaker');
Class::C3->reinitialize();
$row = $schema->resultset('Test')->create({ });
ok DBIC::Test::is_uuid( $row->id ), 'got something that looks like a UUID from CustomUUIDMaker';

is(DBIx::Class::UUIDColumns::UUIDMaker->as_string, undef);

SKIP: {
    skip 'Data::UUID not installed', 2 unless eval 'require Data::UUID';

    DBIC::Test::Schema::Test->uuid_class('::Data::UUID');
    Class::C3->reinitialize();
    is(DBIC::Test::Schema::Test->uuid_class, 'DBIx::Class::UUIDColumns::UUIDMaker::Data::UUID');
    $row = $schema->resultset('Test')->create({ });
    ok DBIC::Test::is_uuid( $row->id ), 'got something that looks like a UUID from Data::UUID';
};

SKIP: {
    skip 'Data::GUID not installed', 1 unless eval 'require Data::GUID';

    DBIC::Test::Schema::Test->uuid_class('::Data::GUID');
    Class::C3->reinitialize();
    $row = $schema->resultset('Test')->create({ });
    ok DBIC::Test::is_uuid( $row->id ), 'got something that looks like a UUID from Data::GUID';
};

SKIP: {
    skip 'APR::UUID not installed', 1 unless eval 'require APR::UUID and $^O ne \'openbsd\'';

    DBIC::Test::Schema::Test->uuid_class('::APR::UUID');
    Class::C3->reinitialize();
    $row = $schema->resultset('Test')->create({ });
    ok DBIC::Test::is_uuid( $row->id ), 'got something that looks like a UUID from APR::UUID';
};

SKIP: {
    skip 'UUID not installed', 1 unless eval 'require UUID';

    DBIC::Test::Schema::Test->uuid_class('::UUID');
    Class::C3->reinitialize();
    $row = $schema->resultset('Test')->create({ });
    ok DBIC::Test::is_uuid( $row->id ), 'got something that looks like a UUID from UUID';
};

SKIP: {
    skip 'Win32::Guidgen not installed', 1 unless eval 'require Win32::Guidgen';

    DBIC::Test::Schema::Test->uuid_class('::Win32::Guidgen');
    Class::C3->reinitialize();
    $row = $schema->resultset('Test')->create({ });
    ok DBIC::Test::is_uuid( $row->id ), 'got something that looks like a UUID from Win32::Guidgen';
};

SKIP: {
    skip 'Win32API::GUID not installed', 1 unless eval 'require Win32API::GUID';

    DBIC::Test::Schema::Test->uuid_class('::Win32API::GUID');
    Class::C3->reinitialize();
    $row = $schema->resultset('Test')->create({ });
    ok DBIC::Test::is_uuid( $row->id ), 'got something that looks like a UUID from Win32API::GUID';
};

SKIP: {
    skip 'Data::Uniqid not installed', 1 unless eval 'require Data::Uniqid';

    DBIC::Test::Schema::Test->uuid_class('::Data::Uniqid');
    Class::C3->reinitialize();
    $row = $schema->resultset('Test')->create({ });
    ok $row->id, 'got something from Data::Uniqid';
};

SKIP: {
    skip 'UUID::Random not installed', 1 unless eval 'require UUID::Random';

    DBIC::Test::Schema::Test->uuid_class('::UUID::Random');
    Class::C3->reinitialize();
    $row = $schema->resultset('Test')->create({ });
    ok $row->id, 'got something from UUID::Random';
};

eval {
    DBIC::Test::Schema::Test->uuid_class('::JunkIDMaker');
};
if ($@ && $@ =~ /could not be loaded/i) {
    pass;
} else {
    fail('uuid_class dies when class can not be loaded');
};

eval {
    DBIC::Test::Schema::Test->uuid_class('BadUUIDMaker');
};
if ($@ && $@ =~ /is not a UUIDMaker subclass/i) {
    pass;
} else {
    fail('uuid_class dies when class no isa DBIx::Class::UUIDColumns::UUIDMaker');
};

1;