Event.pm: add a new_event helper to parse and construct an Event

An Event will be part of many Tasks
This commit is contained in:
Graham Christensen 2021-08-09 10:05:33 -04:00 committed by Your Name
parent 64a3e75c10
commit 4e86e55008
2 changed files with 18 additions and 5 deletions

View file

@ -1,14 +1,9 @@
package Hydra::Event;
use strict;
use Hydra::Event::BuildFinished;
use Hydra::Event::BuildStarted;
use Hydra::Event::StepFinished;
our @ISA = qw(Exporter);
our @EXPORT = qw(
parse_payload
);
my %channels_to_events = (
build_started => \&Hydra::Event::BuildStarted::parse,
@ -28,3 +23,14 @@ sub parse_payload :prototype($$) {
return $parser->(@payload);
}
sub new_event {
my ($self, $channel_name, $payload) = @_;
return bless {
"channel_name" => $channel_name,
"payload" => $payload,
"event" => parse_payload($channel_name, $payload),
}, $self;
}

View file

@ -7,6 +7,13 @@ use Hydra::Event::StepFinished;
use Test2::V0;
use Test2::Tools::Exception;
subtest "Event: new event" => sub {
my $event = Hydra::Event->new_event("build_started", "19");
is($event->{'payload'}, "19");
is($event->{'channel_name'}, "build_started");
is($event->{'event'}->{'build_id'}, 19);
};
subtest "Payload type: build_started" => sub {
like(
dies { Hydra::Event::parse_payload("build_started", "") },