xref: /aosp_15_r20/build/make/tools/compliance/policy_resolveprivacy_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	"testing"
20*9e94795aSAndroid Build Coastguard Worker)
21*9e94795aSAndroid Build Coastguard Worker
22*9e94795aSAndroid Build Coastguard Workerfunc TestResolveSourcePrivacy(t *testing.T) {
23*9e94795aSAndroid Build Coastguard Worker	tests := []struct {
24*9e94795aSAndroid Build Coastguard Worker		name                string
25*9e94795aSAndroid Build Coastguard Worker		roots               []string
26*9e94795aSAndroid Build Coastguard Worker		edges               []annotated
27*9e94795aSAndroid Build Coastguard Worker		expectedResolutions []res
28*9e94795aSAndroid Build Coastguard Worker	}{
29*9e94795aSAndroid Build Coastguard Worker		{
30*9e94795aSAndroid Build Coastguard Worker			name:  "firstparty",
31*9e94795aSAndroid Build Coastguard Worker			roots: []string{"apacheBin.meta_lic"},
32*9e94795aSAndroid Build Coastguard Worker			edges: []annotated{
33*9e94795aSAndroid Build Coastguard Worker				{"apacheBin.meta_lic", "apacheLib.meta_lic", []string{"static"}},
34*9e94795aSAndroid Build Coastguard Worker			},
35*9e94795aSAndroid Build Coastguard Worker			expectedResolutions: []res{},
36*9e94795aSAndroid Build Coastguard Worker		},
37*9e94795aSAndroid Build Coastguard Worker		{
38*9e94795aSAndroid Build Coastguard Worker			name:  "notice",
39*9e94795aSAndroid Build Coastguard Worker			roots: []string{"mitBin.meta_lic"},
40*9e94795aSAndroid Build Coastguard Worker			edges: []annotated{
41*9e94795aSAndroid Build Coastguard Worker				{"mitBin.meta_lic", "mitLib.meta_lic", []string{"static"}},
42*9e94795aSAndroid Build Coastguard Worker			},
43*9e94795aSAndroid Build Coastguard Worker			expectedResolutions: []res{},
44*9e94795aSAndroid Build Coastguard Worker		},
45*9e94795aSAndroid Build Coastguard Worker		{
46*9e94795aSAndroid Build Coastguard Worker			name:  "lgpl",
47*9e94795aSAndroid Build Coastguard Worker			roots: []string{"lgplBin.meta_lic"},
48*9e94795aSAndroid Build Coastguard Worker			edges: []annotated{
49*9e94795aSAndroid Build Coastguard Worker				{"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}},
50*9e94795aSAndroid Build Coastguard Worker			},
51*9e94795aSAndroid Build Coastguard Worker			expectedResolutions: []res{},
52*9e94795aSAndroid Build Coastguard Worker		},
53*9e94795aSAndroid Build Coastguard Worker		{
54*9e94795aSAndroid Build Coastguard Worker			name:  "proprietaryonresricted",
55*9e94795aSAndroid Build Coastguard Worker			roots: []string{"proprietary.meta_lic"},
56*9e94795aSAndroid Build Coastguard Worker			edges: []annotated{
57*9e94795aSAndroid Build Coastguard Worker				{"proprietary.meta_lic", "gplLib.meta_lic", []string{"static"}},
58*9e94795aSAndroid Build Coastguard Worker			},
59*9e94795aSAndroid Build Coastguard Worker			expectedResolutions: []res{
60*9e94795aSAndroid Build Coastguard Worker				{"proprietary.meta_lic", "proprietary.meta_lic", "proprietary"},
61*9e94795aSAndroid Build Coastguard Worker			},
62*9e94795aSAndroid Build Coastguard Worker		},
63*9e94795aSAndroid Build Coastguard Worker		{
64*9e94795aSAndroid Build Coastguard Worker			name:  "restrictedonproprietary",
65*9e94795aSAndroid Build Coastguard Worker			roots: []string{"gplBin.meta_lic"},
66*9e94795aSAndroid Build Coastguard Worker			edges: []annotated{
67*9e94795aSAndroid Build Coastguard Worker				{"gplBin.meta_lic", "proprietary.meta_lic", []string{"static"}},
68*9e94795aSAndroid Build Coastguard Worker			},
69*9e94795aSAndroid Build Coastguard Worker			expectedResolutions: []res{
70*9e94795aSAndroid Build Coastguard Worker				{"gplBin.meta_lic", "proprietary.meta_lic", "proprietary"},
71*9e94795aSAndroid Build Coastguard Worker			},
72*9e94795aSAndroid Build Coastguard Worker		},
73*9e94795aSAndroid Build Coastguard Worker	}
74*9e94795aSAndroid Build Coastguard Worker	for _, tt := range tests {
75*9e94795aSAndroid Build Coastguard Worker		t.Run(tt.name, func(t *testing.T) {
76*9e94795aSAndroid Build Coastguard Worker			stderr := &bytes.Buffer{}
77*9e94795aSAndroid Build Coastguard Worker			lg, err := toGraph(stderr, tt.roots, tt.edges)
78*9e94795aSAndroid Build Coastguard Worker			if err != nil {
79*9e94795aSAndroid Build Coastguard Worker				t.Errorf("unexpected test data error: got %s, want no error", err)
80*9e94795aSAndroid Build Coastguard Worker				return
81*9e94795aSAndroid Build Coastguard Worker			}
82*9e94795aSAndroid Build Coastguard Worker			expectedRs := toResolutionSet(lg, tt.expectedResolutions)
83*9e94795aSAndroid Build Coastguard Worker			actualRs := ResolveSourcePrivacy(lg)
84*9e94795aSAndroid Build Coastguard Worker			checkResolves(actualRs, expectedRs, t)
85*9e94795aSAndroid Build Coastguard Worker		})
86*9e94795aSAndroid Build Coastguard Worker	}
87*9e94795aSAndroid Build Coastguard Worker}
88