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 | |
Ronald Braunstein | c560309 | 2024-03-27 06:46:47 -0700 | [diff] [blame] | 30 | var prepareForTestWithTeamAndFakeBuildComponents = GroupFixturePreparers( |
| 31 | FixtureRegisterWithContext(RegisterTeamBuildComponents), |
| 32 | FixtureRegisterWithContext(func(ctx RegistrationContext) { |
| 33 | ctx.RegisterModuleType("fake", fakeModuleFactory) |
| 34 | }), |
| 35 | ) |
| 36 | |
Ronald Braunstein | 73b08ff | 2023-12-19 10:24:47 -0800 | [diff] [blame] | 37 | func (*fakeModuleForTests) GenerateAndroidBuildActions(ModuleContext) {} |
| 38 | |
| 39 | func TestTeam(t *testing.T) { |
| 40 | t.Parallel() |
Ronald Braunstein | c560309 | 2024-03-27 06:46:47 -0700 | [diff] [blame] | 41 | ctx := prepareForTestWithTeamAndFakeBuildComponents. |
| 42 | RunTestWithBp(t, ` |
Ronald Braunstein | 73b08ff | 2023-12-19 10:24:47 -0800 | [diff] [blame] | 43 | fake { |
| 44 | name: "main_test", |
| 45 | team: "someteam", |
| 46 | } |
| 47 | team { |
| 48 | name: "someteam", |
| 49 | trendy_team_id: "cool_team", |
| 50 | } |
| 51 | |
| 52 | team { |
| 53 | name: "team2", |
| 54 | trendy_team_id: "22222", |
| 55 | } |
| 56 | |
| 57 | fake { |
| 58 | name: "tool", |
| 59 | team: "team2", |
| 60 | } |
| 61 | `) |
| 62 | |
| 63 | // Assert the rule from GenerateAndroidBuildActions exists. |
| 64 | m := ctx.ModuleForTests("main_test", "") |
| 65 | AssertStringEquals(t, "msg", m.Module().base().Team(), "someteam") |
| 66 | m = ctx.ModuleForTests("tool", "") |
| 67 | AssertStringEquals(t, "msg", m.Module().base().Team(), "team2") |
| 68 | } |
| 69 | |
| 70 | func TestMissingTeamFails(t *testing.T) { |
| 71 | t.Parallel() |
Ronald Braunstein | c560309 | 2024-03-27 06:46:47 -0700 | [diff] [blame] | 72 | prepareForTestWithTeamAndFakeBuildComponents. |
Ronald Braunstein | 73b08ff | 2023-12-19 10:24:47 -0800 | [diff] [blame] | 73 | ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern("depends on undefined module \"ring-bearer")). |
| 74 | RunTestWithBp(t, ` |
| 75 | fake { |
| 76 | name: "you_cannot_pass", |
| 77 | team: "ring-bearer", |
| 78 | } |
| 79 | `) |
| 80 | } |
| 81 | |
| 82 | func TestPackageBadTeamNameFails(t *testing.T) { |
| 83 | t.Parallel() |
| 84 | GroupFixturePreparers( |
| 85 | PrepareForTestWithTeamBuildComponents, |
| 86 | PrepareForTestWithPackageModule, |
Ronald Braunstein | 73b08ff | 2023-12-19 10:24:47 -0800 | [diff] [blame] | 87 | ). |
| 88 | ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern("depends on undefined module \"ring-bearer")). |
| 89 | RunTestWithBp(t, ` |
| 90 | package { |
| 91 | default_team: "ring-bearer", |
| 92 | } |
| 93 | `) |
| 94 | } |