-
Notifications
You must be signed in to change notification settings - Fork 6
Upgrade test coverage from 24.6% to 94.12% #210
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
| end | ||
|
|
||
| def test_receive_data_with_invalid_data | ||
| stubs(:invalid_data?).returns(true) |
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 added a stub to the invalid_data? method so it always returns true. Then you send data that’s obviously invalid? What if I decide to send valid data here: will the test fail, or will it just claim my valid data is invalid too?
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.
Obviously this test would return same result despite sent data as it is focused on code behaviour in negative scenario. But for better handling test is now rewritten.
| assert_equal 0, @sent_data.length | ||
| end | ||
|
|
||
| def test_receive_data_full_flow |
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.
What exactly is this test checking? You’ve mocked so many methods that I can’t tell what we’re actually testing here.
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.
It was testing on positive scenario. It is rewritten: test_receive_data_returns_valid_whois_body
| mock_record.verify | ||
| end | ||
|
|
||
| def test_receive_data_integration_full_flow |
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.
And what are we testing in this one? Is it any different from the previous test, apart from the domain name?
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.
It was very similar. And now it is removed to reduce duplication.
| data = "\xFF\xFE".force_encoding('ASCII-8BIT') | ||
| ip = ['12345', '127.0.0.1'] | ||
|
|
||
| send(:process_whois_request, data, ip) |
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.
process_whois_request is a private method. It’s generally considered bad practice to test a private method directly, except in rare cases. You should prepare test data that triggers this method indirectly, so we can verify how it behaves through its effects. A private method is meant to be hidden, no one outside the class should know about it. It’s a black box.
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.
Testing private methods is removed.
| data = 'invalid..domain.ee' | ||
| ip = ['12345', '127.0.0.1'] | ||
|
|
||
| send(:process_whois_request, data, ip) |
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.
Same thing here. The issue was that when we ran code like printf 'täpiline.ee\r\n' | nc localhost 43, the WHOIS service would crash. That’s why we updated the process_whois_request method to add extra checks: specifically for cases when the invalid_data? method in the public scope doesn’t see anything suspicious.
Honestly, I’d slightly restructure and refactor this, but the problem is that if I move some of the logic from private methods up to a higher-level abstraction, for example, from process_whois_request into receive_data, the tests will start failing. And that’s exactly the point I’m making: you shouldn’t be testing private methods directly. Public methods should be the ones calling them as needed, depending on the data and conditions.
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.
All testing on focused for private methods have been removed.
| assert_includes @sent_data.first, 'Policy error' | ||
| end | ||
|
|
||
| def test_process_whois_request_with_valid_domain_found |
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.
what differents between this test and test_receive_data_full_flow?
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.
Duplication was a bit heavy in these tests. Now the duplication have been reduced by removing similar tests and rewritten test logic.
This PR improves test coverage and refactors the test suite for better maintainability by splitting a large test file into smaller, focused test files.
Changes
Test Coverage Improvements
unicode_validator_test.rbto improve coverage from 45.45% to 100%Test Structure Refactoring
test/whois_server_test.rb(449 lines, 70+ test methods) into three focused test files:test/unit/whois_server_core_test.rb- Domain validation and regexp tests (6 tests)test/unit/whois_server_methods_test.rb- Individual method tests (25 tests)test/integration/whois_server_integration_test.rb- Integration flow tests (13 tests)Configuration
test_helper.rbfor accurate coverage trackingTest Results