Use test fixtures in CheckSnapshot()
Using the preparer(s) that were used to run the test to verify the integrity of the generated snapshot ensures that it will be verified in the same environment as the snapshot was generated. This ensures that as sdk tests are migrated to use fixtures that are optimized for each test that they will benefit from those optimizations when checking the snapshot. Bug: 183184375 Test: m nothing Change-Id: I62b383f9a1d9a77d1cabb101d9d1e4a976170fe3
This commit is contained in:
@@ -200,13 +200,33 @@ func CheckSnapshot(t *testing.T, result *android.TestResult, name string, dir st
|
||||
|
||||
// Populate a mock filesystem with the files that would have been copied by
|
||||
// the rules.
|
||||
fs := make(map[string][]byte)
|
||||
fs := android.MockFS{}
|
||||
snapshotSubDir := "snapshot"
|
||||
for _, dest := range snapshotBuildInfo.snapshotContents {
|
||||
fs[dest] = nil
|
||||
fs[filepath.Join(snapshotSubDir, dest)] = nil
|
||||
}
|
||||
fs[filepath.Join(snapshotSubDir, "Android.bp")] = []byte(snapshotBuildInfo.androidBpContents)
|
||||
|
||||
// Process the generated bp file to make sure it is valid.
|
||||
testSdkWithFs(t, snapshotBuildInfo.androidBpContents, fs)
|
||||
preparer := result.Preparer()
|
||||
|
||||
// Process the generated bp file to make sure it is valid. Use the same preparer as was used to
|
||||
// produce this result.
|
||||
t.Run("snapshot without source", func(t *testing.T) {
|
||||
android.GroupFixturePreparers(
|
||||
preparer,
|
||||
// TODO(b/183184375): Set Config.TestAllowNonExistentPaths = false to verify that all the
|
||||
// files the snapshot needs are actually copied into the snapshot.
|
||||
|
||||
// Add the files (including bp) created for this snapshot to the test fixture.
|
||||
fs.AddToFixture(),
|
||||
|
||||
// Remove the source Android.bp file to make sure it works without.
|
||||
// TODO(b/183184375): Add a test with the source.
|
||||
android.FixtureModifyMockFS(func(fs android.MockFS) {
|
||||
delete(fs, "Android.bp")
|
||||
}),
|
||||
).RunTest(t)
|
||||
})
|
||||
}
|
||||
|
||||
type snapshotBuildInfoChecker func(info *snapshotBuildInfo)
|
||||
|
Reference in New Issue
Block a user