blob: ccfcaaa664f08dc823cf5a73919162553aee5c5c [file] [log] [blame]
Ronald Braunstein73b08ff2023-12-19 10:24:47 -08001// 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.
14package android
15
16import (
17 "testing"
18)
19
20type fakeModuleForTests struct {
21 ModuleBase
22}
23
24func fakeModuleFactory() Module {
25 module := &fakeModuleForTests{}
26 InitAndroidModule(module)
27 return module
28}
29
Ronald Braunsteinc5603092024-03-27 06:46:47 -070030var prepareForTestWithTeamAndFakeBuildComponents = GroupFixturePreparers(
31 FixtureRegisterWithContext(RegisterTeamBuildComponents),
32 FixtureRegisterWithContext(func(ctx RegistrationContext) {
33 ctx.RegisterModuleType("fake", fakeModuleFactory)
34 }),
35)
36
Ronald Braunstein73b08ff2023-12-19 10:24:47 -080037func (*fakeModuleForTests) GenerateAndroidBuildActions(ModuleContext) {}
38
39func TestTeam(t *testing.T) {
40 t.Parallel()
Ronald Braunsteinc5603092024-03-27 06:46:47 -070041 ctx := prepareForTestWithTeamAndFakeBuildComponents.
42 RunTestWithBp(t, `
Ronald Braunstein73b08ff2023-12-19 10:24:47 -080043 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
70func TestMissingTeamFails(t *testing.T) {
71 t.Parallel()
Ronald Braunsteinc5603092024-03-27 06:46:47 -070072 prepareForTestWithTeamAndFakeBuildComponents.
Ronald Braunstein73b08ff2023-12-19 10:24:47 -080073 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
82func TestPackageBadTeamNameFails(t *testing.T) {
83 t.Parallel()
84 GroupFixturePreparers(
85 PrepareForTestWithTeamBuildComponents,
86 PrepareForTestWithPackageModule,
Ronald Braunstein73b08ff2023-12-19 10:24:47 -080087 ).
88 ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern("depends on undefined module \"ring-bearer")).
89 RunTestWithBp(t, `
90 package {
91 default_team: "ring-bearer",
92 }
93 `)
94}