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