diff options
| author | 2021-03-15 15:42:40 +0000 | |
|---|---|---|
| committer | 2021-03-16 12:35:04 +0000 | |
| commit | dff5ff064ea5ffeae8420ac21f5a4a08a820145d (patch) | |
| tree | 5e33dfc6e5152005c25519ee6ef5b65a29405478 | |
| parent | 567465da8cf04b436e82be5c0f2fa46f0f2001aa (diff) | |
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
| -rw-r--r-- | android/fixture.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/android/fixture.go b/android/fixture.go index d8893f7d9..928967d8c 100644 --- a/android/fixture.go +++ b/android/fixture.go @@ -221,7 +221,8 @@ type FixtureFactory interface { // // 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 -// 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 { return &fixtureFactory{ buildDirSupplier: buildDirSupplier, @@ -585,7 +586,16 @@ func (f *fixtureFactory) Extend(preparers ...FixturePreparer) FixtureFactory { } 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) fixture := &fixture{ factory: f, |