Adding tests to Peace::DAO::Build.
This commit is contained in:
parent
693d720ede
commit
90f9f743a0
@ -49,6 +49,7 @@ EOF
|
|||||||
my $result =
|
my $result =
|
||||||
$dbh->selectrow_hashref( $insert, undef, $build->release->uuid,
|
$dbh->selectrow_hashref( $insert, undef, $build->release->uuid,
|
||||||
$build->success, $build->log, $build->arch );
|
$build->success, $build->log, $build->arch );
|
||||||
|
die "Couldn't create build." if !defined $result;
|
||||||
my $uuid = $result->{uuid};
|
my $uuid = $result->{uuid};
|
||||||
my $new_build = $self->recover_by_uuid( uuid => $uuid );
|
my $new_build = $self->recover_by_uuid( uuid => $uuid );
|
||||||
$build->uuid( $new_build->uuid );
|
$build->uuid( $new_build->uuid );
|
||||||
|
64
t/00012-build-dao.t
Normal file
64
t/00012-build-dao.t
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
use v5.30.0;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use Test::Most tests => 3;
|
||||||
|
|
||||||
|
use DBI;
|
||||||
|
use DateTime;
|
||||||
|
use DateTime::Format::Pg;
|
||||||
|
|
||||||
|
use Peace::Test::Mock::Model::Build;
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
use_ok 'Peace::DAO::Build';
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
## GIVEN
|
||||||
|
my $sql = <<'EOF';
|
||||||
|
INSERT INTO builds (release, success, log,
|
||||||
|
arch)
|
||||||
|
VALUES (?, ?, ?, ?)
|
||||||
|
RETURNING uuid;
|
||||||
|
EOF
|
||||||
|
my $datetime = DateTime->now;
|
||||||
|
my $iso8601 = DateTime::Format::Pg->new;
|
||||||
|
my $uuid = 'hola';
|
||||||
|
my $dbh = DBI->connect('dbi:Mock:');
|
||||||
|
my $build = Peace::Test::Mock::Model::Build->new;
|
||||||
|
$build->release->uuid('hola');
|
||||||
|
my $build_dao = Peace::DAO::Build->new( dbh => $dbh );
|
||||||
|
$dbh->{mock_add_resultset} = {
|
||||||
|
sql => $sql,
|
||||||
|
results => [ ['uuid'], [$uuid], ]
|
||||||
|
};
|
||||||
|
$sql = <<'EOF';
|
||||||
|
SELECT uuid, date_creation,
|
||||||
|
release, success, log, arch
|
||||||
|
FROM builds
|
||||||
|
WHERE uuid = ?;
|
||||||
|
EOF
|
||||||
|
$dbh->{mock_add_resultset} = {
|
||||||
|
sql => $sql,
|
||||||
|
results => [
|
||||||
|
[ 'uuid', 'date_creation', 'release', 'success', 'log', 'arch' ],
|
||||||
|
[
|
||||||
|
$uuid, $iso8601->format_datetime($datetime),
|
||||||
|
$build->release->uuid, $build->success,
|
||||||
|
$build->log, $build->arch
|
||||||
|
],
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
## WHEN
|
||||||
|
$build_dao->create( build => $build );
|
||||||
|
|
||||||
|
## THEN
|
||||||
|
is $build->uuid, $uuid, 'Uuid is set correctly';
|
||||||
|
is "" . $build->date_creation, "" . $datetime,
|
||||||
|
'Date creation matchs the expected';
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user