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

login1: add NewWithConnection and RebootWithContext methods #390

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

invidian
Copy link

@invidian invidian commented Jan 10, 2022

This PR does some small improvements to login1 package, namely changes tests to use blackbox approach to avoid building up the tech debt by adding new tests without doing so in the first place.

Then adds NewWithConnection method together with tests as a new constructor to login1.Conn (#389), which allows re-using and mocking D-Bus connection so remaining method calls can be tested.

Finally, RebootWithContext method is added as an replacement and improved version of Reboot.

Closes #387
Closes #391

Submitted code is based on the work I've done in flatcar/flatcar-linux-update-operator#112.

@invidian invidian force-pushed the invidian/login1-reboot-tests-and-improvements branch from 0722452 to b3aa1e3 Compare January 10, 2022 10:05
@invidian invidian force-pushed the invidian/login1-reboot-tests-and-improvements branch from e187552 to 484c87e Compare January 10, 2022 10:36
1.12 is now EOL for almost 2 years: https://endoflife.date/go.

As a reference, supported Ubuntu versions use either 1.10 or 1.13:
https://packages.ubuntu.com/search?keywords=golang-go

So I think this bump is reasonable.

This is done to get access to stdlib methods like errors.Is and
formatting statement %w, which is de facto standard for handling errors
nowadays.

Closes coreos#391

Signed-off-by: Mateusz Gozdek <[email protected]>
This is a desired way of testing to avoid creating fragile test suites
and be able to refactor code without touching tests.

Signed-off-by: Mateusz Gozdek <[email protected]>
This method allows passing existing D-Bus connection, which allows to
re-use connection between clients and to mock D-Bus connection for
testing purposes.

Signed-off-by: Mateusz Gozdek <[email protected]>
Existing Reboot() method does not allow using context not inspecting
D-Bus call errors, which makes it difficult to debug and use.

This commit adds new RebootWithContext() method which addresses those
shortcomings.

Closes coreos#387

Signed-off-by: Mateusz Gozdek <[email protected]>
Copy link
Contributor

@lucab lucab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!
This is unfortunately becoming a kitchen sink, which isn't nice.
Let's only add RebootWithContext in here, everything else will be touched elsewhere.

@invidian
Copy link
Author

Hey, thanks for quick feedback. Would you like me to create one PR per commit from this PR then? Generally, I'd prefer to not submit code without tests, no matter how trivial it is, and changes here as the simplest steps to get things testable. Also, I'm concerned that "everything else" will not get enough attention once RebootWithContext is merged, so I'd prefer to focus on other bits first.

@lucab
Copy link
Contributor

lucab commented Jan 31, 2022

Generally speaking yes, I prefer handling separate PRs as they can easily travel at different speeds and merge at different times.
So I'd use this only to fix #387, which is indeed a very useful thing (and thanks again!).

Regarding testing, it usually goes in the same PR, agreed. In this case though it is both a large reworking and pretty much just formalized mocking. It effectively does not cover much juicy content, other than package-global constants and other static strings.
From a maintenance point of view, the increased ballast is not worth the price. Let's aggressively trim down this PR to just carry RebootWithContext.

@invidian
Copy link
Author

I've created #395 and #396 then, to split the changes and make them easier to review and merge.

For the time being solving #391 is not needed, I'll rework this PR once PRs above are merged, so it's not needed, so this one can be merged as well.

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.

Bump required Go version to 1.13 Provide error handling for Reboot() call
2 participants