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

intercept val in driver_interpreter and remove capitals #3654

Merged
merged 3 commits into from
Sep 11, 2024

Conversation

levkropp
Copy link
Contributor

close #3565

@levkropp levkropp linked an issue Aug 30, 2024 that may be closed by this pull request
@@ -53,6 +53,7 @@ QString persistent_settings_filename()

QString driver_interpreter(QString val)
{
val = val.toLower().remove("-");
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link

codecov bot commented Aug 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.86%. Comparing base (a1df43d) to head (ddf2fc9).
Report is 19 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@levkropp levkropp force-pushed the local-driver-case-insensitivity branch from e6054db to 6754877 Compare August 30, 2024 15:45
@levkropp levkropp changed the title intercept val in driver_interpreter and remove capitals and dashes intercept val in driver_interpreter and remove capitals Aug 30, 2024
ricab
ricab previously approved these changes Sep 5, 2024
Copy link
Collaborator

@ricab ricab left a 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.

georgeliao
georgeliao previously approved these changes Sep 6, 2024
@georgeliao
Copy link
Contributor

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, hYPER-V, vBOx, virtUALBox, because we convert the whole word to lower cases. However, I think these names should be also acceptable.

@ricab
Copy link
Collaborator

ricab commented Sep 6, 2024

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!

@levkropp levkropp dismissed stale reviews from georgeliao and ricab via 4696cf9 September 6, 2024 10:44
Copy link
Collaborator

@ricab ricab left a 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.

@levkropp levkropp force-pushed the local-driver-case-insensitivity branch from 4696cf9 to 5b25bd9 Compare September 10, 2024 18:27
Copy link
Contributor

@georgeliao georgeliao left a 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";
Copy link
Contributor

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";
Copy link
Contributor

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)));
Copy link
Contributor

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)));
Copy link
Contributor

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)

@levkropp levkropp force-pushed the local-driver-case-insensitivity branch from 5b25bd9 to ddf2fc9 Compare September 11, 2024 12:04
@georgeliao georgeliao added this pull request to the merge queue Sep 11, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Sep 11, 2024
@georgeliao georgeliao added this pull request to the merge queue Sep 11, 2024
Merged via the queue into main with commit 04b3227 Sep 11, 2024
13 of 14 checks passed
@georgeliao georgeliao deleted the local-driver-case-insensitivity branch September 11, 2024 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accept local.driver values regardless of the case
3 participants