Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1065 from joyent/ether/fix-validation-results
Browse files Browse the repository at this point in the history
include validation name, version, description in all ValidationResults
  • Loading branch information
karenetheridge authored Nov 18, 2020
2 parents eff7296 + 499c07d commit d9c3358
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
5 changes: 4 additions & 1 deletion docs/json-schema/response.json
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,10 @@
"hint",
"message",
"status",
"validation_id"
"validation_id",
"name",
"version",
"description"
],
"type" : "object"
},
Expand Down
4 changes: 4 additions & 0 deletions docs/modules/Conch::DB::Result::ValidationResult.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ Type: many\_to\_many

Composing rels: ["validation\_state\_members"](#validation_state_members) -> validation\_state

### TO\_JSON

Include information about the validation corresponding to the result, if available.

## LICENSING

Copyright Joyent, Inc.
Expand Down
3 changes: 3 additions & 0 deletions json-schema/response.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,9 @@ definitions:
- message
- status
- validation_id
- name
- version
- description
properties:
id:
oneOf:
Expand Down
18 changes: 18 additions & 0 deletions lib/Conch/DB/Result/ValidationResult.pm
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,24 @@ __PACKAGE__->add_columns(
'+device_id' => { is_serializable => 0 },
);

use experimental 'signatures';

=head2 TO_JSON
Include information about the validation corresponding to the result, if available.
=cut

sub TO_JSON ($self) {
my $data = $self->next::method(@_);

if (my $validation = ($self->related_resultset('validation')->get_cache // [])->[0]) {
$data->{$_} = $validation->$_ foreach qw(name version description);
}

return $data;
}

1;
__END__
Expand Down
22 changes: 14 additions & 8 deletions lib/Conch/ValidationSystem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,16 @@ sub run_validation_plan ($self, %options) {

$validator->run($data);

push @validation_results, map
$validation_result_rs->new_result({
push @validation_results, map {
my $result = $validation_result_rs->new_result({
validation_id => $validation->id,
device_id => $device->id,
$_->%{qw(message hint status category component)},
}),
$validator->validation_results;
});
$result->related_resultset('validation')->set_cache([ $validation ]);
$result;
}
$validator->validation_results;

$self->log->debug('validation '.$validation->name.' returned no results for device id '.$device->id)
if not $validator->validation_results;
Expand Down Expand Up @@ -398,13 +401,16 @@ sub run_validation ($self, %options) {
$validator->run($data);

my $validation_result_rs = $self->schema->resultset('validation_result');
my @validation_results = map
$validation_result_rs->new_result({
my @validation_results = map {
my $result = $validation_result_rs->new_result({
validation_id => $validation->id,
device_id => $device->id,
$_->%{qw(message hint status category component)},
}),
$validator->validation_results;
});
$result->related_resultset('validation')->set_cache([ $validation ]);
$result;
}
$validator->validation_results;

return @validation_results;
}
Expand Down
1 change: 1 addition & 0 deletions t/integration/device-reports.t
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ subtest 'run report without an existing device and without making updates' => su
hint => ignore,
message => ignore,
status => any(qw(error fail pass)),
do { my $v = $_; map +($_ => $v->$_), qw(name version description) },
}, @validations)),
});

Expand Down

0 comments on commit d9c3358

Please sign in to comment.