.github
datadog
doc
examples
foreman
src
t
Helper
Hydra
Config
Controller
Event
BuildFinished.t
BuildQueued.t
BuildStarted.t
CachedBuildFinished.t
CachedBuildQueued.t
EvalAdded.t
EvalCached.t
EvalFailed.t
EvalStarted.t
StepFinished.t
Helper
Plugin
Schema
View
Event.t
Math.t
PostgresListener.t
TaskDispatcher.t
evaluator
input-types
jobs
lib
queue-runner
scripts
Makefile.am
api-test.t
build-products.t
perlcritic.pl
s3-backup-test.config
s3-backup-test.pl
setup-notifications-jobset.pl
test.pl
.editorconfig
.gitignore
.perlcriticrc
.yath.rc
COPYING
INSTALL
Makefile.am
Procfile
README.md
bootstrap
configure.ac
default.nix
flake.lock
flake.nix
hydra-api.yaml
hydra-module.nix
shell.nix
version.txt
I was not going to break the interface until I noticed the current implementation uses the string literal \t.
113 lines
3.2 KiB
Perl
113 lines
3.2 KiB
Perl
use strict;
|
|
use warnings;
|
|
use Setup;
|
|
use Hydra::Event;
|
|
use Hydra::Event::EvalAdded;
|
|
use Test2::V0;
|
|
use Test2::Tools::Exception;
|
|
use Test2::Tools::Mock qw(mock_obj);
|
|
|
|
|
|
my $ctx = test_context();
|
|
my $builds = $ctx->makeAndEvaluateJobset(
|
|
expression => "basic.nix",
|
|
build => 1
|
|
);
|
|
|
|
|
|
subtest "Parsing eval_added" => sub {
|
|
like(
|
|
dies { Hydra::Event::parse_payload("eval_added", "") },
|
|
qr/three arguments/,
|
|
"empty payload"
|
|
);
|
|
like(
|
|
dies { Hydra::Event::parse_payload("eval_added", "abc123") },
|
|
qr/three arguments/,
|
|
"one argument"
|
|
);
|
|
like(
|
|
dies { Hydra::Event::parse_payload("eval_added", "abc123\tabc123") },
|
|
qr/three arguments/,
|
|
"two arguments"
|
|
);
|
|
like(
|
|
dies { Hydra::Event::parse_payload("eval_added", "abc123\tabc123\tabc123\tabc123") },
|
|
qr/three arguments/,
|
|
"four arguments"
|
|
);
|
|
like(
|
|
dies { Hydra::Event::parse_payload("eval_added", "abc123\tabc123\t123") },
|
|
qr/should be an integer/,
|
|
"not an integer: second position"
|
|
);
|
|
like(
|
|
dies { Hydra::Event::parse_payload("eval_added", "abc123\t123\tabc123") },
|
|
qr/should be an integer/,
|
|
"not an integer: third position"
|
|
);
|
|
is(
|
|
Hydra::Event::parse_payload("eval_added", "abc123\t123\t456"),
|
|
Hydra::Event::EvalAdded->new("abc123", 123, 456)
|
|
);
|
|
};
|
|
|
|
subtest "interested" => sub {
|
|
my $event = Hydra::Event::EvalAdded->new("abc123", 123, 456);
|
|
|
|
subtest "A plugin which does not implement the API" => sub {
|
|
my $plugin = {};
|
|
my $mock = mock_obj $plugin => ();
|
|
|
|
is($event->interestedIn($plugin), 0, "The plugin is not interesting.");
|
|
};
|
|
|
|
subtest "A plugin which does implement the API" => sub {
|
|
my $plugin = {};
|
|
my $mock = mock_obj $plugin => (
|
|
add => [
|
|
"evalAdded" => sub {}
|
|
]
|
|
);
|
|
|
|
is($event->interestedIn($plugin), 1, "The plugin is interesting.");
|
|
};
|
|
};
|
|
|
|
subtest "load" => sub {
|
|
my $jobset = $builds->{"empty_dir"}->jobset;
|
|
my $evaluation = $builds->{"empty_dir"}->jobsetevals->first();
|
|
|
|
my $event = Hydra::Event::EvalAdded->new("traceID", $jobset->id, $evaluation->id);
|
|
|
|
$event->load($ctx->db());
|
|
is($event->{"trace_id"}, "traceID", "The Trace ID matches");
|
|
is($event->{"jobset_id"}, $jobset->id, "The Jobset ID matches");
|
|
is($event->{"evaluation_id"}, $evaluation->id, "The Evaluation ID matches");
|
|
|
|
|
|
# Create a fake "plugin" with a evalAdded sub, the sub sets these
|
|
# "globals"
|
|
my $passedTraceID;
|
|
my $passedJobset;
|
|
my $passedEvaluation;
|
|
my $plugin = {};
|
|
my $mock = mock_obj $plugin => (
|
|
add => [
|
|
"evalAdded" => sub {
|
|
my ($self, $traceID, $jobset, $evaluation) = @_;
|
|
$passedTraceID = $traceID;
|
|
$passedJobset = $jobset;
|
|
$passedEvaluation = $evaluation;
|
|
}
|
|
]
|
|
);
|
|
|
|
$event->execute($ctx->db(), $plugin);
|
|
is($passedTraceID, "traceID", "We get the expected trace ID");
|
|
is($passedJobset->id, $jobset->id, "The correct jobset is passed");
|
|
is($passedEvaluation->id, $evaluation->id, "The correct evaluation is passed");
|
|
};
|
|
|
|
done_testing;
|