Skip to content

Commit

Permalink
Merge pull request #2842 from kalikiana/equals_each_be_foreach
Browse files Browse the repository at this point in the history
Convert uses of `each` to `foreach`
  • Loading branch information
kalikiana committed Mar 20, 2020
2 parents fc67103 + a465431 commit 2966923
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 25 deletions.
3 changes: 2 additions & 1 deletion lib/OpenQA/Schema/Result/Jobs.pm
Expand Up @@ -1425,7 +1425,8 @@ sub update_status {
$self->insert_test_modules($status->{test_order}) if $status->{test_order};
my %known;
if ($status->{result}) {
while (my ($name, $result) = each %{$status->{result}}) {
foreach my $name (sort keys %{$status->{result}}) {
my $result = $status->{result}->{$name};
my $existent = $self->update_module($name, $result) || [];
for (@$existent) { $known{$_} = 1; }
}
Expand Down
11 changes: 6 additions & 5 deletions lib/OpenQA/Schema/ResultSet/Jobs.pm
Expand Up @@ -62,17 +62,18 @@ sub latest_build {
$attrs{order_by} = {-desc => 'me.id'}; # More reliable for tests than t_created
$attrs{columns} = qw(BUILD);

while (my ($k, $v) = each %args) {
foreach my $key (keys %args) {
my $value = $args{$key};

if (grep { $k eq $_ } qw(distri version flavor machine arch build test)) {
push(@conds, {"me." . uc($k) => $v});
if (grep { $key eq $_ } qw(distri version flavor machine arch build test)) {
push(@conds, {"me." . uc($key) => $value});
}
else {

my $subquery = $schema->resultset("JobSettings")->search(
{
key => uc($k),
value => $v
key => uc($key),
value => $value
});
push(@conds, {'me.id' => {-in => $subquery->get_column('job_id')->as_query}});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/OpenQA/UserAgent.pm
Expand Up @@ -77,8 +77,8 @@ sub _add_auth_headers {
$headers{'X-API-Hash'} = hmac_sha1_sum($self->_path_query($tx) . $timestamp, $self->apisecret);
}

while (my ($k, $v) = each %headers) {
$tx->req->headers->header($k, $v);
foreach my $key (keys %headers) {
$tx->req->headers->header($key, $headers{$key});
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/OpenQA/Utils.pm
Expand Up @@ -939,7 +939,8 @@ sub loaded_plugins {
sub hashwalker {
my ($hash, $callback, $keys) = @_;
$keys = [] if !$keys;
while (my ($key, $value) = each %$hash) {
foreach my $key (sort keys %$hash) {
my $value = $hash->{$key};
push @$keys, $key;
if (ref($value) eq 'HASH') {
hashwalker($value, $callback, $keys);
Expand Down
4 changes: 2 additions & 2 deletions lib/OpenQA/WebAPI/Auth/OpenID.pm
Expand Up @@ -90,8 +90,8 @@ sub auth_response {
return (error => 'Got response on http but https is forced. MOJO_REVERSE_PROXY not set?');
}

while (my ($k, $v) = each %params) {
$params{$k} = URI::Escape::uri_unescape($v);
foreach my $key (keys %params) {
$params{$key} = URI::Escape::uri_unescape($params{$key});
}

my $csr = Net::OpenID::Consumer->new(
Expand Down
7 changes: 4 additions & 3 deletions t/05-scheduler-dependencies.t
Expand Up @@ -1254,12 +1254,13 @@ my $ordered_sort = sub {
};

my %tests = ('duplicate' => $duplicate_test, 'slepos test workers' => $slepos_test_workers);
while (my ($k, $v) = each %tests) {
foreach my $key (sort keys %tests) {
my $value = $tests{$key};
no warnings 'redefine';
*OpenQA::Jobs::Constants::search_for = $unordered_sort;
subtest "$k unordered" => $v;
subtest "$key unordered" => $value;
*OpenQA::Jobs::Constants::search_for = $ordered_sort;
subtest "$k ordered" => $v;
subtest "$key ordered" => $value;
}

subtest "SAP setup - issue 52928" => sub {
Expand Down
15 changes: 7 additions & 8 deletions t/api/03-auth.t
Expand Up @@ -155,22 +155,21 @@ subtest 'wrong api key - replay attack' => sub() {

my $timestamp = 0;
my %headers = (
Accept => 'application/json',
'X-API-Key' => $self->apikey,
'X-API-Microtime' => $timestamp,
'X-API-Hash' => hmac_sha1_sum($self->_path_query($tx) . $timestamp, $self->apisecret),
);

while (my ($k, $v) = each %headers) {
$tx->req->headers->header($k, $v);
foreach my $key (keys %headers) {
$tx->req->headers->header($key, $headers{$key});
}
});
$t->get_ok('/api/v1/jobs')->status_is(200);
$t->post_ok('/api/v1/products/1')->status_is(403);
is($t->tx->res->json->{error}, 'timestamp mismatch', 'timestamp mismatch error');
$t->delete_ok('/api/v1/assets/1')->status_is(403);
is($t->tx->res->json->{error}, 'timestamp mismatch', 'timestamp mismatch error');
is($mock_asset_remove_callcount, 0, 'asset deletion function was not called');
$t->post_ok('/api/v1/products/1')->status_is(403)
->json_is('/error' => 'timestamp mismatch', 'timestamp mismatch error');
$t->delete_ok('/api/v1/assets/1')->status_is(403)
->json_is('/error' => 'timestamp mismatch', 'timestamp mismatch error');
is($mock_asset_remove_callcount, 0, 'asset deletion function was not called');
};

done_testing();
6 changes: 3 additions & 3 deletions t/ui/01-list.t
Expand Up @@ -111,9 +111,9 @@ sub schema_hook {

my $job99940 = $jobs->find(99940);
my %modules = (a => 'skip', b => 'ok', c => 'none', d => 'softfail', e => 'fail');
while (my ($k, $v) = each %modules) {
$job99940->insert_module({name => $k, category => $k, script => $k});
$job99940->update_module($k, {result => $v, details => []});
foreach my $key (sort keys %modules) {
$job99940->insert_module({name => $key, category => $key, script => $key});
$job99940->update_module($key, {result => $modules{$key}, details => []});
}

my $schedule_job = $jobs->create(
Expand Down

0 comments on commit 2966923

Please sign in to comment.