-
Notifications
You must be signed in to change notification settings - Fork 19
Added extra test coverage for validate_dnssec_job #2811
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
base: master
Are you sure you want to change the base?
Conversation
Pull request testing fails. Probable cause is timing in test method: |
Resolved the problem with ENV['nameserver_validation_timeout'] |
original_timeout = ENV['nameserver_validation_timeout'] | ||
|
||
# Seadista kindel väärtus testiks | ||
ENV['nameserver_validation_timeout'] = '4' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Translate comment to English, because registry is Open Source product.
Also, among the English comments, this one stands out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced this comment with more explanatory English comment.
def test_prepare_validator_configures_dnsruby_resolver_with_correct_parameters | ||
job = ValidateDnssecJob.new | ||
|
||
# To store original environment variable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment doesn't really add any meaning — it just explains what the code is doing, which is already obvious. So there are two options: either delete the comment, or rewrite it to explain what the nameserver_validation_timeout value does and how it affects the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the unnecessary comment.
|
||
resolver = job.send(:prepare_validator, "8.8.8.8") | ||
|
||
assert_instance_of Dnsruby::Resolver, resolver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we testing type safety or functionality here? Please clarify, because otherwise I don't see the point of this check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While Ruby is dynamically typed language, so it is meant that code behaves correctly at runtime. It is functional guarantee we can use resolver object in next steps.
valid_to: 1.year.from_now | ||
) | ||
|
||
# Add DNSKEY to domain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed!
job = ValidateDnssecJob.new | ||
job.define_singleton_method(:logger) { logger } | ||
|
||
# Run the job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed!
job.perform(domain_name: domain.name) | ||
|
||
# Verify that the domain was skipped | ||
assert_match /No related nameservers for this domain/, log_output.string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you've overcomplicated the test a bit. If you look at the file app/jobs/validate_dnssec_job.rb, the dns key object has a field called validation_datetime, which gets updated when the validation is successful. You could’ve used that for the check.
Of course, if the goal is to verify the logs, then tracking logs makes sense too. But what's really important here is that the job didn’t make any changes to the database record.
We actually need two clear tests:
One test that confirms the table was updated when a nameserver is present.
And this current test should prove that validation was skipped, meaning no changes happened in the table at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Rewrote test logic.
end | ||
|
||
def perform_without_domain_name_executes_else_block | ||
# Use existing domain fixture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed!
# Use existing domain fixture | ||
domain = domains(:shop) | ||
|
||
# Add DNSKEY if not present |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can rewrite this part more like "ruby-style":
domain.dnskeys << @dnskey unless domain.dnskeys.any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out. Rewrote the code.
|
||
ValidateDnssecJob.perform_now() | ||
|
||
assert true, "Job finished without errors" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not quite sure I understand the point of this test. What happens if there’s no nameserver — does it still complete without errors? What exactly is the success criteria here? Just checking that the job runs?
What we really need is to confirm that the job actually did its job — meaning the data we expect to change has actually changed (or hasn’t, depending on the case).
I know the job we’re testing includes exception handling, but those should have their own separate tests. Here, the main check should be whether the expected data changes happened — that's the real sign the job worked correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrote those two tests a bit clearer.
) | ||
end | ||
|
||
ValidateDnssecJob.perform_now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the parentheses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read my feedback, if you have some question, you can contact with me
Thank you for really valuable feedback! |
No description provided.