-
Notifications
You must be signed in to change notification settings - Fork 911
POC subtestWrapper #885
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
Closed
prestonvasquez
wants to merge
1
commit into
mongodb:master
from
prestonvasquez:GODRIVER-2310.addExampleTestWrapper
Closed
POC subtestWrapper #885
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,18 +37,19 @@ func TestDocumentationExamples(t *testing.T) { | |
|
||
db := client.Database("documentation_examples") | ||
|
||
documentation_examples.InsertExamples(t, db) | ||
documentation_examples.QueryToplevelFieldsExamples(t, db) | ||
documentation_examples.QueryEmbeddedDocumentsExamples(t, db) | ||
documentation_examples.QueryArraysExamples(t, db) | ||
documentation_examples.QueryArrayEmbeddedDocumentsExamples(t, db) | ||
documentation_examples.QueryNullMissingFieldsExamples(t, db) | ||
documentation_examples.ProjectionExamples(t, db) | ||
documentation_examples.UpdateExamples(t, db) | ||
documentation_examples.DeleteExamples(t, db) | ||
documentation_examples.RunCommandExamples(t, db) | ||
documentation_examples.IndexExamples(t, db) | ||
documentation_examples.StableAPIExamples() | ||
stw := newSubtestWrapper(t, db) | ||
stw.run("InsertExamples", documentation_examples.InsertExamples) | ||
stw.run("QueryToplevelFieldsExamples", documentation_examples.QueryToplevelFieldsExamples) | ||
stw.run("QueryEmbeddedDocumentsExamples", documentation_examples.QueryEmbeddedDocumentsExamples) | ||
stw.run("QueryArraysExamples", documentation_examples.QueryArraysExamples) | ||
stw.run("QueryArrayEmbeddedDocumentsExamples", documentation_examples.QueryArrayEmbeddedDocumentsExamples) | ||
stw.run("QueryNullMissingFieldssExamples", documentation_examples.QueryNullMissingFieldsExamples) | ||
stw.run("ProjectionExamples", documentation_examples.ProjectionExamples) | ||
stw.run("UpdateExamples", documentation_examples.UpdateExamples) | ||
stw.run("DeleteExamples", documentation_examples.DeleteExamples) | ||
stw.run("RunCommandExamples", documentation_examples.RunCommandExamples) | ||
stw.run("IndexExamples", documentation_examples.IndexExamples) | ||
stw.runEmpty("StableAPExamples", documentation_examples.StableAPIExamples) | ||
|
||
// Because it uses RunCommand with an apiVersion, the strict count example can only be | ||
// run on 5.0+ without auth. It also cannot be run on 6.0+ since the count command was | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also use an |
||
|
@@ -157,3 +158,29 @@ func createTopology(t *testing.T) *topology.Topology { | |
} | ||
return topo | ||
} | ||
|
||
// subtestWrapper maintains testing state for subtest operations | ||
type subtestWrapper struct { | ||
t *testing.T | ||
db *mongo.Database | ||
} | ||
|
||
func newSubtestWrapper(t *testing.T, db *mongo.Database) subtestWrapper { | ||
stw := new(subtestWrapper) | ||
stw.t = t | ||
stw.db = db | ||
return *stw | ||
} | ||
|
||
type subtest func(*testing.T, *mongo.Database) | ||
type subtestEmpty func() | ||
|
||
// run wraps a subtest using an `stw` object | ||
func (stw subtestWrapper) run(name string, st subtest) { | ||
stw.t.Run(name, func(t *testing.T) { st(stw.t, stw.db) }) | ||
} | ||
|
||
// runEmpty wraps a subtest without functional arguments from an `stw` object. | ||
func (stw subtestWrapper) runEmpty(name string, st subtestEmpty) { | ||
stw.t.Run(name, func(t *testing.T) { st() }) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
While I do enjoy the abstraction here, is the usage of
subtestWrapper
strictly necessary? What would you think about just making each of these an explicit subtest? As in:That might be more readable?
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.
The only real value of the wrapper is to avoid multi-line subtests but that's just cosmetic. I'm more than happy to do it this way.