blob: d4d196774f19afff7ccd8d0499e35b51761263ee [file] [log] [blame]
Bob Badour9ee7d032021-10-25 16:51:48 -07001// Copyright 2021 Google LLC
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
15package compliance
16
17import (
18 "bytes"
19 "testing"
20)
21
22func TestResolveSourcePrivacy(t *testing.T) {
23 tests := []struct {
24 name string
25 roots []string
26 edges []annotated
27 expectedResolutions []res
28 }{
29 {
30 name: "firstparty",
31 roots: []string{"apacheBin.meta_lic"},
32 edges: []annotated{
33 {"apacheBin.meta_lic", "apacheLib.meta_lic", []string{"static"}},
34 },
35 expectedResolutions: []res{},
36 },
37 {
38 name: "notice",
39 roots: []string{"mitBin.meta_lic"},
40 edges: []annotated{
41 {"mitBin.meta_lic", "mitLib.meta_lic", []string{"static"}},
42 },
43 expectedResolutions: []res{},
44 },
45 {
46 name: "lgpl",
47 roots: []string{"lgplBin.meta_lic"},
48 edges: []annotated{
49 {"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}},
50 },
51 expectedResolutions: []res{},
52 },
53 {
54 name: "proprietaryonresricted",
55 roots: []string{"proprietary.meta_lic"},
56 edges: []annotated{
57 {"proprietary.meta_lic", "gplLib.meta_lic", []string{"static"}},
58 },
59 expectedResolutions: []res{
Bob Badoura6ee6d52022-12-16 13:50:41 -080060 {"proprietary.meta_lic", "proprietary.meta_lic", "proprietary"},
Bob Badour9ee7d032021-10-25 16:51:48 -070061 },
62 },
63 {
64 name: "restrictedonproprietary",
65 roots: []string{"gplBin.meta_lic"},
66 edges: []annotated{
67 {"gplBin.meta_lic", "proprietary.meta_lic", []string{"static"}},
68 },
69 expectedResolutions: []res{
Bob Badoura6ee6d52022-12-16 13:50:41 -080070 {"gplBin.meta_lic", "proprietary.meta_lic", "proprietary"},
Bob Badour9ee7d032021-10-25 16:51:48 -070071 },
72 },
73 }
74 for _, tt := range tests {
75 t.Run(tt.name, func(t *testing.T) {
76 stderr := &bytes.Buffer{}
77 lg, err := toGraph(stderr, tt.roots, tt.edges)
78 if err != nil {
Colin Cross179ec3e2022-01-27 15:47:09 -080079 t.Errorf("unexpected test data error: got %s, want no error", err)
Bob Badour9ee7d032021-10-25 16:51:48 -070080 return
81 }
82 expectedRs := toResolutionSet(lg, tt.expectedResolutions)
83 actualRs := ResolveSourcePrivacy(lg)
Bob Badour103eb0f2022-01-10 13:50:57 -080084 checkResolves(actualRs, expectedRs, t)
Bob Badour9ee7d032021-10-25 16:51:48 -070085 })
86 }
87}