Merge "Allow customization of all fixture state at once"
This commit is contained in:
@@ -252,6 +252,15 @@ func (fs MockFS) AddToFixture() FixturePreparer {
|
|||||||
return FixtureMergeMockFs(fs)
|
return FixtureMergeMockFs(fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FixtureCustomPreparer allows for the modification of any aspect of the fixture.
|
||||||
|
//
|
||||||
|
// This should only be used if one of the other more specific preparers are not suitable.
|
||||||
|
func FixtureCustomPreparer(mutator func(fixture Fixture)) FixturePreparer {
|
||||||
|
return newSimpleFixturePreparer(func(f *fixture) {
|
||||||
|
mutator(f)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Modify the config
|
// Modify the config
|
||||||
func FixtureModifyConfig(mutator func(config Config)) FixturePreparer {
|
func FixtureModifyConfig(mutator func(config Config)) FixturePreparer {
|
||||||
return newSimpleFixturePreparer(func(f *fixture) {
|
return newSimpleFixturePreparer(func(f *fixture) {
|
||||||
@@ -564,6 +573,15 @@ func FixtureCustomErrorHandler(function func(t *testing.T, result *TestResult))
|
|||||||
|
|
||||||
// Fixture defines the test environment.
|
// Fixture defines the test environment.
|
||||||
type Fixture interface {
|
type Fixture interface {
|
||||||
|
// Config returns the fixture's configuration.
|
||||||
|
Config() Config
|
||||||
|
|
||||||
|
// Context returns the fixture's test context.
|
||||||
|
Context() *TestContext
|
||||||
|
|
||||||
|
// MockFS returns the fixture's mock filesystem.
|
||||||
|
MockFS() MockFS
|
||||||
|
|
||||||
// Run the test, checking any errors reported and returning a TestResult instance.
|
// Run the test, checking any errors reported and returning a TestResult instance.
|
||||||
RunTest() *TestResult
|
RunTest() *TestResult
|
||||||
}
|
}
|
||||||
@@ -702,6 +720,18 @@ type fixture struct {
|
|||||||
errorHandler FixtureErrorHandler
|
errorHandler FixtureErrorHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *fixture) Config() Config {
|
||||||
|
return f.config
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fixture) Context() *TestContext {
|
||||||
|
return f.ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fixture) MockFS() MockFS {
|
||||||
|
return f.mockFS
|
||||||
|
}
|
||||||
|
|
||||||
func (f *fixture) RunTest() *TestResult {
|
func (f *fixture) RunTest() *TestResult {
|
||||||
f.t.Helper()
|
f.t.Helper()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user