Updates TestUtil.pm for unit tests#1340
Conversation
| (in all uppercase), and their corresponding values are an array of: | ||
|
|
||
| =over | ||
|
|
||
| =item * | ||
| a boolean (testable) | ||
|
|
||
| =item * | ||
| a string (zone name) | ||
|
|
||
| =item * | ||
| an array of strings (all test case message tags) | ||
|
|
||
| =item * | ||
| an array of strings (mandatory message tags) | ||
|
|
||
| =item * | ||
| an array of strings (forbidden message tags) | ||
|
|
||
| =item * | ||
| an array of name server expressions for undelegated name servers | ||
|
|
||
| =item * | ||
| an array of DS expressions for "undelegated" DS | ||
|
|
||
| =back |
There was a problem hiding this comment.
These are a lot of positional arguments. I suggest replacing the arrayref of positional arguments with a hashref of named arguments.
There was a problem hiding this comment.
I think that I understand what you mean, but that will make it more complex to create e.g. t/Test-nameserver15.t and harder to read it. Please note that "all test case message tags" will just be a variable, and that the two last arguments will not be used in most cases.
There was a problem hiding this comment.
I'm not sure how you're measuring complexity in the call site. The calling code would be easier to read and less error prone because you wouldn't run the risk of mixing up the arguments. There would be more code inside perform_testcase_testing() but this is a quite good investment.
| if ( ref( $testable ) ne '' ) { | ||
| diag("Scenario $scenario: Type of testable must not be a reference"); | ||
| fail("Testable is of the correct type"); | ||
| next; | ||
| } |
There was a problem hiding this comment.
This is problematic for a couple of reasons, but the biggest one is that the diag() and fail() methods are uses here for complaining about the test script. They should only be used for complaining about the object under test. When complaining about the test script it's better to use croak().
There are more of these below.
I do realize you followed the established pattern, but it would be a really good to break this pattern.
There was a problem hiding this comment.
This is not new code. It is the same code as in the current version, but moved up. Could you suggest the replacement code?
There was a problem hiding this comment.
Just replace the diag, fail and next with a croak.
| } | ||
|
|
||
| if ( ref( $mandatory_message_tags ) ne 'ARRAY' ) { | ||
| if ( ref( $all_test_case_tags ) ne 'ARRAY' ) { |
There was a problem hiding this comment.
If we care to verify that it's an array, shouldn't we also check the type of the array elements?
There are more of these below.
There was a problem hiding this comment.
This is not new code. It is the same code as in the current version, but maybe moved. What you suggest is that all elements in the array should be matching the tag format? I guess that could be done. Should that also use croak() instead of diag/fail? If so, what is the benefit of croak?
There was a problem hiding this comment.
I don’t think it’s useful to check the type of the array elements: because the array is usually prepared using qw(), it is reasonable to assume that each element can be treated as a string. I’m not saying this kind of thorough checking shouldn’t be done; only that I don’t mind if it isn’t done.
However, I do agree that we should use croak instead of diag and fail here. We don’t want to raise an issue with the domain under test here, but with the code that tests the code. In that case, aborting early gives a stronger signal that the problem is with the testing code.
Co-authored-by: Mattias Päivärinta <mattias@paivarinta.se>
* Replaces diag/fail with croak(). * Additional verification of test data from t file. * Moved "all tags" to be a common parameter, not scenario specific.
|
@mattias-p, please re-review. |
|
@mattias-p, could your re-review? |
| 'NO-RESPONSE-MX-QUERY' => [ | ||
| q(no-response-mx-query.zone09.xa), | ||
| 1, | ||
| q(no-response-mx-query.zone09.xa),# |
There was a problem hiding this comment.
Why is there a trailing # here? (many other occurrences below)
There was a problem hiding this comment.
I tagged scenarios where MANDATORY and FORBIDDEN did not cover all tags. I'll make it explicit.
Co-authored-by: tgreenx <96772376+tgreenx@users.noreply.github.com>
|
@tgreenx and @mattias-p, please re-review. |
|
@mattias-p, @tgreenx and @marc-vanderwal, can you approve this? I would like to merge it. It updates TestUtils.pm and the unit tests that use it. They pass as expected. |
|
I’ve had a look. I see no issues that haven’t already been brought up by @tgreenx. |
Co-authored-by: tgreenx <96772376+tgreenx@users.noreply.github.com>
|
@marc-vanderwal and @tgreenx, please re-review after my latest updates. |
marc-vanderwal
left a comment
There was a problem hiding this comment.
Looks fine. I do think that croak is better than diag/fail when there is a problem with the data in the test script. It’s better to have a specific failure mode for problems with the testing code, that can’t be confused with the outcome of a failing unit test suite for reasons unrelated to the testing code itself.
| } | ||
|
|
||
| if ( ref( $mandatory_message_tags ) ne 'ARRAY' ) { | ||
| if ( ref( $all_test_case_tags ) ne 'ARRAY' ) { |
There was a problem hiding this comment.
I don’t think it’s useful to check the type of the array elements: because the array is usually prepared using qw(), it is reasonable to assume that each element can be treated as a string. I’m not saying this kind of thorough checking shouldn’t be done; only that I don’t mind if it isn’t done.
However, I do agree that we should use croak instead of diag and fail here. We don’t want to raise an issue with the domain under test here, but with the code that tests the code. In that case, aborting early gives a stronger signal that the problem is with the testing code.
| } | ||
|
|
||
| if ( ! defined( $mandatory_message_tags ) and !defined( $forbidden_message_tags ) ) { | ||
| diag("Scenario $scenario: Not both array of mandatory tags and array of forbidden tags can be undefined"); |
There was a problem hiding this comment.
| diag("Scenario $scenario: Not both array of mandatory tags and array of forbidden tags can be undefined"); | |
| diag("Scenario $scenario: Arrays of mandatory tags and forbidden tags cannot be both undefined"); |
There was a problem hiding this comment.
Your proposal must be based on old code. The current code uses "croak" for such tests.
|
@marc-vanderwal and @tgreenx, please re-review after my latest updates. All tests pass. TestUtil now treats empty-empty as an error. Can this be merged now? |
tgreenx
left a comment
There was a problem hiding this comment.
@marc-vanderwal and @tgreenx, please re-review after my latest updates. All tests pass. TestUtil now treats empty-empty as an error. Can this be merged now?
Almost! A few nits left:
Co-authored-by: tgreenx <96772376+tgreenx@users.noreply.github.com>
|
I have commited the proposal from @tgreenx and I have updated the documentation so that it states that empty-empty is not permitted. @marc-vanderwal and @tgreenx, please re-review. |
Co-authored-by: Marc van der Wal <103426270+marc-vanderwal@users.noreply.github.com>
|
@marc-vanderwal and @tgreenx, please re-review. |
Purpose
This PR introduces two changes to function in TestUtil.pm:
tfile. Use croak() instead.The unit test files using TestUtil.pm have been updated to match the new format.
Five new scenarios have been added to Consistency05 and two to Consistency06. Both updates are to unit tests that uses the new function in TestUtil.pm that supports undelegated data.
The following new scenario fail:
Context
The update is needed for zonemaster/zonemaster#1255.
How to test this PR
Review TestUtil.pm. If the unit test files using TestUtil.pm then they should be fine.