login1: add NewWithConnection and RebootWithContext methods
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 https://github.com/flatcar-linux/flatcar-linux-update-operator/pull/112.
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.
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.
I've created https://github.com/coreos/go-systemd/pull/395 and https://github.com/coreos/go-systemd/pull/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.