refactor bp2build module allowlists into struct
To make testing easier, refactor existing module-global variables into a
struct that can be mocked.
Test: build/bazel/bp2build.go
Change-Id: I9d177677644ea743641a745b1839a3a8b29f902a
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index b21a477..0f3ca79 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -20,6 +20,7 @@
"testing"
"android/soong/android"
+ "android/soong/android/allowlists"
"android/soong/python"
)
@@ -922,7 +923,7 @@
moduleTypeUnderTestFactory android.ModuleFactory
expectedCount map[string]int
description string
- bp2buildConfig android.Bp2BuildConfig
+ bp2buildConfig allowlists.Bp2BuildConfig
checkDir string
fs map[string]string
}{
@@ -937,10 +938,10 @@
"not_migrated": 0,
"also_not_migrated": 0,
},
- bp2buildConfig: android.Bp2BuildConfig{
- "migrated": android.Bp2BuildDefaultTrueRecursively,
- "migrated/but_not_really": android.Bp2BuildDefaultFalse,
- "not_migrated": android.Bp2BuildDefaultFalse,
+ bp2buildConfig: allowlists.Bp2BuildConfig{
+ "migrated": allowlists.Bp2BuildDefaultTrueRecursively,
+ "migrated/but_not_really": allowlists.Bp2BuildDefaultFalse,
+ "not_migrated": allowlists.Bp2BuildDefaultFalse,
},
fs: map[string]string{
"migrated/Android.bp": `filegroup { name: "a" }`,
@@ -960,9 +961,9 @@
"package-opt-out": 1,
"package-opt-out/subpackage": 0,
},
- bp2buildConfig: android.Bp2BuildConfig{
- "package-opt-in": android.Bp2BuildDefaultFalse,
- "package-opt-out": android.Bp2BuildDefaultTrueRecursively,
+ bp2buildConfig: allowlists.Bp2BuildConfig{
+ "package-opt-in": allowlists.Bp2BuildDefaultFalse,
+ "package-opt-out": allowlists.Bp2BuildDefaultTrueRecursively,
},
fs: map[string]string{
"package-opt-in/Android.bp": `
@@ -1004,7 +1005,8 @@
config := android.TestConfig(buildDir, nil, "", fs)
ctx := android.NewTestContext(config)
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
- ctx.RegisterBp2BuildConfig(testCase.bp2buildConfig)
+ allowlist := android.NewBp2BuildAllowlist().SetDefaultConfig(testCase.bp2buildConfig)
+ ctx.RegisterBp2BuildConfig(allowlist)
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, toParse)