RunCommandLogs: set a UUID automatically

This commit is contained in:
Graham Christensen 2022-01-24 11:56:34 -05:00 committed by Cole Helbling
parent 89e8676d80
commit dcb0c1425c
2 changed files with 27 additions and 0 deletions

View file

@ -174,9 +174,30 @@ __PACKAGE__->belongs_to(
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZVpYU6k3d/k/nitjpdgf/A # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZVpYU6k3d/k/nitjpdgf/A
use POSIX qw(WEXITSTATUS WIFEXITED WIFSIGNALED WTERMSIG); use POSIX qw(WEXITSTATUS WIFEXITED WIFSIGNALED WTERMSIG);
use UUID4::Tiny qw(create_uuid_string);
use Digest::SHA1 qw(sha1_hex); use Digest::SHA1 qw(sha1_hex);
use Hydra::Model::DB; use Hydra::Model::DB;
=head2 new
Initialize a new row object.
Sets the UUID automatically unless a UUID is specified in the attributes.
=cut
sub new {
my ($class, $attrs) = @_;
if (!defined $attrs->{uuid}) {
$attrs->{uuid} = create_uuid_string();
}
my $new = $class->next::method($attrs);
return $new;
}
=head2 started =head2 started
Update the row with the current timestamp as the start time. Update the row with the current timestamp as the start time.

View file

@ -20,6 +20,12 @@ sub new_run_log {
}); });
} }
subtest "A new record has a UUID" => sub {
my $runlog = new_run_log();
is(length($runlog->uuid), 36, "The UUID attribute is sufficiently UUID-like.");
like($runlog->uuid, qr/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/, "The UUID attribute is sufficiently UUID-like.");
};
subtest "Not yet started" => sub { subtest "Not yet started" => sub {
my $runlog = new_run_log(); my $runlog = new_run_log();