-
Notifications
You must be signed in to change notification settings - Fork 650
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
intercept val
in driver_interpreter and remove capitals
#3654
Conversation
src/daemon/daemon_init_settings.cpp
Outdated
@@ -53,6 +53,7 @@ QString persistent_settings_filename() | |||
|
|||
QString driver_interpreter(QString val) | |||
{ | |||
val = val.toLower().remove("-"); |
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 also accepts something like HyPeR-----V
, right? Is that ok? I think we might need a regex format check on the input val first and then interpret.
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.
Is that ok?
Since hyper-v is the only hypervisor that contains dashes IIRC, it might be better to only apply toLower() to val
and then whenever there is a check for if (driver == "hyperv")
to also check for if (driver == "hyperv" || driver == "hyper-v")
. What do you think about this solution instead?
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 would like to add a third option 🙂 How about we do only toLower()
here and convert hyper-v to hyperv on the Windows platform?
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.
That could even be done in a separate PR, to avoid having to sync branches.
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.
Since hyper-v is the only hypervisor that contains dashes IIRC, it might be better to only apply toLower() to val and then whenever there is a check for if (driver == "hyperv") to also check for if (driver == "hyperv" || driver == "hyper-v"). What do you think about this solution instead?
This sounds good. One more hard-coded string is not that bad in this scenario.
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.
convert hyper-v to hyperv on the Windows platform?
Do you mean removing the first -
character from the input string via QString member function, and compare to hyperv
string? If that can be easily done via QString functions, this is also good.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3654 +/- ##
==========================================
- Coverage 88.89% 88.86% -0.04%
==========================================
Files 254 254
Lines 14251 14266 +15
==========================================
+ Hits 12668 12677 +9
- Misses 1583 1589 +6 ☔ View full report in Codecov by Sentry. |
e6054db
to
6754877
Compare
val
in driver_interpreter and remove capitals and dashesval
in driver_interpreter and remove capitals
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.
Thank you Lev, I haven't tested but this looks good to me. Fine with me if @georgeliao approves.
The only concern of mine is that we will accept all the partial upper case name cases like, |
Thanks @georgeliao. I think we can indeed accept that, since no ambiguity should ever come from it. @levkropp small detail inline if you want, then we can merge. Thanks! |
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.
Oh, tests missing. We missed Codecov before. This shouldn't be too hard: look for the tests that cover the surrounding code and it should be easy to replicate/generalize.
4696cf9
to
5b25bd9
Compare
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.
@levkropp
Thanks for the good work. I really like the patch 100% test coverage.
Functional testing was done on windows, it worked as expected.
Both the interpreter code and unit tests look good. I only had a few minor comments on unit tests for refinement.
@@ -267,6 +267,32 @@ TEST_F(TestGlobalSettingsHandlers, daemonRegistersHandlerThatAcceptsValidBackend | |||
ASSERT_NO_THROW(handler->set(key, val)); | |||
} | |||
|
|||
TEST_F(TestGlobalSettingsHandlers, daemonRegistersHandlerThatTransformsHyperVDriver) | |||
{ | |||
auto key = mp::driver_key, val = "hyper-v"; |
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.
Two minor things here:
First one is the multiple variables declaration in one line. I know we have other code doing this and the code here is correct, but this is not a good practice in general in terms of readability and error proneness. There is also a c++ core guideline item for this.
Second one is that const
can be added to the three to make these variables read only. That makes the result code:
const auto key = mp::driver_key;
const auto val = "hyper-v";
const auto transformed_val = "hyperv";
|
||
TEST_F(TestGlobalSettingsHandlers, daemonRegistersHandlerThatTransformsVBoxDriver) | ||
{ | ||
auto key = mp::driver_key, val = "vbox"; |
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.
Idem
|
||
mp::daemon::register_global_settings_handlers(); | ||
|
||
EXPECT_CALL(*mock_qsettings, setValue(Eq(key), Eq(transformed_val))); |
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.
Idem
|
||
mp::daemon::register_global_settings_handlers(); | ||
|
||
EXPECT_CALL(*mock_qsettings, setValue(Eq(key), Eq(transformed_val))); |
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.
Another minor thing.
Without specifying the called times, the default expected called number is at least once. Maybe we can make it more accurate by specifying times once since it is only called once. That makes
EXPECT_CALL(*mock_qsettings, setValue(Eq(key), Eq(transformed_val))).Times(1)
5b25bd9
to
ddf2fc9
Compare
close #3565