RunCommand: enable the plugin if dynamicruncommand is set

This commit is contained in:
Graham Christensen 2021-12-08 11:38:14 -05:00
parent 6ffc93c01a
commit ea311a0eb4
2 changed files with 140 additions and 3 deletions

View file

@ -12,7 +12,29 @@ use Try::Tiny;
sub isEnabled {
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 {

View file

@ -7,13 +7,13 @@ use Hydra::Plugin::RunCommand;
subtest "isEnabled" => sub {
is(
Hydra::Plugin::RunCommand::isEnabled({}),
"",
0,
"Disabled by default."
);
is(
Hydra::Plugin::RunCommand::isEnabled({ config => {}}),
"",
0,
"Disabled by default."
);
@ -22,6 +22,121 @@ subtest "isEnabled" => sub {
1,
"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 {