Make MockBazelContext more specific to cquerys

Rather than having a single storage container, make multiple so that it
is easier to unit test building modules with bazel with MockBazelContext

Test: go test genrule_test
Change-Id: I1da85d28f096d5102ad889b9518fdda6914342b1
This commit is contained in:
Liz Kammer 2021-04-07 20:25:21 -04:00
parent 76579e0e9a
commit a92e844d16
2 changed files with 12 additions and 9 deletions

View File

@ -117,21 +117,25 @@ var _ BazelContext = noopBazelContext{}
// A bazel context to use for tests.
type MockBazelContext struct {
AllFiles map[string][]string
OutputBaseDir string
LabelToOutputFiles map[string][]string
LabelToOutputFilesAndCcObjectFiles map[string]cquery.GetOutputFilesAndCcObjectFiles_Result
LabelToCcStaticLibraryFiles map[string][]string
}
func (m MockBazelContext) GetOutputFiles(label string, archType ArchType) ([]string, bool) {
result, ok := m.AllFiles[label]
result, ok := m.LabelToOutputFiles[label]
return result, ok
}
func (m MockBazelContext) GetOutputFilesAndCcObjectFiles(label string, archType ArchType) ([]string, []string, bool) {
result, ok := m.AllFiles[label]
return result, result, ok
result, ok := m.LabelToOutputFilesAndCcObjectFiles[label]
return result.OutputFiles, result.CcObjectFiles, ok
}
func (m MockBazelContext) GetPrebuiltCcStaticLibraryFiles(label string, archType ArchType) ([]string, bool) {
result, ok := m.AllFiles[label]
result, ok := m.LabelToCcStaticLibraryFiles[label]
return result, ok
}
@ -143,9 +147,7 @@ func (m MockBazelContext) BazelEnabled() bool {
return true
}
func (m MockBazelContext) OutputBase() string {
return "outputbase"
}
func (m MockBazelContext) OutputBase() string { return m.OutputBaseDir }
func (m MockBazelContext) BuildStatementsToRegister() []bazel.BuildStatement {
return []bazel.BuildStatement{}

View File

@ -696,7 +696,8 @@ func TestGenruleWithBazel(t *testing.T) {
result := android.GroupFixturePreparers(
prepareForGenRuleTest, android.FixtureModifyConfig(func(config android.Config) {
config.BazelContext = android.MockBazelContext{
AllFiles: map[string][]string{
OutputBaseDir: "outputbase",
LabelToOutputFiles: map[string][]string{
"//foo/bar:bar": []string{"bazelone.txt", "bazeltwo.txt"}}}
})).RunTestWithBp(t, testGenruleBp()+bp)