1*333d2b36SAndroid Build Coastguard Worker// Copyright 2024 Google Inc. All rights reserved. 2*333d2b36SAndroid Build Coastguard Worker// 3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*333d2b36SAndroid Build Coastguard Worker// 7*333d2b36SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 8*333d2b36SAndroid Build Coastguard Worker// 9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*333d2b36SAndroid Build Coastguard Worker// limitations under the License. 14*333d2b36SAndroid Build Coastguard Workerpackage android 15*333d2b36SAndroid Build Coastguard Worker 16*333d2b36SAndroid Build Coastguard Workerimport ( 17*333d2b36SAndroid Build Coastguard Worker "testing" 18*333d2b36SAndroid Build Coastguard Worker) 19*333d2b36SAndroid Build Coastguard Worker 20*333d2b36SAndroid Build Coastguard Workertype fakeModuleForTests struct { 21*333d2b36SAndroid Build Coastguard Worker ModuleBase 22*333d2b36SAndroid Build Coastguard Worker} 23*333d2b36SAndroid Build Coastguard Worker 24*333d2b36SAndroid Build Coastguard Workerfunc fakeModuleFactory() Module { 25*333d2b36SAndroid Build Coastguard Worker module := &fakeModuleForTests{} 26*333d2b36SAndroid Build Coastguard Worker InitAndroidModule(module) 27*333d2b36SAndroid Build Coastguard Worker return module 28*333d2b36SAndroid Build Coastguard Worker} 29*333d2b36SAndroid Build Coastguard Worker 30*333d2b36SAndroid Build Coastguard Workervar prepareForTestWithTeamAndFakeBuildComponents = GroupFixturePreparers( 31*333d2b36SAndroid Build Coastguard Worker FixtureRegisterWithContext(RegisterTeamBuildComponents), 32*333d2b36SAndroid Build Coastguard Worker FixtureRegisterWithContext(func(ctx RegistrationContext) { 33*333d2b36SAndroid Build Coastguard Worker ctx.RegisterModuleType("fake", fakeModuleFactory) 34*333d2b36SAndroid Build Coastguard Worker }), 35*333d2b36SAndroid Build Coastguard Worker) 36*333d2b36SAndroid Build Coastguard Worker 37*333d2b36SAndroid Build Coastguard Workerfunc (*fakeModuleForTests) GenerateAndroidBuildActions(ModuleContext) {} 38*333d2b36SAndroid Build Coastguard Worker 39*333d2b36SAndroid Build Coastguard Workerfunc TestTeam(t *testing.T) { 40*333d2b36SAndroid Build Coastguard Worker t.Parallel() 41*333d2b36SAndroid Build Coastguard Worker ctx := prepareForTestWithTeamAndFakeBuildComponents. 42*333d2b36SAndroid Build Coastguard Worker RunTestWithBp(t, ` 43*333d2b36SAndroid Build Coastguard Worker fake { 44*333d2b36SAndroid Build Coastguard Worker name: "main_test", 45*333d2b36SAndroid Build Coastguard Worker team: "someteam", 46*333d2b36SAndroid Build Coastguard Worker } 47*333d2b36SAndroid Build Coastguard Worker team { 48*333d2b36SAndroid Build Coastguard Worker name: "someteam", 49*333d2b36SAndroid Build Coastguard Worker trendy_team_id: "cool_team", 50*333d2b36SAndroid Build Coastguard Worker } 51*333d2b36SAndroid Build Coastguard Worker 52*333d2b36SAndroid Build Coastguard Worker team { 53*333d2b36SAndroid Build Coastguard Worker name: "team2", 54*333d2b36SAndroid Build Coastguard Worker trendy_team_id: "22222", 55*333d2b36SAndroid Build Coastguard Worker } 56*333d2b36SAndroid Build Coastguard Worker 57*333d2b36SAndroid Build Coastguard Worker fake { 58*333d2b36SAndroid Build Coastguard Worker name: "tool", 59*333d2b36SAndroid Build Coastguard Worker team: "team2", 60*333d2b36SAndroid Build Coastguard Worker } 61*333d2b36SAndroid Build Coastguard Worker `) 62*333d2b36SAndroid Build Coastguard Worker 63*333d2b36SAndroid Build Coastguard Worker // Assert the rule from GenerateAndroidBuildActions exists. 64*333d2b36SAndroid Build Coastguard Worker m := ctx.ModuleForTests("main_test", "") 65*333d2b36SAndroid Build Coastguard Worker AssertStringEquals(t, "msg", m.Module().base().Team(), "someteam") 66*333d2b36SAndroid Build Coastguard Worker m = ctx.ModuleForTests("tool", "") 67*333d2b36SAndroid Build Coastguard Worker AssertStringEquals(t, "msg", m.Module().base().Team(), "team2") 68*333d2b36SAndroid Build Coastguard Worker} 69*333d2b36SAndroid Build Coastguard Worker 70*333d2b36SAndroid Build Coastguard Workerfunc TestMissingTeamFails(t *testing.T) { 71*333d2b36SAndroid Build Coastguard Worker t.Parallel() 72*333d2b36SAndroid Build Coastguard Worker prepareForTestWithTeamAndFakeBuildComponents. 73*333d2b36SAndroid Build Coastguard Worker ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern("depends on undefined module \"ring-bearer")). 74*333d2b36SAndroid Build Coastguard Worker RunTestWithBp(t, ` 75*333d2b36SAndroid Build Coastguard Worker fake { 76*333d2b36SAndroid Build Coastguard Worker name: "you_cannot_pass", 77*333d2b36SAndroid Build Coastguard Worker team: "ring-bearer", 78*333d2b36SAndroid Build Coastguard Worker } 79*333d2b36SAndroid Build Coastguard Worker `) 80*333d2b36SAndroid Build Coastguard Worker} 81*333d2b36SAndroid Build Coastguard Worker 82*333d2b36SAndroid Build Coastguard Workerfunc TestPackageBadTeamNameFails(t *testing.T) { 83*333d2b36SAndroid Build Coastguard Worker t.Parallel() 84*333d2b36SAndroid Build Coastguard Worker GroupFixturePreparers( 85*333d2b36SAndroid Build Coastguard Worker PrepareForTestWithTeamBuildComponents, 86*333d2b36SAndroid Build Coastguard Worker PrepareForTestWithPackageModule, 87*333d2b36SAndroid Build Coastguard Worker ). 88*333d2b36SAndroid Build Coastguard Worker ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern("depends on undefined module \"ring-bearer")). 89*333d2b36SAndroid Build Coastguard Worker RunTestWithBp(t, ` 90*333d2b36SAndroid Build Coastguard Worker package { 91*333d2b36SAndroid Build Coastguard Worker default_team: "ring-bearer", 92*333d2b36SAndroid Build Coastguard Worker } 93*333d2b36SAndroid Build Coastguard Worker `) 94*333d2b36SAndroid Build Coastguard Worker} 95