Use test fixtures in CheckSnapshot() am: c93c98e315

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1647191

Change-Id: I23a650f9689b41ad6fb060c0a4d8c8562f8a7134
This commit is contained in:
Paul Duffin
2021-03-22 23:00:51 +00:00
committed by Automerger Merge Worker

View File

@@ -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)