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
diff --git a/sdk/testing.go b/sdk/testing.go
index c319895..307b6de 100644
--- a/sdk/testing.go
+++ b/sdk/testing.go
@@ -200,13 +200,33 @@
// 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)