Punk-Observe
view release on metacpan or search on metacpan
t/0910-backend.t view on Meta::CPAN
my $sql = do { open my $fh, '<', $f or die "$f: $!"; local $/; <$fh> };
while ($sql =~ /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?(\w+)\s*\((.*?)\n\s*\);/gis) {
my ($t, $body) = (lc $1, $2);
$tables{$engine}{$t} = 1;
# A column is a name at the start of a line followed by a type.
# The words below start a CONTINUATION - a REFERENCES clause
# wrapping onto `ON DELETE CASCADE` reads as a column called `on`
# otherwise, which is a failing test with no bug behind it.
my @kw = qw(unique primary foreign check references constraint
on default not null cascade);
my %c = map { lc $_ => 1 } $body =~ /^\s+(\w+)\s+\S/gm;
delete @c{@kw};
$cols{$engine}{$t} = \%c;
}
}
is_deeply([ sort keys %{ $tables{pg} } ], [ sort keys %{ $tables{sqlite} } ],
'both engines describe the same tables')
or diag("pg only: @{[ grep { !$tables{sqlite}{$_} } sort keys %{$tables{pg}} ]}\n"
. "sqlite only: @{[ grep { !$tables{pg}{$_} } sort keys %{$tables{sqlite}} ]}");
t/0914-alert-editor.t view on Meta::CPAN
(rule_id, series, kind, from_state, to_state, at)
VALUES (?, 'all', 1, 'ok', 'firing', 1)", undef, $r->{id});
$dbh->do("INSERT INTO notifications
(rule_id, series, kind, at, created_at)
VALUES (?, 'all', 1, 1, 1)", undef, $r->{id});
my $d = $C->can('delete_alert')->($db, 'default', $r->{id});
ok($d->{ok}, 'the rule deletes');
for my $t (qw(alert_state alert_events notifications)) {
my ($n) = $dbh->selectrow_array("SELECT COUNT(*) FROM $t");
is($n, 0, " and $t went with it - the cascade is real because the "
. 'backend turns foreign keys on');
}
}
done_testing();
( run in 0.839 second using v1.01-cache-2.11-cpan-e7c6538aa59 )