Adding tests to Peace::DAO::Build.

This commit is contained in:
sergiotarxz 2022-03-31 18:36:10 +02:00
parent 693d720ede
commit 90f9f743a0
2 changed files with 65 additions and 0 deletions

View File

@ -49,6 +49,7 @@ EOF
my $result =
$dbh->selectrow_hashref( $insert, undef, $build->release->uuid,
$build->success, $build->log, $build->arch );
die "Couldn't create build." if !defined $result;
my $uuid = $result->{uuid};
my $new_build = $self->recover_by_uuid( uuid => $uuid );
$build->uuid( $new_build->uuid );

64
t/00012-build-dao.t Normal file
View 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';
}