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
Turn rpm-ostree code into a client #100
Turn rpm-ostree code into a client #100
Conversation
/hold I'd like to wait on merging things like this until after the current round of testing. |
I'm really excited about these PRs (and future unit testing). Thanks for getting this started! |
Deployment is also an @abhinavdahiya thoughts? |
Hmm yeah, I think that makes sense overall for the goal of unit testing. That said for upstream CI, hopefully we can get a real cluster going and test there?
Or maybe something like |
I'm 👍 to that. I'll make the change in a bit. |
Agreed, but that's a different set of work :-) |
0c98546
to
99484d7
Compare
Updated. |
pkg/daemon/rpm-ostree.go
Outdated
} | ||
|
||
// GetBootedDeployment returns the current deployment found | ||
func (r *RpmOstreeClient) GetBootedDeployment(rootMount string) (*RpmOstreeDeployment, error) { |
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 this function called by anything external to this package? I only see the one change. if not, I would probably advocate for removing it from the client interface and just having it as a method on RpmOstreeClient
.
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.
/cc @jlebon
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.
Yup, that sounds good to me!
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.
Updated.
f10d421
to
4732d45
Compare
This change allows for modification of rpm-ostree related code so unittesting can occur. Instead of the functionality being spread through private functions within the daemon package, a structure which implements NodeUpdaterClient is used and is passed in to the Daemon at creation. Signed-off-by: Steve Milner <smilner@redhat.com>
4732d45
to
f9f1c6f
Compare
Should test implementations be in the same file as the main implementation or should they be implemented within a |
Code looks sane to me!
I'll let folks more experienced with golang decide. |
FWIW my inclination is to put the test implementations in |
In terms of testing usage. This would look something like this (untested, uncompiled, but close :-)): testClient := RpmOstreeClientMock{
GetBootedOSImageURLReturns: []GetBootedOSImageURLReturn{
OsImageURL: "theurl",
Version: "some-version",
Error: nil,
}
RunPivotReturns: []error{nil, fmt.Errorf("broken")}
}
// Create an instance that uses the client
// Execute a method that calls GetBootedOSImageURL off the client. It will get the contents past to GetBootedOSImageURLReturns every time it is executed.
// Execute a method that calls RunPivot. The first time it will return no error. The second run and beyond will return an the "broken" error. |
/hold cancel |
f9f1c6f
to
bfc5b82
Compare
Signed-off-by: Steve Milner <smilner@redhat.com>
Signed-off-by: Steve Milner <smilner@redhat.com>
bfc5b82
to
ef2b688
Compare
} | ||
|
||
// Create a Daemon instance with mocked clients | ||
d := Daemon{ |
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 expect creating a test Daemon
instance would likely be added as well to keep many of the tests from recreating the instances each time.
Moved test code into |
@sdemos PTAL |
FWIW
|
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 all looks good to me. I'll let @jlebon give the final go-ahead since it hits on the rpm-ostree code.
just kidding, he is out today, I'll just do it. /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ashcrow, sdemos The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This change allows for modification of rpm-ostree related code so
unittesting can occur. Instead of the functionality being spread
through private functions within the daemon package, a structure
which implements DeploymentClient is used and is passed in to
the Daemon at creation.
Part of #101
/cc @jlebon @sdemos @kikisdeliveryservice