xref: /aosp_15_r20/build/soong/android/team_test.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
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.
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
30var prepareForTestWithTeamAndFakeBuildComponents = GroupFixturePreparers(
31	FixtureRegisterWithContext(RegisterTeamBuildComponents),
32	FixtureRegisterWithContext(func(ctx RegistrationContext) {
33		ctx.RegisterModuleType("fake", fakeModuleFactory)
34	}),
35)
36
37func (*fakeModuleForTests) GenerateAndroidBuildActions(ModuleContext) {}
38
39func TestTeam(t *testing.T) {
40	t.Parallel()
41	ctx := prepareForTestWithTeamAndFakeBuildComponents.
42		RunTestWithBp(t, `
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
70func TestMissingTeamFails(t *testing.T) {
71	t.Parallel()
72	prepareForTestWithTeamAndFakeBuildComponents.
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
82func TestPackageBadTeamNameFails(t *testing.T) {
83	t.Parallel()
84	GroupFixturePreparers(
85		PrepareForTestWithTeamBuildComponents,
86		PrepareForTestWithPackageModule,
87	).
88		ExtendWithErrorHandler(FixtureExpectsAtLeastOneErrorMatchingPattern("depends on undefined module \"ring-bearer")).
89		RunTestWithBp(t, `
90		package {
91			default_team: "ring-bearer",
92		}
93	`)
94}
95