forked from lix-project/hydra
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:
parent
64a3e75c10
commit
4e86e55008
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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", "") },
|
||||
|
|
Loading…
Reference in a new issue