Tests: restructure to more closely mirror the sources
t/ had lots of directories and files mirroring src/lib/Hydra. This moves those files under t/Hydra
This commit is contained in:
@ -1,115 +0,0 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Setup;
|
||||
|
||||
my %ctx = test_init();
|
||||
|
||||
require Hydra::Schema;
|
||||
require Hydra::Model::DB;
|
||||
use Hydra::Event;
|
||||
use Hydra::Event::BuildFinished;
|
||||
|
||||
use Test2::V0;
|
||||
use Test2::Tools::Exception;
|
||||
use Test2::Tools::Mock qw(mock_obj);
|
||||
|
||||
my $db = Hydra::Model::DB->new;
|
||||
hydra_setup($db);
|
||||
|
||||
subtest "Parsing" => sub {
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("build_finished", "") },
|
||||
qr/at least one argument/,
|
||||
"empty payload"
|
||||
);
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("build_finished", "abc123") },
|
||||
qr/should be integers/,
|
||||
"build ID should be an integer"
|
||||
);
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("build_finished", "123\tabc123") },
|
||||
qr/should be integers/,
|
||||
"dependent ID should be an integer"
|
||||
);
|
||||
is(
|
||||
Hydra::Event::parse_payload("build_finished", "123"),
|
||||
Hydra::Event::BuildFinished->new(123, []),
|
||||
"no dependent builds"
|
||||
);
|
||||
is(
|
||||
Hydra::Event::parse_payload("build_finished", "123\t456"),
|
||||
Hydra::Event::BuildFinished->new(123, [456]),
|
||||
"one dependent build"
|
||||
);
|
||||
is(
|
||||
Hydra::Event::parse_payload("build_finished", "123\t456\t789\t012\t345"),
|
||||
Hydra::Event::BuildFinished->new(123, [456, 789, 12, 345]),
|
||||
"four dependent builds"
|
||||
);
|
||||
};
|
||||
|
||||
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
|
||||
my $jobset = createBaseJobset("basic", "basic.nix", $ctx{jobsdir});
|
||||
ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0");
|
||||
is(nrQueuedBuildsForJobset($jobset), 3, "Evaluating jobs/basic.nix should result in 3 builds");
|
||||
|
||||
subtest "interested" => sub {
|
||||
my $event = Hydra::Event::BuildFinished->new(123, []);
|
||||
|
||||
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 => [
|
||||
"buildFinished" => sub {}
|
||||
]
|
||||
);
|
||||
|
||||
is($event->interestedIn($plugin), 1, "The plugin is interesting.");
|
||||
};
|
||||
};
|
||||
|
||||
subtest "load" => sub {
|
||||
my ($build, $dependent_a, $dependent_b) = $db->resultset('Builds')->search(
|
||||
{ },
|
||||
{ limit => 3 }
|
||||
)->all;
|
||||
|
||||
my $event = Hydra::Event::BuildFinished->new($build->id, [$dependent_a->id, $dependent_b->id]);
|
||||
|
||||
$event->load($db);
|
||||
|
||||
is($event->{"build"}->id, $build->id, "The build record matches.");
|
||||
is($event->{"dependents"}[0]->id, $dependent_a->id, "The dependent_a record matches.");
|
||||
is($event->{"dependents"}[1]->id, $dependent_b->id, "The dependent_b record matches.");
|
||||
|
||||
# Create a fake "plugin" with a buildFinished sub, the sub sets this
|
||||
# global passedBuild and passedDependents variables for verifying.
|
||||
my $passedBuild;
|
||||
my $passedDependents;
|
||||
my $plugin = {};
|
||||
my $mock = mock_obj $plugin => (
|
||||
add => [
|
||||
"buildFinished" => sub {
|
||||
my ($self, $build, $dependents) = @_;
|
||||
$passedBuild = $build;
|
||||
$passedDependents = $dependents;
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
$event->execute($db, $plugin);
|
||||
|
||||
is($passedBuild->id, $build->id, "The plugin's buildFinished hook is called with a matching build");
|
||||
is($passedDependents->[0]->id, $dependent_a->id, "The plugin's buildFinished hook is called with a matching dependent_a");
|
||||
is($passedDependents->[1]->id, $dependent_b->id, "The plugin's buildFinished hook is called with a matching dependent_b");
|
||||
};
|
||||
|
||||
done_testing;
|
@ -1,91 +0,0 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Setup;
|
||||
use Hydra::Event;
|
||||
use Hydra::Event::BuildQueued;
|
||||
use Test2::V0;
|
||||
use Test2::Tools::Exception;
|
||||
use Test2::Tools::Mock qw(mock_obj);
|
||||
|
||||
my $ctx = test_context();
|
||||
|
||||
my $db = $ctx->db();
|
||||
|
||||
my $builds = $ctx->makeAndEvaluateJobset(
|
||||
expression => "basic.nix"
|
||||
);
|
||||
|
||||
subtest "Parsing build_queued" => sub {
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("build_queued", "") },
|
||||
qr/one argument/,
|
||||
"empty payload"
|
||||
);
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("build_queued", "abc123\tabc123") },
|
||||
qr/only one argument/,
|
||||
"two arguments"
|
||||
);
|
||||
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("build_queued", "abc123") },
|
||||
qr/should be an integer/,
|
||||
"not an integer"
|
||||
);
|
||||
is(
|
||||
Hydra::Event::parse_payload("build_queued", "19"),
|
||||
Hydra::Event::BuildQueued->new(19),
|
||||
"Valid parse"
|
||||
);
|
||||
};
|
||||
|
||||
subtest "interested" => sub {
|
||||
my $event = Hydra::Event::BuildQueued->new(123, []);
|
||||
|
||||
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 => [
|
||||
"buildQueued" => sub {}
|
||||
]
|
||||
);
|
||||
|
||||
is($event->interestedIn($plugin), 1, "The plugin is interesting.");
|
||||
};
|
||||
};
|
||||
|
||||
subtest "load" => sub {
|
||||
my $build = $builds->{"empty_dir"};
|
||||
|
||||
my $event = Hydra::Event::BuildQueued->new($build->id);
|
||||
|
||||
$event->load($db);
|
||||
|
||||
is($event->{"build"}->id, $build->id, "The build record matches.");
|
||||
|
||||
# Create a fake "plugin" with a buildQueued sub, the sub sets this
|
||||
# global passedBuild variable.
|
||||
my $passedBuild;
|
||||
my $plugin = {};
|
||||
my $mock = mock_obj $plugin => (
|
||||
add => [
|
||||
"buildQueued" => sub {
|
||||
my ($self, $build) = @_;
|
||||
$passedBuild = $build;
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
$event->execute($db, $plugin);
|
||||
|
||||
is($passedBuild->id, $build->id, "The plugin's buildQueued hook is called with the proper build");
|
||||
};
|
||||
|
||||
done_testing;
|
@ -1,100 +0,0 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Setup;
|
||||
|
||||
my %ctx = test_init();
|
||||
|
||||
require Hydra::Schema;
|
||||
require Hydra::Model::DB;
|
||||
use Hydra::Event;
|
||||
use Hydra::Event::BuildStarted;
|
||||
|
||||
use Test2::V0;
|
||||
use Test2::Tools::Exception;
|
||||
use Test2::Tools::Mock qw(mock_obj);
|
||||
|
||||
my $db = Hydra::Model::DB->new;
|
||||
hydra_setup($db);
|
||||
|
||||
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
|
||||
my $jobset = createBaseJobset("basic", "basic.nix", $ctx{jobsdir});
|
||||
ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0");
|
||||
is(nrQueuedBuildsForJobset($jobset), 3, "Evaluating jobs/basic.nix should result in 3 builds");
|
||||
|
||||
subtest "Parsing build_started" => sub {
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("build_started", "") },
|
||||
qr/one argument/,
|
||||
"empty payload"
|
||||
);
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("build_started", "abc123\tabc123") },
|
||||
qr/only one argument/,
|
||||
"two arguments"
|
||||
);
|
||||
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("build_started", "abc123") },
|
||||
qr/should be an integer/,
|
||||
"not an integer"
|
||||
);
|
||||
is(
|
||||
Hydra::Event::parse_payload("build_started", "19"),
|
||||
Hydra::Event::BuildStarted->new(19),
|
||||
"Valid parse"
|
||||
);
|
||||
};
|
||||
|
||||
subtest "interested" => sub {
|
||||
my $event = Hydra::Event::BuildStarted->new(123, []);
|
||||
|
||||
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 => [
|
||||
"buildStarted" => sub {}
|
||||
]
|
||||
);
|
||||
|
||||
is($event->interestedIn($plugin), 1, "The plugin is interesting.");
|
||||
};
|
||||
};
|
||||
|
||||
subtest "load" => sub {
|
||||
my $build = $db->resultset('Builds')->search(
|
||||
{ },
|
||||
{ limit => 1 }
|
||||
)->next;
|
||||
|
||||
my $event = Hydra::Event::BuildStarted->new($build->id);
|
||||
|
||||
$event->load($db);
|
||||
|
||||
is($event->{"build"}->id, $build->id, "The build record matches.");
|
||||
|
||||
# Create a fake "plugin" with a buildStarted sub, the sub sets this
|
||||
# global passedBuild variable.
|
||||
my $passedBuild;
|
||||
my $plugin = {};
|
||||
my $mock = mock_obj $plugin => (
|
||||
add => [
|
||||
"buildStarted" => sub {
|
||||
my ($self, $build) = @_;
|
||||
$passedBuild = $build;
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
$event->execute($db, $plugin);
|
||||
|
||||
is($passedBuild->id, $build->id, "The plugin's buildStarted hook is called with the proper build");
|
||||
};
|
||||
|
||||
done_testing;
|
@ -1,124 +0,0 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use Setup;
|
||||
|
||||
my %ctx = test_init();
|
||||
|
||||
require Hydra::Schema;
|
||||
require Hydra::Model::DB;
|
||||
use Hydra::Event;
|
||||
use Hydra::Event::BuildStarted;
|
||||
|
||||
use Test2::V0;
|
||||
use Test2::Tools::Exception;
|
||||
use Test2::Tools::Mock qw(mock_obj);
|
||||
|
||||
my $db = Hydra::Model::DB->new;
|
||||
hydra_setup($db);
|
||||
|
||||
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
|
||||
my $jobset = createBaseJobset("basic", "basic.nix", $ctx{jobsdir});
|
||||
ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0");
|
||||
is(nrQueuedBuildsForJobset($jobset), 3, "Evaluating jobs/basic.nix should result in 3 builds");
|
||||
|
||||
for my $build (queuedBuildsForJobset($jobset)) {
|
||||
ok(runBuild($build), "Build '".$build->job."' from jobs/basic.nix should exit with return code 0");
|
||||
}
|
||||
|
||||
|
||||
|
||||
subtest "Parsing step_finished" => sub {
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("step_finished", "") },
|
||||
qr/three arguments/,
|
||||
"empty payload"
|
||||
);
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("step_finished", "abc123") },
|
||||
qr/three arguments/,
|
||||
"one argument"
|
||||
);
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("step_finished", "abc123\tabc123") },
|
||||
qr/three arguments/,
|
||||
"two arguments"
|
||||
);
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("step_finished", "abc123\tabc123\tabc123\tabc123") },
|
||||
qr/three arguments/,
|
||||
"four arguments"
|
||||
);
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("step_finished", "abc123\t123\t/path/to/log") },
|
||||
qr/should be an integer/,
|
||||
"not an integer: first position"
|
||||
);
|
||||
like(
|
||||
dies { Hydra::Event::parse_payload("step_finished", "123\tabc123\t/path/to/log") },
|
||||
qr/should be an integer/,
|
||||
"not an integer: second argument"
|
||||
);
|
||||
is(
|
||||
Hydra::Event::parse_payload("step_finished", "123\t456\t/path/to/logfile"),
|
||||
Hydra::Event::StepFinished->new(123, 456, "/path/to/logfile")
|
||||
);
|
||||
};
|
||||
|
||||
subtest "interested" => sub {
|
||||
my $event = Hydra::Event::StepFinished->new(123, []);
|
||||
|
||||
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 => [
|
||||
"stepFinished" => sub {}
|
||||
]
|
||||
);
|
||||
|
||||
is($event->interestedIn($plugin), 1, "The plugin is interesting.");
|
||||
};
|
||||
};
|
||||
|
||||
subtest "load" => sub {
|
||||
|
||||
my $step = $db->resultset('BuildSteps')->search(
|
||||
{ },
|
||||
{ limit => 1 }
|
||||
)->next;
|
||||
my $build = $step->build;
|
||||
|
||||
my $event = Hydra::Event::StepFinished->new($build->id, $step->stepnr, "/foo/bar/baz");
|
||||
|
||||
$event->load($db);
|
||||
is($event->{"step"}->get_column("build"), $build->id, "The build record matches.");
|
||||
|
||||
# Create a fake "plugin" with a stepFinished sub, the sub sets this
|
||||
# "global" passedStep, passedLogPath variables.
|
||||
my $passedStep;
|
||||
my $passedLogPath;
|
||||
my $plugin = {};
|
||||
my $mock = mock_obj $plugin => (
|
||||
add => [
|
||||
"stepFinished" => sub {
|
||||
my ($self, $step, $log_path) = @_;
|
||||
$passedStep = $step;
|
||||
$passedLogPath = $log_path;
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
$event->execute($db, $plugin);
|
||||
|
||||
is($passedStep->get_column("build"), $build->id, "The plugin's stepFinished hook is called with a step from the expected build");
|
||||
is($passedStep->stepnr, $step->stepnr, "The plugin's stepFinished hook is called with the proper step of the build");
|
||||
is($passedLogPath, "/foo/bar/baz", "The plugin's stepFinished hook is called with the proper log path");
|
||||
};
|
||||
|
||||
done_testing;
|
Reference in New Issue
Block a user