Skip to content

hack/tests,test/e2e: separate testing and scaffolding of E2E te… #1586

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

Merged
merged 15 commits into from
Jun 28, 2019

Conversation

AlexNPavel
Copy link
Contributor

Description of the change: Separate the scaffolding and testing sections of the Golang E2E tests. This change allows us to directly use operator-sdk test local to run the tests directly from a properly scaffolding memcached-operator project.

Motivation for the change: It makes the code cleaner, less hacky, and designed in a way that users can copy our tests directly into the example memcached-operator project without modifications.

At the moment, this means that our go files for testing now have tmpl extensions. To develop with tools, you should use the e2e-go-scaffold.sh script, do you development in the generated project, and then copy back the modified test files into the sdk. This also means that we won't have highlighting in GitHub. We need to keep it like this for now however, as the project refers to github.com/example-inc/memcached-operator, which does not exist and would cause dep ensure and IDE tools to fail. We will be able to fix this once the go mod migration of the SDK is completed: #1566

@AlexNPavel AlexNPavel added area/testing Issue related to testing the operator-sdk and subcomponents refactoring labels Jun 22, 2019
@openshift-ci-robot openshift-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jun 22, 2019
Copy link
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 Jun 24, 2019
@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 24, 2019
@AlexNPavel
Copy link
Contributor Author

/hold
Looks like I messed up a rebase and some of Joe's changes to the E2E test disappeared. Fixing now

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 24, 2019
@AlexNPavel
Copy link
Contributor Author

/hold cancel
Github stores branches that previously existed but were force pushed to, so it was a simple copy paste fix 🙌

@openshift-ci-robot openshift-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jun 24, 2019
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 25, 2019
Copy link
Member

@lilic lilic left a comment

Choose a reason for hiding this comment

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

Overall lgtm, tested it locally and it works on mac OSX as well 👍


import (
"bytes"
goctx "context"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Any reason for this rename?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have it renamed as goctx in all of our documentation and sample code for the test framework, so this makes it more consistent. It makes it easier to differentiate between the TestCtx from the framework and context from golang.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 2019
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 28, 2019
mkdir -p $BASEPROJECTDIR

pushd "$BASEPROJECTDIR"
go run "$ROOTDIR/hack/tests/scaffolding/scaffold-memcached.go" --local-repo $ROOTDIR --image-name=$IMAGE_NAME --local-image
Copy link
Member

Choose a reason for hiding this comment

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

Not a huge deal, since I could fix this in the go-mod PR, but go run doesn't work well when running from a directory outside the module where the go file being run is.

I solved this in the go-mod PR by running go build before switching to the $BASEPROJECTDIR directory, and then just running the executable after switching.

Copy link
Member

Choose a reason for hiding this comment

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

Ehh.. maybe don't worry about this, as there will be other things to fix anyway.

Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

A few nits, questions, and suggestions, but looks good overall.

Do we have developer docs about CI and testing that will need to be updated?

return nil, errors.Wrap(err, "failed to write go.mod before replacing SDK repo")
}
return modBytes, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Most of this go program is running CLI commands and other things that would be much simpler in bash. Would it make sense to port it to bash and incorporate it into e2e-go-scaffold.sh?

Probably not something to do in this PR, but maybe something to consider for a TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add that as a TODO

tmplFiles := map[string]string{
filepath.Join(localSDKPath, "example/memcached-operator/memcached_controller.go.tmpl"): "pkg/controller/memcached/memcached_controller.go",
filepath.Join(localSDKPath, "test/e2e/_incluster-test-code/main_test.go"): "test/e2e/main_test.go",
filepath.Join(localSDKPath, "test/e2e/_incluster-test-code/memcached_test.go"): "test/e2e/memcached_test.go",
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason for prefixing the incluster-test-code package name with an underscore? Does that hint to the go toolchain to ignore it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, underscores tell the go toolchain (tools like go vet and go mod) to ignore that directory (or file), which we need to do since we are importing a non-existent project. This wasn't a problem before because we had the .tmpl file extension, but that makes the files much more difficult to work on and review since that removes the code highlighting, which is more important now that this is our main test file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to do the same with example/memcached-operator/memcached_controller.go.tmpl? i.e example/_memcached-operator/memcached_controller.go.

It would be so much better to look at with syntax highlighting especially since we link to it in our README.

Copy link
Contributor

@hasbro17 hasbro17 left a comment

Choose a reason for hiding this comment

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

LGTM after nits.

@AlexNPavel
Copy link
Contributor Author

@joelanford I looked at the docs, and it looks like we don't actually describe how we scaffold the project, so the docs are still mostly accurate. They are missing the metrics tests, but I feel like that should be a separate PR, since it's not directly related to the changes here.

@AlexNPavel AlexNPavel changed the title hack/tests,test/e2e: separate testing and scaffolding of E2E tests hack/tests,test/e2e: separate testing and scaffolding of E2E te… Jun 28, 2019
@AlexNPavel AlexNPavel merged commit 4d7b853 into operator-framework:master Jun 28, 2019
@AlexNPavel AlexNPavel deleted the go-e2e-refactor branch June 28, 2019 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing Issue related to testing the operator-sdk and subcomponents size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants