forked from lix-project/hydra
RunCommand: enable the plugin if dynamicruncommand is set
This commit is contained in:
parent
6ffc93c01a
commit
ea311a0eb4
|
@ -12,7 +12,29 @@ use Try::Tiny;
|
||||||
|
|
||||||
sub isEnabled {
|
sub isEnabled {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
return defined $self->{config}->{runcommand};
|
|
||||||
|
return areStaticCommandsEnabled($self->{config}) || areDynamicCommandsEnabled($self->{config});
|
||||||
|
}
|
||||||
|
|
||||||
|
sub areStaticCommandsEnabled {
|
||||||
|
my ($config) = @_;
|
||||||
|
|
||||||
|
if (defined $config->{runcommand}) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub areDynamicCommandsEnabled {
|
||||||
|
my ($config) = @_;
|
||||||
|
|
||||||
|
if ((defined $config->{dynamicruncommand})
|
||||||
|
&& $config->{dynamicruncommand}->{enable}) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub configSectionMatches {
|
sub configSectionMatches {
|
||||||
|
|
|
@ -7,13 +7,13 @@ use Hydra::Plugin::RunCommand;
|
||||||
subtest "isEnabled" => sub {
|
subtest "isEnabled" => sub {
|
||||||
is(
|
is(
|
||||||
Hydra::Plugin::RunCommand::isEnabled({}),
|
Hydra::Plugin::RunCommand::isEnabled({}),
|
||||||
"",
|
0,
|
||||||
"Disabled by default."
|
"Disabled by default."
|
||||||
);
|
);
|
||||||
|
|
||||||
is(
|
is(
|
||||||
Hydra::Plugin::RunCommand::isEnabled({ config => {}}),
|
Hydra::Plugin::RunCommand::isEnabled({ config => {}}),
|
||||||
"",
|
0,
|
||||||
"Disabled by default."
|
"Disabled by default."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -22,6 +22,121 @@ subtest "isEnabled" => sub {
|
||||||
1,
|
1,
|
||||||
"Enabled if any runcommand blocks exist."
|
"Enabled if any runcommand blocks exist."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::isEnabled({ config => { dynamicruncommand => {}}}),
|
||||||
|
0,
|
||||||
|
"Not enabled if an empty dynamicruncommand blocks exist."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::isEnabled({ config => { dynamicruncommand => { enable => 0 }}}),
|
||||||
|
0,
|
||||||
|
"Not enabled if a dynamicruncommand blocks exist without enable being set to 1."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::isEnabled({ config => { dynamicruncommand => { enable => 1 }}}),
|
||||||
|
1,
|
||||||
|
"Enabled if a dynamicruncommand blocks exist with enable being set to 1."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::isEnabled({ config => {
|
||||||
|
runcommand => {},
|
||||||
|
dynamicruncommand => { enable => 0 }
|
||||||
|
}}),
|
||||||
|
1,
|
||||||
|
"Enabled if a runcommand config block exists, even if a dynamicruncommand is explicitly disabled."
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
subtest "areStaticCommandsEnabled" => sub {
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areStaticCommandsEnabled({}),
|
||||||
|
0,
|
||||||
|
"Disabled by default."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areStaticCommandsEnabled({}),
|
||||||
|
0,
|
||||||
|
"Disabled by default."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areStaticCommandsEnabled({ runcommand => {}}),
|
||||||
|
1,
|
||||||
|
"Enabled if any runcommand blocks exist."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areStaticCommandsEnabled({ dynamicruncommand => {}}),
|
||||||
|
0,
|
||||||
|
"Not enabled by dynamicruncommand blocks."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areStaticCommandsEnabled({ dynamicruncommand => { enable => 0 }}),
|
||||||
|
0,
|
||||||
|
"Not enabled by dynamicruncommand blocks."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areStaticCommandsEnabled({ dynamicruncommand => { enable => 1 }}),
|
||||||
|
0,
|
||||||
|
"Not enabled by dynamicruncommand blocks."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areStaticCommandsEnabled({
|
||||||
|
runcommand => {},
|
||||||
|
dynamicruncommand => { enable => 0 }
|
||||||
|
}),
|
||||||
|
1,
|
||||||
|
"Enabled if a runcommand config block exists, even if a dynamicruncommand is explicitly disabled."
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
subtest "areDynamicCommandsEnabled" => sub {
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areDynamicCommandsEnabled({}),
|
||||||
|
0,
|
||||||
|
"Disabled by default."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areDynamicCommandsEnabled({ runcommand => {}}),
|
||||||
|
0,
|
||||||
|
"Disabled even if any runcommand blocks exist."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areDynamicCommandsEnabled({ dynamicruncommand => {}}),
|
||||||
|
0,
|
||||||
|
"Not enabled if an empty dynamicruncommand blocks exist."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areDynamicCommandsEnabled({ dynamicruncommand => { enable => 0 }}),
|
||||||
|
0,
|
||||||
|
"Not enabled if a dynamicruncommand blocks exist without enable being set to 1."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areDynamicCommandsEnabled({ dynamicruncommand => { enable => 1 }}),
|
||||||
|
1,
|
||||||
|
"Enabled if a dynamicruncommand blocks exist with enable being set to 1."
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
Hydra::Plugin::RunCommand::areDynamicCommandsEnabled({
|
||||||
|
runcommand => {},
|
||||||
|
dynamicruncommand => { enable => 0 }
|
||||||
|
}),
|
||||||
|
0,
|
||||||
|
"Disabled if dynamicruncommand is explicitly disabled."
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest "configSectionMatches" => sub {
|
subtest "configSectionMatches" => sub {
|
||||||
|
|
Loading…
Reference in a new issue