Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package compliance |
| 16 | |
| 17 | import ( |
| 18 | "bytes" |
| 19 | "testing" |
| 20 | ) |
| 21 | |
| 22 | func 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 Badour | a6ee6d5 | 2022-12-16 13:50:41 -0800 | [diff] [blame] | 60 | {"proprietary.meta_lic", "proprietary.meta_lic", "proprietary"}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 61 | }, |
| 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 Badour | a6ee6d5 | 2022-12-16 13:50:41 -0800 | [diff] [blame] | 70 | {"gplBin.meta_lic", "proprietary.meta_lic", "proprietary"}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 71 | }, |
| 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 Cross | 179ec3e | 2022-01-27 15:47:09 -0800 | [diff] [blame] | 79 | t.Errorf("unexpected test data error: got %s, want no error", err) |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 80 | return |
| 81 | } |
| 82 | expectedRs := toResolutionSet(lg, tt.expectedResolutions) |
| 83 | actualRs := ResolveSourcePrivacy(lg) |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 84 | checkResolves(actualRs, expectedRs, t) |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 85 | }) |
| 86 | } |
| 87 | } |