Skip to content

add unit tests for cmd/run#3413

Merged
estroz merged 1 commit intooperator-framework:masterfrom
jberkhahn:run_tests
Jul 17, 2020
Merged

add unit tests for cmd/run#3413
estroz merged 1 commit intooperator-framework:masterfrom
jberkhahn:run_tests

Conversation

@jberkhahn
Copy link
Copy Markdown
Contributor

Description of the change:
Add unit tests for the stuff that's staying in cmd/run. Includes a minor refactor to put the arg parsing into a validate method so it's testable, but omitting a separate PR as no functionality changed. Hope that's OK?

Also added a dir with a dummy project file to test the behavior where it's supposed to automatically set the manifest dir if a project file is present. I opted to put a real file on disk and include it in the repo as opposed to writing something temp from the code. Let me know if the other way would be preferable.

Motivation for the change:
As part of ongoing work for #3246

Copy link
Copy Markdown
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

.

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 16, 2020
Copy link
Copy Markdown
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

I am ok with it.
/lgtm

wdyt @jmrodri and @estroz?

Comment on lines +58 to +77
if len(args) > 0 {
if len(args) > 1 {
return fmt.Errorf("exactly one argument is required")
}
c.ManifestsDir = args[0]
} else {
c.ManifestsDir = "packagemanifests"
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should only be validating a packagemanifestsCmd, not setting fields

Suggested change
if len(args) > 0 {
if len(args) > 1 {
return fmt.Errorf("exactly one argument is required")
}
c.ManifestsDir = args[0]
} else {
c.ManifestsDir = "packagemanifests"
}
if len(args) != 0 && len(args) > 1 {
return fmt.Errorf("exactly one argument is required")
}

Set defaults in a function like

func (c *packagemanifestsCmd) setDefaults(args []string) {
	if len(args) != 0 {
		c.ManifestsDir = args[0]
	} else {
		c.ManifestsDir = "packagemanifests"
	}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was trying to keep it simple by have all the pre-parsing stuff happen in validate(), I can break it out into a separate method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

also, I might have to change it in some of the other parts, I think I stuck parsing into validate in some of the other refactors I did.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 16, 2020
@jberkhahn
Copy link
Copy Markdown
Contributor Author

changed it.

Copy link
Copy Markdown
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 17, 2020
@estroz estroz merged commit 612e02b into operator-framework:master Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants