xref: /aosp_15_r20/build/make/tools/compliance/policy_policy_test.go (revision 9e94795a3d4ef5c1d47486f9a02bb378756cea8a)
1*9e94795aSAndroid Build Coastguard Worker// Copyright 2021 Google LLC
2*9e94795aSAndroid Build Coastguard Worker//
3*9e94795aSAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*9e94795aSAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*9e94795aSAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*9e94795aSAndroid Build Coastguard Worker//
7*9e94795aSAndroid Build Coastguard Worker//      http://www.apache.org/licenses/LICENSE-2.0
8*9e94795aSAndroid Build Coastguard Worker//
9*9e94795aSAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*9e94795aSAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*9e94795aSAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*9e94795aSAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*9e94795aSAndroid Build Coastguard Worker// limitations under the License.
14*9e94795aSAndroid Build Coastguard Worker
15*9e94795aSAndroid Build Coastguard Workerpackage compliance
16*9e94795aSAndroid Build Coastguard Worker
17*9e94795aSAndroid Build Coastguard Workerimport (
18*9e94795aSAndroid Build Coastguard Worker	"bytes"
19*9e94795aSAndroid Build Coastguard Worker	"fmt"
20*9e94795aSAndroid Build Coastguard Worker	"sort"
21*9e94795aSAndroid Build Coastguard Worker	"strings"
22*9e94795aSAndroid Build Coastguard Worker	"testing"
23*9e94795aSAndroid Build Coastguard Worker
24*9e94795aSAndroid Build Coastguard Worker	"android/soong/tools/compliance/testfs"
25*9e94795aSAndroid Build Coastguard Worker)
26*9e94795aSAndroid Build Coastguard Worker
27*9e94795aSAndroid Build Coastguard Workerfunc TestPolicy_edgeConditions(t *testing.T) {
28*9e94795aSAndroid Build Coastguard Worker	tests := []struct {
29*9e94795aSAndroid Build Coastguard Worker		name                     string
30*9e94795aSAndroid Build Coastguard Worker		edge                     annotated
31*9e94795aSAndroid Build Coastguard Worker		treatAsAggregate         bool
32*9e94795aSAndroid Build Coastguard Worker		otherCondition           string
33*9e94795aSAndroid Build Coastguard Worker		expectedDepActions       []string
34*9e94795aSAndroid Build Coastguard Worker		expectedTargetConditions []string
35*9e94795aSAndroid Build Coastguard Worker	}{
36*9e94795aSAndroid Build Coastguard Worker		{
37*9e94795aSAndroid Build Coastguard Worker			name:                     "firstparty",
38*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"apacheBin.meta_lic", "apacheLib.meta_lic", []string{"static"}},
39*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
40*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
41*9e94795aSAndroid Build Coastguard Worker		},
42*9e94795aSAndroid Build Coastguard Worker		{
43*9e94795aSAndroid Build Coastguard Worker			name:                     "notice",
44*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"mitBin.meta_lic", "mitLib.meta_lic", []string{"static"}},
45*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
46*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
47*9e94795aSAndroid Build Coastguard Worker		},
48*9e94795aSAndroid Build Coastguard Worker		{
49*9e94795aSAndroid Build Coastguard Worker			name: "fponlgpl",
50*9e94795aSAndroid Build Coastguard Worker			edge: annotated{"apacheBin.meta_lic", "lgplLib.meta_lic", []string{"static"}},
51*9e94795aSAndroid Build Coastguard Worker			expectedDepActions: []string{
52*9e94795aSAndroid Build Coastguard Worker				"apacheBin.meta_lic:lgplLib.meta_lic:restricted_if_statically_linked",
53*9e94795aSAndroid Build Coastguard Worker				"lgplLib.meta_lic:lgplLib.meta_lic:restricted_if_statically_linked",
54*9e94795aSAndroid Build Coastguard Worker			},
55*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
56*9e94795aSAndroid Build Coastguard Worker		},
57*9e94795aSAndroid Build Coastguard Worker		{
58*9e94795aSAndroid Build Coastguard Worker			name:                     "fponlgpldynamic",
59*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"apacheBin.meta_lic", "lgplLib.meta_lic", []string{"dynamic"}},
60*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
61*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
62*9e94795aSAndroid Build Coastguard Worker		},
63*9e94795aSAndroid Build Coastguard Worker		{
64*9e94795aSAndroid Build Coastguard Worker			name: "fpongpl",
65*9e94795aSAndroid Build Coastguard Worker			edge: annotated{"apacheBin.meta_lic", "gplLib.meta_lic", []string{"static"}},
66*9e94795aSAndroid Build Coastguard Worker			expectedDepActions: []string{
67*9e94795aSAndroid Build Coastguard Worker				"apacheBin.meta_lic:gplLib.meta_lic:restricted",
68*9e94795aSAndroid Build Coastguard Worker				"gplLib.meta_lic:gplLib.meta_lic:restricted",
69*9e94795aSAndroid Build Coastguard Worker			},
70*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
71*9e94795aSAndroid Build Coastguard Worker		},
72*9e94795aSAndroid Build Coastguard Worker		{
73*9e94795aSAndroid Build Coastguard Worker			name: "fpongpldynamic",
74*9e94795aSAndroid Build Coastguard Worker			edge: annotated{"apacheBin.meta_lic", "gplLib.meta_lic", []string{"dynamic"}},
75*9e94795aSAndroid Build Coastguard Worker			expectedDepActions: []string{
76*9e94795aSAndroid Build Coastguard Worker				"apacheBin.meta_lic:gplLib.meta_lic:restricted",
77*9e94795aSAndroid Build Coastguard Worker				"gplLib.meta_lic:gplLib.meta_lic:restricted",
78*9e94795aSAndroid Build Coastguard Worker			},
79*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
80*9e94795aSAndroid Build Coastguard Worker		},
81*9e94795aSAndroid Build Coastguard Worker		{
82*9e94795aSAndroid Build Coastguard Worker			name:                     "independentmodule",
83*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}},
84*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
85*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
86*9e94795aSAndroid Build Coastguard Worker		},
87*9e94795aSAndroid Build Coastguard Worker		{
88*9e94795aSAndroid Build Coastguard Worker			name:                     "independentmodulestatic",
89*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"static"}},
90*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
91*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
92*9e94795aSAndroid Build Coastguard Worker		},
93*9e94795aSAndroid Build Coastguard Worker		{
94*9e94795aSAndroid Build Coastguard Worker			name:                     "dependentmodule",
95*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"dependentModule.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}},
96*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
97*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
98*9e94795aSAndroid Build Coastguard Worker		},
99*9e94795aSAndroid Build Coastguard Worker
100*9e94795aSAndroid Build Coastguard Worker		{
101*9e94795aSAndroid Build Coastguard Worker			name:                     "lgplonfp",
102*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}},
103*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
104*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{"lgplBin.meta_lic:restricted_if_statically_linked"},
105*9e94795aSAndroid Build Coastguard Worker		},
106*9e94795aSAndroid Build Coastguard Worker		{
107*9e94795aSAndroid Build Coastguard Worker			name:                     "lgplonfpdynamic",
108*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}},
109*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
110*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
111*9e94795aSAndroid Build Coastguard Worker		},
112*9e94795aSAndroid Build Coastguard Worker		{
113*9e94795aSAndroid Build Coastguard Worker			name:                     "gplonfp",
114*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"gplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}},
115*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
116*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{"gplBin.meta_lic:restricted"},
117*9e94795aSAndroid Build Coastguard Worker		},
118*9e94795aSAndroid Build Coastguard Worker		{
119*9e94795aSAndroid Build Coastguard Worker			name:                     "gplcontainer",
120*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"gplContainer.meta_lic", "apacheLib.meta_lic", []string{"static"}},
121*9e94795aSAndroid Build Coastguard Worker			treatAsAggregate:         true,
122*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
123*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{"gplContainer.meta_lic:restricted"},
124*9e94795aSAndroid Build Coastguard Worker		},
125*9e94795aSAndroid Build Coastguard Worker		{
126*9e94795aSAndroid Build Coastguard Worker			name:             "gploncontainer",
127*9e94795aSAndroid Build Coastguard Worker			edge:             annotated{"apacheContainer.meta_lic", "apacheLib.meta_lic", []string{"static"}},
128*9e94795aSAndroid Build Coastguard Worker			treatAsAggregate: true,
129*9e94795aSAndroid Build Coastguard Worker			otherCondition:   "gplLib.meta_lic:restricted",
130*9e94795aSAndroid Build Coastguard Worker			expectedDepActions: []string{
131*9e94795aSAndroid Build Coastguard Worker				"apacheContainer.meta_lic:gplLib.meta_lic:restricted",
132*9e94795aSAndroid Build Coastguard Worker				"apacheLib.meta_lic:gplLib.meta_lic:restricted",
133*9e94795aSAndroid Build Coastguard Worker				"gplLib.meta_lic:gplLib.meta_lic:restricted",
134*9e94795aSAndroid Build Coastguard Worker			},
135*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
136*9e94795aSAndroid Build Coastguard Worker		},
137*9e94795aSAndroid Build Coastguard Worker		{
138*9e94795aSAndroid Build Coastguard Worker			name:             "gplonbin",
139*9e94795aSAndroid Build Coastguard Worker			edge:             annotated{"apacheBin.meta_lic", "apacheLib.meta_lic", []string{"static"}},
140*9e94795aSAndroid Build Coastguard Worker			treatAsAggregate: false,
141*9e94795aSAndroid Build Coastguard Worker			otherCondition:   "gplLib.meta_lic:restricted",
142*9e94795aSAndroid Build Coastguard Worker			expectedDepActions: []string{
143*9e94795aSAndroid Build Coastguard Worker				"apacheBin.meta_lic:gplLib.meta_lic:restricted",
144*9e94795aSAndroid Build Coastguard Worker				"apacheLib.meta_lic:gplLib.meta_lic:restricted",
145*9e94795aSAndroid Build Coastguard Worker				"gplLib.meta_lic:gplLib.meta_lic:restricted",
146*9e94795aSAndroid Build Coastguard Worker			},
147*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{"gplLib.meta_lic:restricted"},
148*9e94795aSAndroid Build Coastguard Worker		},
149*9e94795aSAndroid Build Coastguard Worker		{
150*9e94795aSAndroid Build Coastguard Worker			name:                     "gplonfpdynamic",
151*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"gplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}},
152*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
153*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{"gplBin.meta_lic:restricted"},
154*9e94795aSAndroid Build Coastguard Worker		},
155*9e94795aSAndroid Build Coastguard Worker		{
156*9e94795aSAndroid Build Coastguard Worker			name:                     "independentmodulereverse",
157*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"dynamic"}},
158*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
159*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
160*9e94795aSAndroid Build Coastguard Worker		},
161*9e94795aSAndroid Build Coastguard Worker		{
162*9e94795aSAndroid Build Coastguard Worker			name:                     "independentmodulereversestatic",
163*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"static"}},
164*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
165*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
166*9e94795aSAndroid Build Coastguard Worker		},
167*9e94795aSAndroid Build Coastguard Worker		{
168*9e94795aSAndroid Build Coastguard Worker			name:                     "dependentmodulereverse",
169*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"gplWithClasspathException.meta_lic", "dependentModule.meta_lic", []string{"dynamic"}},
170*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
171*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
172*9e94795aSAndroid Build Coastguard Worker		},
173*9e94795aSAndroid Build Coastguard Worker		{
174*9e94795aSAndroid Build Coastguard Worker			name: "ponr",
175*9e94795aSAndroid Build Coastguard Worker			edge: annotated{"proprietary.meta_lic", "gplLib.meta_lic", []string{"static"}},
176*9e94795aSAndroid Build Coastguard Worker			expectedDepActions: []string{
177*9e94795aSAndroid Build Coastguard Worker				"proprietary.meta_lic:gplLib.meta_lic:restricted",
178*9e94795aSAndroid Build Coastguard Worker				"gplLib.meta_lic:gplLib.meta_lic:restricted",
179*9e94795aSAndroid Build Coastguard Worker			},
180*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
181*9e94795aSAndroid Build Coastguard Worker		},
182*9e94795aSAndroid Build Coastguard Worker		{
183*9e94795aSAndroid Build Coastguard Worker			name:                     "ronp",
184*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"gplBin.meta_lic", "proprietary.meta_lic", []string{"static"}},
185*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
186*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{"gplBin.meta_lic:restricted"},
187*9e94795aSAndroid Build Coastguard Worker		},
188*9e94795aSAndroid Build Coastguard Worker		{
189*9e94795aSAndroid Build Coastguard Worker			name:                     "noticeonb_e_o",
190*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"mitBin.meta_lic", "by_exception.meta_lic", []string{"static"}},
191*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
192*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
193*9e94795aSAndroid Build Coastguard Worker		},
194*9e94795aSAndroid Build Coastguard Worker		{
195*9e94795aSAndroid Build Coastguard Worker			name:                     "b_e_oonnotice",
196*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"by_exception.meta_lic", "mitLib.meta_lic", []string{"static"}},
197*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
198*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
199*9e94795aSAndroid Build Coastguard Worker		},
200*9e94795aSAndroid Build Coastguard Worker		{
201*9e94795aSAndroid Build Coastguard Worker			name:                     "noticeonrecip",
202*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"mitBin.meta_lic", "mplLib.meta_lic", []string{"static"}},
203*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
204*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
205*9e94795aSAndroid Build Coastguard Worker		},
206*9e94795aSAndroid Build Coastguard Worker		{
207*9e94795aSAndroid Build Coastguard Worker			name:                     "reciponnotice",
208*9e94795aSAndroid Build Coastguard Worker			edge:                     annotated{"mplBin.meta_lic", "mitLib.meta_lic", []string{"static"}},
209*9e94795aSAndroid Build Coastguard Worker			expectedDepActions:       []string{},
210*9e94795aSAndroid Build Coastguard Worker			expectedTargetConditions: []string{},
211*9e94795aSAndroid Build Coastguard Worker		},
212*9e94795aSAndroid Build Coastguard Worker	}
213*9e94795aSAndroid Build Coastguard Worker	for _, tt := range tests {
214*9e94795aSAndroid Build Coastguard Worker		t.Run(tt.name, func(t *testing.T) {
215*9e94795aSAndroid Build Coastguard Worker			fs := make(testfs.TestFS)
216*9e94795aSAndroid Build Coastguard Worker			stderr := &bytes.Buffer{}
217*9e94795aSAndroid Build Coastguard Worker			target := meta[tt.edge.target] + fmt.Sprintf("deps: {\n  file: \"%s\"\n", tt.edge.dep)
218*9e94795aSAndroid Build Coastguard Worker			for _, ann := range tt.edge.annotations {
219*9e94795aSAndroid Build Coastguard Worker				target += fmt.Sprintf("  annotations: \"%s\"\n", ann)
220*9e94795aSAndroid Build Coastguard Worker			}
221*9e94795aSAndroid Build Coastguard Worker			fs[tt.edge.target] = []byte(target + "}\n")
222*9e94795aSAndroid Build Coastguard Worker			fs[tt.edge.dep] = []byte(meta[tt.edge.dep])
223*9e94795aSAndroid Build Coastguard Worker			lg, err := ReadLicenseGraph(&fs, stderr, []string{tt.edge.target})
224*9e94795aSAndroid Build Coastguard Worker			if err != nil {
225*9e94795aSAndroid Build Coastguard Worker				t.Errorf("unexpected error reading graph: %s", err)
226*9e94795aSAndroid Build Coastguard Worker				return
227*9e94795aSAndroid Build Coastguard Worker			}
228*9e94795aSAndroid Build Coastguard Worker			edge := lg.Edges()[0]
229*9e94795aSAndroid Build Coastguard Worker			// simulate a condition inherited from another edge/dependency.
230*9e94795aSAndroid Build Coastguard Worker			otherTarget := ""
231*9e94795aSAndroid Build Coastguard Worker			otherCondition := ""
232*9e94795aSAndroid Build Coastguard Worker			var otn *TargetNode
233*9e94795aSAndroid Build Coastguard Worker			if len(tt.otherCondition) > 0 {
234*9e94795aSAndroid Build Coastguard Worker				fields := strings.Split(tt.otherCondition, ":")
235*9e94795aSAndroid Build Coastguard Worker				otherTarget = fields[0]
236*9e94795aSAndroid Build Coastguard Worker				otherCondition = fields[1]
237*9e94795aSAndroid Build Coastguard Worker				otn = &TargetNode{name: otherTarget}
238*9e94795aSAndroid Build Coastguard Worker				// other target must exist in graph
239*9e94795aSAndroid Build Coastguard Worker				lg.targets[otherTarget] = otn
240*9e94795aSAndroid Build Coastguard Worker				otn.licenseConditions = LicenseConditionSet(RecognizedConditionNames[otherCondition])
241*9e94795aSAndroid Build Coastguard Worker			}
242*9e94795aSAndroid Build Coastguard Worker			targets := make(map[string]*TargetNode)
243*9e94795aSAndroid Build Coastguard Worker			targets[edge.target.name] = edge.target
244*9e94795aSAndroid Build Coastguard Worker			targets[edge.dependency.name] = edge.dependency
245*9e94795aSAndroid Build Coastguard Worker			if otn != nil {
246*9e94795aSAndroid Build Coastguard Worker				targets[otn.name] = otn
247*9e94795aSAndroid Build Coastguard Worker			}
248*9e94795aSAndroid Build Coastguard Worker			if tt.expectedDepActions != nil {
249*9e94795aSAndroid Build Coastguard Worker				t.Run("depConditionsPropagatingToTarget", func(t *testing.T) {
250*9e94795aSAndroid Build Coastguard Worker					depConditions := edge.dependency.LicenseConditions()
251*9e94795aSAndroid Build Coastguard Worker					if otherTarget != "" {
252*9e94795aSAndroid Build Coastguard Worker						// simulate a sub-dependency's condition having already propagated up to dep and about to go to target
253*9e94795aSAndroid Build Coastguard Worker						otherCs := otn.LicenseConditions()
254*9e94795aSAndroid Build Coastguard Worker						depConditions |= otherCs
255*9e94795aSAndroid Build Coastguard Worker					}
256*9e94795aSAndroid Build Coastguard Worker					t.Logf("calculate target actions for edge=%s, dep conditions=%#v %s, treatAsAggregate=%v", edge.String(), depConditions, depConditions, tt.treatAsAggregate)
257*9e94795aSAndroid Build Coastguard Worker					csActual := depConditionsPropagatingToTarget(lg, edge, depConditions, tt.treatAsAggregate)
258*9e94795aSAndroid Build Coastguard Worker					t.Logf("calculated target conditions as %#v %s", csActual, csActual)
259*9e94795aSAndroid Build Coastguard Worker					csExpected := NewLicenseConditionSet()
260*9e94795aSAndroid Build Coastguard Worker					for _, triple := range tt.expectedDepActions {
261*9e94795aSAndroid Build Coastguard Worker						fields := strings.Split(triple, ":")
262*9e94795aSAndroid Build Coastguard Worker						expectedConditions := NewLicenseConditionSet()
263*9e94795aSAndroid Build Coastguard Worker						for _, cname := range fields[2:] {
264*9e94795aSAndroid Build Coastguard Worker							expectedConditions = expectedConditions.Plus(RecognizedConditionNames[cname])
265*9e94795aSAndroid Build Coastguard Worker						}
266*9e94795aSAndroid Build Coastguard Worker						csExpected |= expectedConditions
267*9e94795aSAndroid Build Coastguard Worker					}
268*9e94795aSAndroid Build Coastguard Worker					t.Logf("expected target conditions as %#v %s", csExpected, csExpected)
269*9e94795aSAndroid Build Coastguard Worker					if csActual != csExpected {
270*9e94795aSAndroid Build Coastguard Worker						t.Errorf("unexpected license conditions: got %#v, want %#v", csActual, csExpected)
271*9e94795aSAndroid Build Coastguard Worker					}
272*9e94795aSAndroid Build Coastguard Worker				})
273*9e94795aSAndroid Build Coastguard Worker			}
274*9e94795aSAndroid Build Coastguard Worker			if tt.expectedTargetConditions != nil {
275*9e94795aSAndroid Build Coastguard Worker				t.Run("targetConditionsPropagatingToDep", func(t *testing.T) {
276*9e94795aSAndroid Build Coastguard Worker					targetConditions := edge.target.LicenseConditions()
277*9e94795aSAndroid Build Coastguard Worker					if otherTarget != "" {
278*9e94795aSAndroid Build Coastguard Worker						targetConditions = targetConditions.Union(otn.licenseConditions)
279*9e94795aSAndroid Build Coastguard Worker					}
280*9e94795aSAndroid Build Coastguard Worker					t.Logf("calculate dep conditions for edge=%s, target conditions=%v, treatAsAggregate=%v", edge.String(), targetConditions.Names(), tt.treatAsAggregate)
281*9e94795aSAndroid Build Coastguard Worker					cs := targetConditionsPropagatingToDep(lg, edge, targetConditions, tt.treatAsAggregate, AllResolutions)
282*9e94795aSAndroid Build Coastguard Worker					t.Logf("calculated dep conditions as %v", cs.Names())
283*9e94795aSAndroid Build Coastguard Worker					actual := cs.Names()
284*9e94795aSAndroid Build Coastguard Worker					sort.Strings(actual)
285*9e94795aSAndroid Build Coastguard Worker					expected := make([]string, 0)
286*9e94795aSAndroid Build Coastguard Worker					for _, expectedDepCondition := range tt.expectedTargetConditions {
287*9e94795aSAndroid Build Coastguard Worker						expected = append(expected, strings.Split(expectedDepCondition, ":")[1])
288*9e94795aSAndroid Build Coastguard Worker					}
289*9e94795aSAndroid Build Coastguard Worker					sort.Strings(expected)
290*9e94795aSAndroid Build Coastguard Worker					if len(actual) != len(expected) {
291*9e94795aSAndroid Build Coastguard Worker						t.Errorf("unexpected number of target conditions: got %v with %d conditions, want %v with %d conditions",
292*9e94795aSAndroid Build Coastguard Worker							actual, len(actual), expected, len(expected))
293*9e94795aSAndroid Build Coastguard Worker					} else {
294*9e94795aSAndroid Build Coastguard Worker						for i := 0; i < len(actual); i++ {
295*9e94795aSAndroid Build Coastguard Worker							if actual[i] != expected[i] {
296*9e94795aSAndroid Build Coastguard Worker								t.Errorf("unexpected target condition at element %d: got %q, want %q",
297*9e94795aSAndroid Build Coastguard Worker									i, actual[i], expected[i])
298*9e94795aSAndroid Build Coastguard Worker							}
299*9e94795aSAndroid Build Coastguard Worker						}
300*9e94795aSAndroid Build Coastguard Worker					}
301*9e94795aSAndroid Build Coastguard Worker				})
302*9e94795aSAndroid Build Coastguard Worker			}
303*9e94795aSAndroid Build Coastguard Worker		})
304*9e94795aSAndroid Build Coastguard Worker	}
305*9e94795aSAndroid Build Coastguard Worker}
306