Use test specific build dir when needed
If a FixtureFactory was created with a nil buildDirSupplier then this change will cause it to create a test specific directory instead. This will allow packages whose tests have been fully converted to the test fixture model to remove the need for the package level buildDir variable. Bug: 182885307 Test: m nothing Change-Id: Ifa70acadbd90356fadbe39675bac3214d925aa2f
This commit is contained in:
parent
567465da8c
commit
dff5ff064e
1 changed files with 12 additions and 2 deletions
|
@ -221,7 +221,8 @@ type FixtureFactory interface {
|
||||||
//
|
//
|
||||||
// The buildDirSupplier is a pointer to the package level buildDir variable that is initialized by
|
// The buildDirSupplier is a pointer to the package level buildDir variable that is initialized by
|
||||||
// the package level setUp method. It has to be a pointer to the variable as the variable will not
|
// the package level setUp method. It has to be a pointer to the variable as the variable will not
|
||||||
// have been initialized at the time the factory is created.
|
// have been initialized at the time the factory is created. If it is nil then a test specific
|
||||||
|
// temporary directory will be created instead.
|
||||||
func NewFixtureFactory(buildDirSupplier *string, preparers ...FixturePreparer) FixtureFactory {
|
func NewFixtureFactory(buildDirSupplier *string, preparers ...FixturePreparer) FixtureFactory {
|
||||||
return &fixtureFactory{
|
return &fixtureFactory{
|
||||||
buildDirSupplier: buildDirSupplier,
|
buildDirSupplier: buildDirSupplier,
|
||||||
|
@ -585,7 +586,16 @@ func (f *fixtureFactory) Extend(preparers ...FixturePreparer) FixtureFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *fixtureFactory) Fixture(t *testing.T, preparers ...FixturePreparer) Fixture {
|
func (f *fixtureFactory) Fixture(t *testing.T, preparers ...FixturePreparer) Fixture {
|
||||||
config := TestConfig(*f.buildDirSupplier, nil, "", nil)
|
var buildDir string
|
||||||
|
if f.buildDirSupplier == nil {
|
||||||
|
// Create a new temporary directory for this run. It will be automatically cleaned up when the
|
||||||
|
// test finishes.
|
||||||
|
buildDir = t.TempDir()
|
||||||
|
} else {
|
||||||
|
// Retrieve the buildDir from the supplier.
|
||||||
|
buildDir = *f.buildDirSupplier
|
||||||
|
}
|
||||||
|
config := TestConfig(buildDir, nil, "", nil)
|
||||||
ctx := NewTestContext(config)
|
ctx := NewTestContext(config)
|
||||||
fixture := &fixture{
|
fixture := &fixture{
|
||||||
factory: f,
|
factory: f,
|
||||||
|
|
Loading…
Reference in a new issue