65 lines
1.5 KiB
Perl
65 lines
1.5 KiB
Perl
#!/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';
|
|
}
|