-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
hack/tests,test/e2e: separate testing and scaffolding of E2E te… #1586
Conversation
estroz
left a comment
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.
/lgtm
20d22e0 to
c500238
Compare
|
New changes are detected. LGTM label has been removed. |
|
/hold |
|
/hold cancel |
a1f3bf1 to
0fea55f
Compare
lilic
left a comment
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.
Overall lgtm, tested it locally and it works on mac OSX as well 👍
|
|
||
| import ( | ||
| "bytes" | ||
| goctx "context" |
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.
Nit: Any reason for this rename?
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.
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.
Co-Authored-By: Lili Cosic <cosiclili@gmail.com>
| mkdir -p $BASEPROJECTDIR | ||
|
|
||
| pushd "$BASEPROJECTDIR" | ||
| go run "$ROOTDIR/hack/tests/scaffolding/scaffold-memcached.go" --local-repo $ROOTDIR --image-name=$IMAGE_NAME --local-image |
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.
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.
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.
Ehh.. maybe don't worry about this, as there will be other things to fix anyway.
joelanford
left a comment
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.
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 | ||
| } |
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.
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?
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'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", |
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 there a reason for prefixing the incluster-test-code package name with an underscore? Does that hint to the go toolchain to ignore it?
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.
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.
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 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.
hasbro17
left a comment
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.
LGTM after nits.
Co-Authored-By: Haseeb Tariq <hasbro17@gmail.com>
|
@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. |
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 localto 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
tmplextensions. To develop with tools, you should use thee2e-go-scaffold.shscript, 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 togithub.com/example-inc/memcached-operator, which does not exist and would causedep ensureand IDE tools to fail. We will be able to fix this once thego modmigration of the SDK is completed: #1566