Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testcase results #1055

Merged
merged 6 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,12 @@ Each *test* has a unique *test id*.

Basic data type: object

The object has three keys, `"module"`, `"message"` and `"level"`.
The object has four keys, `"module"`, `"message"`, `"level"` and `"testcase"`.

* `"module"`: a string. The *test module* that produced the result.
* `"message"`: a string. A human-readable *message* describing that particular result.
* `"level"`: a [*severity level*][Severity level]. The severity of the message.
* `"testcase"`: a string. The *test case ID* of the *test case* that produced the result.
matsduf marked this conversation as resolved.
Show resolved Hide resolved
matsduf marked this conversation as resolved.
Show resolved Hide resolved

Sometimes additional keys are present.

Expand Down Expand Up @@ -953,6 +954,11 @@ Example response:
"ipv4": true,
"client_id": "Zonemaster Dancer Frontend"
},
"testcase_descriptions": {
"ZONE08": "MX is not an alias",
"SYNTAX05": "Misuse of '@' character in the SOA RNAME field",
...
},
"results": [
{
"module": "SYSTEM",
Expand Down Expand Up @@ -995,6 +1001,8 @@ An object with the following properties:
* `"params"`: See below.
`start_domain_test` when the *test* was started.
* `"results"`: A list of [*test result*][Test result] objects.
* `"testcase_descriptions"`: A map with the [Test Case Identifiers] as keys and the
translated *Test Case Description* of the corresponding [test cases] as values.

If the test was created by [`start_domain_test`][start_domain_test] then `"params"`
is a normalized version `"params"` object sent to [`start_domain_test`][start_domain_test]
Expand All @@ -1015,9 +1023,9 @@ is a normalized version of an object created from the following parts:

#### `"error"`

>
> TODO: List all possible error codes and describe what they mean enough for clients to know how react to them.
>
>
> TODO: List all possible error codes and describe what they mean enough for clients to know how react to them.
>


## API method: `get_test_history`
Expand Down Expand Up @@ -1558,6 +1566,8 @@ The `"params"` object sent to [`start_domain_test`][start_domain_test] or
[Severity Level Definitions]: https://github.com/zonemaster/zonemaster/blob/master/docs/specifications/tests/SeverityLevelDefinitions.md
[Severity level]: #severity-level
[start_domain_test]: #api-method-start_domain_test
[test cases]: https://github.com/zonemaster/zonemaster/tree/master/docs/specifications/tests#list-of-defined-test-cases
[Test Case Identifiers]: https://github.com/zonemaster/zonemaster/blob/master/docs/internal-documentation/templates/specifications/tests/TestCaseIdentifierSpecification.md
matsduf marked this conversation as resolved.
Show resolved Hide resolved
[Test id]: #test-id
[Test result]: #test-result
[Timestamp]: #timestamp
Expand Down
4 changes: 4 additions & 0 deletions lib/Zonemaster/Backend/RPCAPI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ sub get_test_results {
eval { $translator->data } if $translator; # Provoke lazy loading of translation data

my @zm_results;
my %testcases;

my $test_info = $self->{db}->test_results( $params->{id} );
foreach my $test_res ( @{ $test_info->{results} } ) {
Expand All @@ -364,6 +365,8 @@ sub get_test_results {
$res->{message} =~ s/,/, /isg;
$res->{message} =~ s/;/; /isg;
$res->{level} = $test_res->{level};
$res->{testcase} = $test_res->{testcase};
$testcases{$res->{testcase}} = $translator->test_case_description($test_res->{testcase});

if ( $test_res->{module} eq 'SYSTEM' ) {
if ( $res->{message} =~ /policy\.json/ ) {
Expand Down Expand Up @@ -394,6 +397,7 @@ sub get_test_results {
}

$result = $test_info;
$result->{testcase_descriptions} = \%testcases;
$result->{results} = \@zm_results;

$translator->locale( $previous_locale );
Expand Down
3 changes: 3 additions & 0 deletions lib/Zonemaster/Backend/Translator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ sub translate_tag {
return decode_utf8( $octets );
}

sub test_case_description {
return decode_utf8(Zonemaster::Engine::Translator::test_case_description(@_));
}
1;