Skip to content

pkg/ansible: Adding unit tests for the ansible operator reconcile loop #711

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

Conversation

shawn-hurley
Copy link
Member

Description of the change:
Adding unit tests and fakes to test the reconciliation loop of the ansible operator.

@shawn-hurley shawn-hurley added refactoring language/ansible Issue is related to an Ansible operator project labels Nov 6, 2018
@shawn-hurley shawn-hurley requested a review from mhrivnak November 6, 2018 15:28
@openshift-ci-robot openshift-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 6, 2018
@shawn-hurley shawn-hurley force-pushed the feature/reconcile-unit-test branch 4 times, most recently from 939461d to fd29031 Compare November 8, 2018 15:23
@shawn-hurley
Copy link
Member Author

@mhrivnak Can you take a look at the RunResult changes

I made RunResult an interface so that the fake runner could easily create a fake.RunResult. This would allow the user of the fake, to fake Stdout method, which was causing me issues in the test.

Copy link
Member

@mhrivnak mhrivnak left a comment

Choose a reason for hiding this comment

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

The change to an interface looks good to me. I just have some small things in the review.

m := map[string]interface{}{}
b, err := json.Marshal(status)
if err != nil {
return m
Copy link
Member

Choose a reason for hiding this comment

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

Is it ok to ignore the error here and just return an empty map?

Copy link
Member Author

Choose a reason for hiding this comment

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

as discussed offline adding a log and mentioning that it eats the error on the doc.

@@ -332,17 +332,27 @@ func (r *runner) makeParameters(u *unstructured.Unstructured) map[string]interfa
return parameters
}

type RunResult interface {
Stdout() (string, error)
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to move the comments from runResult.events and runResult.Stdout() to here so they'll show up in the documentation.

* Adding fakes for runner, and runner result.
* Updating status object to be ouput as a map for deep copy functions.
@shawn-hurley shawn-hurley force-pushed the feature/reconcile-unit-test branch from fd29031 to a68727c Compare November 19, 2018 19:39
@shawn-hurley shawn-hurley merged commit 4a9d5a5 into operator-framework:master Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language/ansible Issue is related to an Ansible operator project size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants