Add core of plugin test framework Stepwise #9166
Conversation
m1kola
left a comment
There was a problem hiding this comment.
I left few comments/suggestions inline, but I'm curious: Why do we want to have own testing framework with own types (Case, Steps, etc)? I think I see several issues the framework is going to solve, but I also fear that:
- It is going to be very limiting. For example, some plugins might need to perform actions on external systems between steps, etc.
- Because of the above, it will be tempting to add more features into the framework and it will increase maintanance costs. The fact that the package is going to be used externally adds more flavour into this.
- It is going to be a quite big piece for a very specific purpose which plugin authors will need to learn.
I'm wondering if an alternative approach where we are not trying to wrap Go's testing package with abstractions would be a better fit? I (vaguely at this stage) see it as collection of functions you can use inside of the Go's standard test. Something similar to gomock's approach where you call controller functions inside of a test:
func TestFoo(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
m := NewMockFoo(ctrl)
// Do something
}Apologies if I am bothering you with stupid suggestions. I'm not super familiar with the project and probably missing some background for this PR.
|
Hey @m1kola thanks for the review! I'll reply to your items in-line below.
Vault already has an existing testing framework that's the predecessor to this work in The primary goal(s) of this work here is to effectively overhaul or reintroduce it but utilize an actual instance of Vault instead of some of our Vault core test functions, and to avoid calling plugin methods directly through the plugin's
It may be limiting at times or in certain areas, yes. The framework is not envisioned as an end-all for plugin testing, but instead another tool available, and one that comes with the Vault SDK. We felt that a plugin testing framework that manages an external Vault instances, other external infrastructure, and the required coordination between them may be better suited to be a separate external tool/framework. While this framework does some of that and has limitations, we hope it to be a compromise. Hopefully you can agree!
The intent / design is meant for a specific use-case or style of tests, and as a result will likely not be the most robust framework possible. I'm hopeful we can keep the framework focused on that use-case and resist the temptation to add too much and increase the maintenance costs.
Plugin authors don’t have to learn this if they don’t choose to, but I agree that if they do there will be a learning curve. We feel this specific purpose is much needed in Vault and the Vault ecosystem and we certainly hope people will find it worthwhile to learn.
As I mentioned above, the framework has a specific use-case and so we're explicitly trying to be prescriptive in how to write or construct these tests.
Unfortunately I haven't yet invested the time to learn how to use
No apologies needed! The project was discussed and planned internally and unfortunately not shared with the community until this first PR. Hopefully it will make more sense as follow-up PRs land. Thanks again for the feedback and review! Cheers, |
pcman312
left a comment
There was a problem hiding this comment.
Looks great overall! Just some questions, suggestions for improvements, and some nits.
Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com>
Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com>
|
@catsby thanks for the clarifications. This is very helpful in learning more background for this PR and Vault in general. I understand that the idea is to provide a framework for a very specific use-case of tests, but I'm not convinced that there is a need to enforce such a strict structure (defining a
Thanks for this reference. I had a quick look at the testing framework from I'm looking at
@catsby @pcman312 what do you think? Is it worth exploring? If yes, as a starting point I can rewrite |
return `nil` and not `err` at the end Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com>
Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com>
Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com>
- StepOperation -> Operation - StepwiseEnvironment -> Environment - StepCheckFunc -> AssertionFunc - step.Check -> step.Assert
Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com>
|
Hey @m1kola - Thank you again for your continued feedback! Regarding adding complexity, we certainly don’t consider the framework “done” as of this PR, with more features, changes, and improvements planned in the near future. The focus will remain the same though: providing a prescriptive way to test a plugin through invoking the Vault API itself. I would agree with your sentiments on empowering plugin authors here if we intended or even envisioned I don’t mean to discourage your efforts to add or improve Vault or Vault plugin testing, I hope you don’t receive this reply in that way. There currently exists several internal testing functions and methods for wiring a plugin up with a Vault core (often a simulated one) such as TestCore or NewTestCluster in I want to reiterate that I don’t mean to discourage you from pursuing the ideas you have for improving plugin testing for Vault, quite the opposite! I would love to see and hear more on your ideas, but I want to be clear that they run contrary to the goals of the Thank you again for your input here! I hope this reply answers your questions, at least for now. Cheers, |
* Resolve merge conflicts and updates from running a test * move testing/_test.go over to legacy * updates * Add core of plugin test framework Stepwise (#9166) * adding stepwise testing, but there are protocol buff error :/ * move file and update sdk/go.mo * update/sync modules * update from other branch * update sdk/go.mod * some cleanups after feedback * remove enviornments from this PR * update vendor * change from running go mod tidy * change from go mod tidy * Update sdk/testing/stepwise/helpers.go Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * Update sdk/testing/stepwise/helpers.go Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * change panic to error * Update sdk/testing/stepwise/helpers.go return `nil` and not `err` at the end Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * Defer close() on successful Open of a file * document the re-creation of steps * Update sdk/testing/stepwise/stepwise.go Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * remove unused BarrierKeys() * Update sdk/testing/stepwise/stepwise.go Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * updates from feedback * fix return with bad arguments * Rename things: - StepOperation -> Operation - StepwiseEnvironment -> Environment - StepCheckFunc -> AssertionFunc - step.Check -> step.Assert * document the environment interface methods * rename EnvironmentOptions to MountOptions * rename Name to RegistryName * remove ExpectError because it's redundant * minor doc update * Update sdk/testing/stepwise/stepwise.go Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * add checkShouldRun function * remove redundant return * remove vestigial PreCheck function * add tt.Helper() to makeRequest * minor code formatting and document 1-based index for log output of Steps Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * minor updates * update sdk * use local reference for api, vault dep * Update sdk/testing/stepwise/stepwise.go Co-authored-by: Calvin Leung Huang <cleung2010@gmail.com> * Update sdk/testing/stepwise/stepwise.go Co-authored-by: Calvin Leung Huang <cleung2010@gmail.com> * cleanup some defer functions * call fatal if environment setup fails, and don't call teardown * defer re-setting client token in makeRequest * Move legacy logicaltest back to testhelpers * update mods and test files with go mod tidy * go mod vendor * remove relative replace directives * restore old logical test location * move declaration to main stepwise file * remove index var and use i+1 * add testing for write, delete paths of makeRequest * update stepwise core testing to do request counting * remove unused methods * Update sdk/testing/stepwise/stepwise.go remove dead line Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Update sdk/testing/stepwise/stepwise.go fix capitalization in code comment Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * update code comments for SkipTeardown to clarify its use * update stepwise Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> Co-authored-by: Calvin Leung Huang <cleung2010@gmail.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
* Resolve merge conflicts and updates from running a test * move testing/_test.go over to legacy * updates * Add core of plugin test framework Stepwise (#9166) * adding stepwise testing, but there are protocol buff error :/ * move file and update sdk/go.mo * update/sync modules * update from other branch * update sdk/go.mod * some cleanups after feedback * remove enviornments from this PR * update vendor * change from running go mod tidy * change from go mod tidy * Update sdk/testing/stepwise/helpers.go Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * Update sdk/testing/stepwise/helpers.go Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * change panic to error * Update sdk/testing/stepwise/helpers.go return `nil` and not `err` at the end Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * Defer close() on successful Open of a file * document the re-creation of steps * Update sdk/testing/stepwise/stepwise.go Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * remove unused BarrierKeys() * Update sdk/testing/stepwise/stepwise.go Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * updates from feedback * fix return with bad arguments * Rename things: - StepOperation -> Operation - StepwiseEnvironment -> Environment - StepCheckFunc -> AssertionFunc - step.Check -> step.Assert * document the environment interface methods * rename EnvironmentOptions to MountOptions * rename Name to RegistryName * remove ExpectError because it's redundant * minor doc update * Update sdk/testing/stepwise/stepwise.go Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * add checkShouldRun function * remove redundant return * remove vestigial PreCheck function * add tt.Helper() to makeRequest * minor code formatting and document 1-based index for log output of Steps Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> * minor updates * update sdk * use local reference for api, vault dep * Update sdk/testing/stepwise/stepwise.go Co-authored-by: Calvin Leung Huang <cleung2010@gmail.com> * Update sdk/testing/stepwise/stepwise.go Co-authored-by: Calvin Leung Huang <cleung2010@gmail.com> * cleanup some defer functions * call fatal if environment setup fails, and don't call teardown * defer re-setting client token in makeRequest * Move legacy logicaltest back to testhelpers * update mods and test files with go mod tidy * go mod vendor * remove relative replace directives * restore old logical test location * move declaration to main stepwise file * remove index var and use i+1 * add testing for write, delete paths of makeRequest * update stepwise core testing to do request counting * remove unused methods * Update sdk/testing/stepwise/stepwise.go remove dead line Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Update sdk/testing/stepwise/stepwise.go fix capitalization in code comment Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * update code comments for SkipTeardown to clarify its use * update stepwise Co-authored-by: Michael Golowka <72365+pcman312@users.noreply.github.com> Co-authored-by: Calvin Leung Huang <cleung2010@gmail.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
This is the start of implementing a new plugin testing framework codenamed
stepwise. The goal is to implement a testing framework comparable to (and to eventually replace) the existing "logicaltest" framework found inhelper/testhelpers/logical/testing.go, however using an actual, external, running instance of Vault. The canonical and first coming example would be using Docker to run Vault and run plugin tests against it.This PR introduces the basic types and interface to establish this framework, and the
Runmethod that executes the user defined steps, and some simple tests.This PR is currently in DRAFT form for early review and feedback.Update 2020-06-12: added some tests, removing "draft"