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" |
Ibrahim Kanouche | e7c33de | 2022-09-22 18:17:41 +0000 | [diff] [blame^] | 19 | "fmt" |
| 20 | "os" |
| 21 | "strings" |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 22 | "testing" |
| 23 | ) |
| 24 | |
Ibrahim Kanouche | e7c33de | 2022-09-22 18:17:41 +0000 | [diff] [blame^] | 25 | func TestMain(m *testing.M) { |
| 26 | // Change into the cmd directory before running the tests |
| 27 | // so they can find the testdata directory. |
| 28 | if err := os.Chdir("cmd"); err != nil { |
| 29 | fmt.Printf("failed to change to testdata directory: %s\n", err) |
| 30 | os.Exit(1) |
| 31 | } |
| 32 | os.Exit(m.Run()) |
| 33 | } |
| 34 | |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 35 | func TestWalkResolutionsForCondition(t *testing.T) { |
| 36 | tests := []struct { |
| 37 | name string |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 38 | condition LicenseConditionSet |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 39 | roots []string |
| 40 | edges []annotated |
| 41 | expectedResolutions []res |
| 42 | }{ |
| 43 | { |
| 44 | name: "firstparty", |
| 45 | condition: ImpliesNotice, |
| 46 | roots: []string{"apacheBin.meta_lic"}, |
| 47 | edges: []annotated{ |
| 48 | {"apacheBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 49 | }, |
| 50 | expectedResolutions: []res{ |
| 51 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
| 52 | {"apacheBin.meta_lic", "apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 53 | }, |
| 54 | }, |
| 55 | { |
| 56 | name: "notice", |
| 57 | condition: ImpliesNotice, |
| 58 | roots: []string{"mitBin.meta_lic"}, |
| 59 | edges: []annotated{ |
| 60 | {"mitBin.meta_lic", "mitLib.meta_lic", []string{"static"}}, |
| 61 | }, |
| 62 | expectedResolutions: []res{ |
| 63 | {"mitBin.meta_lic", "mitBin.meta_lic", "mitBin.meta_lic", "notice"}, |
| 64 | {"mitBin.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"}, |
| 65 | }, |
| 66 | }, |
| 67 | { |
| 68 | name: "fponlgplnotice", |
| 69 | condition: ImpliesNotice, |
| 70 | roots: []string{"apacheBin.meta_lic"}, |
| 71 | edges: []annotated{ |
| 72 | {"apacheBin.meta_lic", "lgplLib.meta_lic", []string{"static"}}, |
| 73 | }, |
| 74 | expectedResolutions: []res{ |
| 75 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
| 76 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "lgplLib.meta_lic", "restricted"}, |
| 77 | {"apacheBin.meta_lic", "lgplLib.meta_lic", "lgplLib.meta_lic", "restricted"}, |
| 78 | }, |
| 79 | }, |
| 80 | { |
| 81 | name: "fponlgpldynamicnotice", |
| 82 | condition: ImpliesNotice, |
| 83 | roots: []string{"apacheBin.meta_lic"}, |
| 84 | edges: []annotated{ |
| 85 | {"apacheBin.meta_lic", "lgplLib.meta_lic", []string{"dynamic"}}, |
| 86 | }, |
| 87 | expectedResolutions: []res{ |
| 88 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
| 89 | }, |
| 90 | }, |
| 91 | { |
| 92 | name: "independentmodulenotice", |
| 93 | condition: ImpliesNotice, |
| 94 | roots: []string{"apacheBin.meta_lic"}, |
| 95 | edges: []annotated{ |
| 96 | {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}}, |
| 97 | }, |
| 98 | expectedResolutions: []res{ |
| 99 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
| 100 | }, |
| 101 | }, |
| 102 | { |
| 103 | name: "independentmodulerestricted", |
| 104 | condition: ImpliesRestricted, |
| 105 | roots: []string{"apacheBin.meta_lic"}, |
| 106 | edges: []annotated{ |
| 107 | {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}}, |
| 108 | }, |
| 109 | expectedResolutions: []res{}, |
| 110 | }, |
| 111 | { |
| 112 | name: "independentmodulestaticnotice", |
| 113 | condition: ImpliesNotice, |
| 114 | roots: []string{"apacheBin.meta_lic"}, |
| 115 | edges: []annotated{ |
| 116 | {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"static"}}, |
| 117 | }, |
| 118 | expectedResolutions: []res{ |
| 119 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 120 | {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "permissive"}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 121 | }, |
| 122 | }, |
| 123 | { |
| 124 | name: "independentmodulestaticrestricted", |
| 125 | condition: ImpliesRestricted, |
| 126 | roots: []string{"apacheBin.meta_lic"}, |
| 127 | edges: []annotated{ |
| 128 | {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"static"}}, |
| 129 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 130 | expectedResolutions: []res{}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 131 | }, |
| 132 | { |
| 133 | name: "dependentmodulenotice", |
| 134 | condition: ImpliesNotice, |
| 135 | roots: []string{"dependentModule.meta_lic"}, |
| 136 | edges: []annotated{ |
| 137 | {"dependentModule.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}}, |
| 138 | }, |
| 139 | expectedResolutions: []res{ |
| 140 | {"dependentModule.meta_lic", "dependentModule.meta_lic", "dependentModule.meta_lic", "notice"}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 141 | }, |
| 142 | }, |
| 143 | { |
| 144 | name: "dependentmodulerestricted", |
| 145 | condition: ImpliesRestricted, |
| 146 | roots: []string{"dependentModule.meta_lic"}, |
| 147 | edges: []annotated{ |
| 148 | {"dependentModule.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}}, |
| 149 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 150 | expectedResolutions: []res{}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 151 | }, |
| 152 | { |
| 153 | name: "lgplonfpnotice", |
| 154 | condition: ImpliesNotice, |
| 155 | roots: []string{"lgplBin.meta_lic"}, |
| 156 | edges: []annotated{ |
| 157 | {"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 158 | }, |
| 159 | expectedResolutions: []res{ |
| 160 | {"lgplBin.meta_lic", "lgplBin.meta_lic", "lgplBin.meta_lic", "restricted"}, |
| 161 | {"lgplBin.meta_lic", "apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 162 | {"lgplBin.meta_lic", "apacheLib.meta_lic", "lgplBin.meta_lic", "restricted"}, |
| 163 | }, |
| 164 | }, |
| 165 | { |
| 166 | name: "lgplonfprestricted", |
| 167 | condition: ImpliesRestricted, |
| 168 | roots: []string{"lgplBin.meta_lic"}, |
| 169 | edges: []annotated{ |
| 170 | {"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 171 | }, |
| 172 | expectedResolutions: []res{ |
| 173 | {"lgplBin.meta_lic", "lgplBin.meta_lic", "lgplBin.meta_lic", "restricted"}, |
| 174 | {"lgplBin.meta_lic", "apacheLib.meta_lic", "lgplBin.meta_lic", "restricted"}, |
| 175 | }, |
| 176 | }, |
| 177 | { |
| 178 | name: "lgplonfpdynamicnotice", |
| 179 | condition: ImpliesNotice, |
| 180 | roots: []string{"lgplBin.meta_lic"}, |
| 181 | edges: []annotated{ |
| 182 | {"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}}, |
| 183 | }, |
| 184 | expectedResolutions: []res{ |
| 185 | {"lgplBin.meta_lic", "lgplBin.meta_lic", "lgplBin.meta_lic", "restricted"}, |
| 186 | }, |
| 187 | }, |
| 188 | { |
| 189 | name: "lgplonfpdynamicrestricted", |
| 190 | condition: ImpliesRestricted, |
| 191 | roots: []string{"lgplBin.meta_lic"}, |
| 192 | edges: []annotated{ |
| 193 | {"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}}, |
| 194 | }, |
| 195 | expectedResolutions: []res{ |
| 196 | {"lgplBin.meta_lic", "lgplBin.meta_lic", "lgplBin.meta_lic", "restricted"}, |
| 197 | }, |
| 198 | }, |
| 199 | { |
| 200 | name: "gplonfpnotice", |
| 201 | condition: ImpliesNotice, |
| 202 | roots: []string{"gplBin.meta_lic"}, |
| 203 | edges: []annotated{ |
| 204 | {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 205 | }, |
| 206 | expectedResolutions: []res{ |
| 207 | {"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 208 | {"gplBin.meta_lic", "apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 209 | {"gplBin.meta_lic", "apacheLib.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 210 | }, |
| 211 | }, |
| 212 | { |
| 213 | name: "gplonfprestricted", |
| 214 | condition: ImpliesRestricted, |
| 215 | roots: []string{"gplBin.meta_lic"}, |
| 216 | edges: []annotated{ |
| 217 | {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 218 | }, |
| 219 | expectedResolutions: []res{ |
| 220 | {"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 221 | {"gplBin.meta_lic", "apacheLib.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 222 | }, |
| 223 | }, |
| 224 | { |
| 225 | name: "gplcontainernotice", |
| 226 | condition: ImpliesNotice, |
| 227 | roots: []string{"gplContainer.meta_lic"}, |
| 228 | edges: []annotated{ |
| 229 | {"gplContainer.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 230 | }, |
| 231 | expectedResolutions: []res{ |
| 232 | {"gplContainer.meta_lic", "gplContainer.meta_lic", "gplContainer.meta_lic", "restricted"}, |
| 233 | {"gplContainer.meta_lic", "apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 234 | {"gplContainer.meta_lic", "apacheLib.meta_lic", "gplContainer.meta_lic", "restricted"}, |
| 235 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 236 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "gplContainer.meta_lic", "restricted"}, |
| 237 | }, |
| 238 | }, |
| 239 | { |
| 240 | name: "gplcontainerrestricted", |
| 241 | condition: ImpliesRestricted, |
| 242 | roots: []string{"gplContainer.meta_lic"}, |
| 243 | edges: []annotated{ |
| 244 | {"gplContainer.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 245 | }, |
| 246 | expectedResolutions: []res{ |
| 247 | {"gplContainer.meta_lic", "gplContainer.meta_lic", "gplContainer.meta_lic", "restricted"}, |
| 248 | {"gplContainer.meta_lic", "apacheLib.meta_lic", "gplContainer.meta_lic", "restricted"}, |
| 249 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "gplContainer.meta_lic", "restricted"}, |
| 250 | }, |
| 251 | }, |
| 252 | { |
| 253 | name: "gploncontainernotice", |
| 254 | condition: ImpliesNotice, |
| 255 | roots: []string{"apacheContainer.meta_lic"}, |
| 256 | edges: []annotated{ |
| 257 | {"apacheContainer.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 258 | {"apacheContainer.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 259 | }, |
| 260 | expectedResolutions: []res{ |
| 261 | {"apacheContainer.meta_lic", "apacheContainer.meta_lic", "apacheContainer.meta_lic", "notice"}, |
| 262 | {"apacheContainer.meta_lic", "apacheContainer.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 263 | {"apacheContainer.meta_lic", "apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 264 | {"apacheContainer.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 265 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 266 | {"gplLib.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 267 | }, |
| 268 | }, |
| 269 | { |
| 270 | name: "gploncontainerrestricted", |
| 271 | condition: ImpliesRestricted, |
| 272 | roots: []string{"apacheContainer.meta_lic"}, |
| 273 | edges: []annotated{ |
| 274 | {"apacheContainer.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 275 | {"apacheContainer.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 276 | }, |
| 277 | expectedResolutions: []res{ |
| 278 | {"apacheContainer.meta_lic", "apacheContainer.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 279 | {"apacheContainer.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 280 | {"gplLib.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 281 | }, |
| 282 | }, |
| 283 | { |
| 284 | name: "gplonbinnotice", |
| 285 | condition: ImpliesNotice, |
| 286 | roots: []string{"apacheBin.meta_lic"}, |
| 287 | edges: []annotated{ |
| 288 | {"apacheBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 289 | {"apacheBin.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 290 | }, |
| 291 | expectedResolutions: []res{ |
| 292 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
| 293 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 294 | {"apacheBin.meta_lic", "apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 295 | {"apacheBin.meta_lic", "apacheLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 296 | {"apacheBin.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 297 | }, |
| 298 | }, |
| 299 | { |
| 300 | name: "gplonbinrestricted", |
| 301 | condition: ImpliesRestricted, |
| 302 | roots: []string{"apacheBin.meta_lic"}, |
| 303 | edges: []annotated{ |
| 304 | {"apacheBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 305 | {"apacheBin.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 306 | }, |
| 307 | expectedResolutions: []res{ |
| 308 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 309 | {"apacheBin.meta_lic", "apacheLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 310 | {"apacheBin.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 311 | }, |
| 312 | }, |
| 313 | { |
| 314 | name: "gplonfpdynamicnotice", |
| 315 | condition: ImpliesNotice, |
| 316 | roots: []string{"gplBin.meta_lic"}, |
| 317 | edges: []annotated{ |
| 318 | {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}}, |
| 319 | }, |
| 320 | expectedResolutions: []res{ |
| 321 | {"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 322 | }, |
| 323 | }, |
| 324 | { |
| 325 | name: "gplonfpdynamicrestricted", |
| 326 | condition: ImpliesRestricted, |
| 327 | roots: []string{"gplBin.meta_lic"}, |
| 328 | edges: []annotated{ |
| 329 | {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}}, |
| 330 | }, |
| 331 | expectedResolutions: []res{ |
| 332 | {"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 333 | }, |
| 334 | }, |
| 335 | { |
| 336 | name: "gplonfpdynamicrestrictedshipped", |
| 337 | condition: ImpliesRestricted, |
| 338 | roots: []string{"gplBin.meta_lic", "apacheLib.meta_lic"}, |
| 339 | edges: []annotated{ |
| 340 | {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}}, |
| 341 | }, |
| 342 | expectedResolutions: []res{ |
| 343 | {"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 344 | {"gplBin.meta_lic", "apacheLib.meta_lic", "gplBin.meta_lic", "restricted"}, |
Bob Badour | b285515 | 2021-12-08 12:52:59 -0800 | [diff] [blame] | 345 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "gplBin.meta_lic", "restricted"}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 346 | }, |
| 347 | }, |
| 348 | { |
| 349 | name: "independentmodulereversenotice", |
| 350 | condition: ImpliesNotice, |
| 351 | roots: []string{"gplWithClasspathException.meta_lic"}, |
| 352 | edges: []annotated{ |
| 353 | {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"dynamic"}}, |
| 354 | }, |
| 355 | expectedResolutions: []res{ |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 356 | {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "permissive"}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 357 | }, |
| 358 | }, |
| 359 | { |
| 360 | name: "independentmodulereverserestricted", |
| 361 | condition: ImpliesRestricted, |
| 362 | roots: []string{"gplWithClasspathException.meta_lic"}, |
| 363 | edges: []annotated{ |
| 364 | {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"dynamic"}}, |
| 365 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 366 | expectedResolutions: []res{}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 367 | }, |
| 368 | { |
| 369 | name: "independentmodulereverserestrictedshipped", |
| 370 | condition: ImpliesRestricted, |
| 371 | roots: []string{"gplWithClasspathException.meta_lic", "apacheBin.meta_lic"}, |
| 372 | edges: []annotated{ |
| 373 | {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"dynamic"}}, |
| 374 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 375 | expectedResolutions: []res{}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 376 | }, |
| 377 | { |
| 378 | name: "independentmodulereversestaticnotice", |
| 379 | condition: ImpliesNotice, |
| 380 | roots: []string{"gplWithClasspathException.meta_lic"}, |
| 381 | edges: []annotated{ |
| 382 | {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"static"}}, |
| 383 | }, |
| 384 | expectedResolutions: []res{ |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 385 | {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "permissive"}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 386 | {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 387 | }, |
| 388 | }, |
| 389 | { |
| 390 | name: "independentmodulereversestaticrestricted", |
| 391 | condition: ImpliesRestricted, |
| 392 | roots: []string{"gplWithClasspathException.meta_lic"}, |
| 393 | edges: []annotated{ |
| 394 | {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"static"}}, |
| 395 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 396 | expectedResolutions: []res{}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 397 | }, |
| 398 | { |
| 399 | name: "dependentmodulereversenotice", |
| 400 | condition: ImpliesNotice, |
| 401 | roots: []string{"gplWithClasspathException.meta_lic"}, |
| 402 | edges: []annotated{ |
| 403 | {"gplWithClasspathException.meta_lic", "dependentModule.meta_lic", []string{"dynamic"}}, |
| 404 | }, |
| 405 | expectedResolutions: []res{ |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 406 | {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "permissive"}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 407 | }, |
| 408 | }, |
| 409 | { |
| 410 | name: "dependentmodulereverserestricted", |
| 411 | condition: ImpliesRestricted, |
| 412 | roots: []string{"gplWithClasspathException.meta_lic"}, |
| 413 | edges: []annotated{ |
| 414 | {"gplWithClasspathException.meta_lic", "dependentModule.meta_lic", []string{"dynamic"}}, |
| 415 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 416 | expectedResolutions: []res{}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 417 | }, |
| 418 | { |
| 419 | name: "dependentmodulereverserestrictedshipped", |
| 420 | condition: ImpliesRestricted, |
| 421 | roots: []string{"gplWithClasspathException.meta_lic", "dependentModule.meta_lic"}, |
| 422 | edges: []annotated{ |
| 423 | {"gplWithClasspathException.meta_lic", "dependentModule.meta_lic", []string{"dynamic"}}, |
| 424 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 425 | expectedResolutions: []res{}, |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 426 | }, |
| 427 | { |
| 428 | name: "ponrnotice", |
| 429 | condition: ImpliesNotice, |
| 430 | roots: []string{"proprietary.meta_lic"}, |
| 431 | edges: []annotated{ |
| 432 | {"proprietary.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 433 | }, |
| 434 | expectedResolutions: []res{ |
| 435 | {"proprietary.meta_lic", "proprietary.meta_lic", "proprietary.meta_lic", "proprietary"}, |
| 436 | {"proprietary.meta_lic", "proprietary.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 437 | {"proprietary.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 438 | }, |
| 439 | }, |
| 440 | { |
| 441 | name: "ponrrestricted", |
| 442 | condition: ImpliesRestricted, |
| 443 | roots: []string{"proprietary.meta_lic"}, |
| 444 | edges: []annotated{ |
| 445 | {"proprietary.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 446 | }, |
| 447 | expectedResolutions: []res{ |
| 448 | {"proprietary.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 449 | {"proprietary.meta_lic", "proprietary.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 450 | }, |
| 451 | }, |
| 452 | { |
| 453 | name: "ponrproprietary", |
| 454 | condition: ImpliesProprietary, |
| 455 | roots: []string{"proprietary.meta_lic"}, |
| 456 | edges: []annotated{ |
| 457 | {"proprietary.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 458 | }, |
| 459 | expectedResolutions: []res{ |
| 460 | {"proprietary.meta_lic", "proprietary.meta_lic", "proprietary.meta_lic", "proprietary"}, |
| 461 | }, |
| 462 | }, |
| 463 | { |
| 464 | name: "ronpnotice", |
| 465 | condition: ImpliesNotice, |
| 466 | roots: []string{"gplBin.meta_lic"}, |
| 467 | edges: []annotated{ |
| 468 | {"gplBin.meta_lic", "proprietary.meta_lic", []string{"static"}}, |
| 469 | }, |
| 470 | expectedResolutions: []res{ |
| 471 | {"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 472 | {"gplBin.meta_lic", "proprietary.meta_lic", "proprietary.meta_lic", "proprietary"}, |
| 473 | {"gplBin.meta_lic", "proprietary.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 474 | }, |
| 475 | }, |
| 476 | { |
| 477 | name: "ronprestricted", |
| 478 | condition: ImpliesRestricted, |
| 479 | roots: []string{"gplBin.meta_lic"}, |
| 480 | edges: []annotated{ |
| 481 | {"gplBin.meta_lic", "proprietary.meta_lic", []string{"static"}}, |
| 482 | }, |
| 483 | expectedResolutions: []res{ |
| 484 | {"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 485 | {"gplBin.meta_lic", "proprietary.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 486 | }, |
| 487 | }, |
| 488 | { |
| 489 | name: "ronpproprietary", |
| 490 | condition: ImpliesProprietary, |
| 491 | roots: []string{"gplBin.meta_lic"}, |
| 492 | edges: []annotated{ |
| 493 | {"gplBin.meta_lic", "proprietary.meta_lic", []string{"static"}}, |
| 494 | }, |
| 495 | expectedResolutions: []res{ |
| 496 | {"gplBin.meta_lic", "proprietary.meta_lic", "proprietary.meta_lic", "proprietary"}, |
| 497 | }, |
| 498 | }, |
| 499 | { |
| 500 | name: "noticeonb_e_onotice", |
| 501 | condition: ImpliesNotice, |
| 502 | roots: []string{"mitBin.meta_lic"}, |
| 503 | edges: []annotated{ |
| 504 | {"mitBin.meta_lic", "by_exception.meta_lic", []string{"static"}}, |
| 505 | }, |
| 506 | expectedResolutions: []res{ |
| 507 | {"mitBin.meta_lic", "mitBin.meta_lic", "mitBin.meta_lic", "notice"}, |
| 508 | {"mitBin.meta_lic", "by_exception.meta_lic", "by_exception.meta_lic", "by_exception_only"}, |
| 509 | }, |
| 510 | }, |
| 511 | { |
| 512 | name: "noticeonb_e_orestricted", |
| 513 | condition: ImpliesRestricted, |
| 514 | roots: []string{"mitBin.meta_lic"}, |
| 515 | edges: []annotated{ |
| 516 | {"mitBin.meta_lic", "by_exception.meta_lic", []string{"static"}}, |
| 517 | }, |
| 518 | expectedResolutions: []res{}, |
| 519 | }, |
| 520 | { |
| 521 | name: "noticeonb_e_ob_e_o", |
| 522 | condition: ImpliesByExceptionOnly, |
| 523 | roots: []string{"mitBin.meta_lic"}, |
| 524 | edges: []annotated{ |
| 525 | {"mitBin.meta_lic", "by_exception.meta_lic", []string{"static"}}, |
| 526 | }, |
| 527 | expectedResolutions: []res{ |
| 528 | {"mitBin.meta_lic", "by_exception.meta_lic", "by_exception.meta_lic", "by_exception_only"}, |
| 529 | }, |
| 530 | }, |
| 531 | { |
| 532 | name: "b_e_oonnoticenotice", |
| 533 | condition: ImpliesNotice, |
| 534 | roots: []string{"by_exception.meta_lic"}, |
| 535 | edges: []annotated{ |
| 536 | {"by_exception.meta_lic", "mitLib.meta_lic", []string{"static"}}, |
| 537 | }, |
| 538 | expectedResolutions: []res{ |
| 539 | {"by_exception.meta_lic", "by_exception.meta_lic", "by_exception.meta_lic", "by_exception_only"}, |
| 540 | {"by_exception.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"}, |
| 541 | }, |
| 542 | }, |
| 543 | { |
| 544 | name: "b_e_oonnoticerestricted", |
| 545 | condition: ImpliesRestricted, |
| 546 | roots: []string{"by_exception.meta_lic"}, |
| 547 | edges: []annotated{ |
| 548 | {"by_exception.meta_lic", "mitLib.meta_lic", []string{"static"}}, |
| 549 | }, |
| 550 | expectedResolutions: []res{}, |
| 551 | }, |
| 552 | { |
| 553 | name: "b_e_oonnoticeb_e_o", |
| 554 | condition: ImpliesByExceptionOnly, |
| 555 | roots: []string{"by_exception.meta_lic"}, |
| 556 | edges: []annotated{ |
| 557 | {"by_exception.meta_lic", "mitLib.meta_lic", []string{"static"}}, |
| 558 | }, |
| 559 | expectedResolutions: []res{ |
| 560 | {"by_exception.meta_lic", "by_exception.meta_lic", "by_exception.meta_lic", "by_exception_only"}, |
| 561 | }, |
| 562 | }, |
| 563 | { |
| 564 | name: "noticeonrecipnotice", |
| 565 | condition: ImpliesNotice, |
| 566 | roots: []string{"mitBin.meta_lic"}, |
| 567 | edges: []annotated{ |
| 568 | {"mitBin.meta_lic", "mplLib.meta_lic", []string{"static"}}, |
| 569 | }, |
| 570 | expectedResolutions: []res{ |
| 571 | {"mitBin.meta_lic", "mitBin.meta_lic", "mitBin.meta_lic", "notice"}, |
| 572 | {"mitBin.meta_lic", "mplLib.meta_lic", "mplLib.meta_lic", "reciprocal"}, |
| 573 | }, |
| 574 | }, |
| 575 | { |
| 576 | name: "noticeonreciprecip", |
| 577 | condition: ImpliesReciprocal, |
| 578 | roots: []string{"mitBin.meta_lic"}, |
| 579 | edges: []annotated{ |
| 580 | {"mitBin.meta_lic", "mplLib.meta_lic", []string{"static"}}, |
| 581 | }, |
| 582 | expectedResolutions: []res{ |
| 583 | {"mitBin.meta_lic", "mplLib.meta_lic", "mplLib.meta_lic", "reciprocal"}, |
| 584 | }, |
| 585 | }, |
| 586 | { |
| 587 | name: "reciponnoticenotice", |
| 588 | condition: ImpliesNotice, |
| 589 | roots: []string{"mplBin.meta_lic"}, |
| 590 | edges: []annotated{ |
| 591 | {"mplBin.meta_lic", "mitLib.meta_lic", []string{"static"}}, |
| 592 | }, |
| 593 | expectedResolutions: []res{ |
| 594 | {"mplBin.meta_lic", "mplBin.meta_lic", "mplBin.meta_lic", "reciprocal"}, |
| 595 | {"mplBin.meta_lic", "mitLib.meta_lic", "mitLib.meta_lic", "notice"}, |
| 596 | }, |
| 597 | }, |
| 598 | { |
| 599 | name: "reciponnoticerecip", |
| 600 | condition: ImpliesReciprocal, |
| 601 | roots: []string{"mplBin.meta_lic"}, |
| 602 | edges: []annotated{ |
| 603 | {"mplBin.meta_lic", "mitLib.meta_lic", []string{"static"}}, |
| 604 | }, |
| 605 | expectedResolutions: []res{ |
| 606 | {"mplBin.meta_lic", "mplBin.meta_lic", "mplBin.meta_lic", "reciprocal"}, |
| 607 | }, |
| 608 | }, |
| 609 | } |
| 610 | for _, tt := range tests { |
| 611 | t.Run(tt.name, func(t *testing.T) { |
| 612 | stderr := &bytes.Buffer{} |
| 613 | lg, err := toGraph(stderr, tt.roots, tt.edges) |
| 614 | if err != nil { |
Colin Cross | 179ec3e | 2022-01-27 15:47:09 -0800 | [diff] [blame] | 615 | t.Errorf("unexpected test data error: got %s, want no error", err) |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 616 | return |
| 617 | } |
| 618 | expectedRs := toResolutionSet(lg, tt.expectedResolutions) |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 619 | ResolveTopDownConditions(lg) |
| 620 | actualRs := WalkResolutionsForCondition(lg, tt.condition) |
| 621 | checkResolves(actualRs, expectedRs, t) |
| 622 | }) |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | func TestWalkActionsForCondition(t *testing.T) { |
| 627 | tests := []struct { |
| 628 | name string |
| 629 | condition LicenseConditionSet |
| 630 | roots []string |
| 631 | edges []annotated |
| 632 | expectedActions []act |
| 633 | }{ |
| 634 | { |
| 635 | name: "firstparty", |
| 636 | condition: ImpliesNotice, |
| 637 | roots: []string{"apacheBin.meta_lic"}, |
| 638 | edges: []annotated{ |
| 639 | {"apacheBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 640 | }, |
| 641 | expectedActions: []act{ |
| 642 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
| 643 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 644 | }, |
| 645 | }, |
| 646 | { |
| 647 | name: "notice", |
| 648 | condition: ImpliesNotice, |
| 649 | roots: []string{"mitBin.meta_lic"}, |
| 650 | edges: []annotated{ |
| 651 | {"mitBin.meta_lic", "mitLib.meta_lic", []string{"static"}}, |
| 652 | }, |
| 653 | expectedActions: []act{ |
| 654 | {"mitBin.meta_lic", "mitBin.meta_lic", "notice"}, |
| 655 | {"mitLib.meta_lic", "mitLib.meta_lic", "notice"}, |
| 656 | }, |
| 657 | }, |
| 658 | { |
| 659 | name: "fponlgplnotice", |
| 660 | condition: ImpliesNotice, |
| 661 | roots: []string{"apacheBin.meta_lic"}, |
| 662 | edges: []annotated{ |
| 663 | {"apacheBin.meta_lic", "lgplLib.meta_lic", []string{"static"}}, |
| 664 | }, |
| 665 | expectedActions: []act{ |
| 666 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
| 667 | {"apacheBin.meta_lic", "lgplLib.meta_lic", "restricted"}, |
| 668 | {"lgplLib.meta_lic", "lgplLib.meta_lic", "restricted"}, |
| 669 | }, |
| 670 | }, |
| 671 | { |
| 672 | name: "fponlgpldynamicnotice", |
| 673 | condition: ImpliesNotice, |
| 674 | roots: []string{"apacheBin.meta_lic"}, |
| 675 | edges: []annotated{ |
| 676 | {"apacheBin.meta_lic", "lgplLib.meta_lic", []string{"dynamic"}}, |
| 677 | }, |
| 678 | expectedActions: []act{ |
| 679 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
| 680 | }, |
| 681 | }, |
| 682 | { |
| 683 | name: "independentmodulenotice", |
| 684 | condition: ImpliesNotice, |
| 685 | roots: []string{"apacheBin.meta_lic"}, |
| 686 | edges: []annotated{ |
| 687 | {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}}, |
| 688 | }, |
| 689 | expectedActions: []act{ |
| 690 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
| 691 | }, |
| 692 | }, |
| 693 | { |
| 694 | name: "independentmodulerestricted", |
| 695 | condition: ImpliesRestricted, |
| 696 | roots: []string{"apacheBin.meta_lic"}, |
| 697 | edges: []annotated{ |
| 698 | {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}}, |
| 699 | }, |
| 700 | expectedActions: []act{}, |
| 701 | }, |
| 702 | { |
| 703 | name: "independentmodulestaticnotice", |
| 704 | condition: ImpliesNotice, |
| 705 | roots: []string{"apacheBin.meta_lic"}, |
| 706 | edges: []annotated{ |
| 707 | {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"static"}}, |
| 708 | }, |
| 709 | expectedActions: []act{ |
| 710 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 711 | {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "permissive"}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 712 | }, |
| 713 | }, |
| 714 | { |
| 715 | name: "independentmodulestaticrestricted", |
| 716 | condition: ImpliesRestricted, |
| 717 | roots: []string{"apacheBin.meta_lic"}, |
| 718 | edges: []annotated{ |
| 719 | {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"static"}}, |
| 720 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 721 | expectedActions: []act{}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 722 | }, |
| 723 | { |
| 724 | name: "dependentmodulenotice", |
| 725 | condition: ImpliesNotice, |
| 726 | roots: []string{"dependentModule.meta_lic"}, |
| 727 | edges: []annotated{ |
| 728 | {"dependentModule.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}}, |
| 729 | }, |
| 730 | expectedActions: []act{ |
| 731 | {"dependentModule.meta_lic", "dependentModule.meta_lic", "notice"}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 732 | }, |
| 733 | }, |
| 734 | { |
| 735 | name: "dependentmodulerestricted", |
| 736 | condition: ImpliesRestricted, |
| 737 | roots: []string{"dependentModule.meta_lic"}, |
| 738 | edges: []annotated{ |
| 739 | {"dependentModule.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}}, |
| 740 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 741 | expectedActions: []act{}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 742 | }, |
| 743 | { |
| 744 | name: "lgplonfpnotice", |
| 745 | condition: ImpliesNotice, |
| 746 | roots: []string{"lgplBin.meta_lic"}, |
| 747 | edges: []annotated{ |
| 748 | {"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 749 | }, |
| 750 | expectedActions: []act{ |
| 751 | {"lgplBin.meta_lic", "lgplBin.meta_lic", "restricted"}, |
| 752 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 753 | {"apacheLib.meta_lic", "lgplBin.meta_lic", "restricted"}, |
| 754 | }, |
| 755 | }, |
| 756 | { |
| 757 | name: "lgplonfprestricted", |
| 758 | condition: ImpliesRestricted, |
| 759 | roots: []string{"lgplBin.meta_lic"}, |
| 760 | edges: []annotated{ |
| 761 | {"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 762 | }, |
| 763 | expectedActions: []act{ |
| 764 | {"lgplBin.meta_lic", "lgplBin.meta_lic", "restricted"}, |
| 765 | {"apacheLib.meta_lic", "lgplBin.meta_lic", "restricted"}, |
| 766 | }, |
| 767 | }, |
| 768 | { |
| 769 | name: "lgplonfpdynamicnotice", |
| 770 | condition: ImpliesNotice, |
| 771 | roots: []string{"lgplBin.meta_lic"}, |
| 772 | edges: []annotated{ |
| 773 | {"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}}, |
| 774 | }, |
| 775 | expectedActions: []act{ |
| 776 | {"lgplBin.meta_lic", "lgplBin.meta_lic", "restricted"}, |
| 777 | }, |
| 778 | }, |
| 779 | { |
| 780 | name: "lgplonfpdynamicrestricted", |
| 781 | condition: ImpliesRestricted, |
| 782 | roots: []string{"lgplBin.meta_lic"}, |
| 783 | edges: []annotated{ |
| 784 | {"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}}, |
| 785 | }, |
| 786 | expectedActions: []act{ |
| 787 | {"lgplBin.meta_lic", "lgplBin.meta_lic", "restricted"}, |
| 788 | }, |
| 789 | }, |
| 790 | { |
| 791 | name: "gplonfpnotice", |
| 792 | condition: ImpliesNotice, |
| 793 | roots: []string{"gplBin.meta_lic"}, |
| 794 | edges: []annotated{ |
| 795 | {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 796 | }, |
| 797 | expectedActions: []act{ |
| 798 | {"gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 799 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 800 | {"apacheLib.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 801 | }, |
| 802 | }, |
| 803 | { |
| 804 | name: "gplonfprestricted", |
| 805 | condition: ImpliesRestricted, |
| 806 | roots: []string{"gplBin.meta_lic"}, |
| 807 | edges: []annotated{ |
| 808 | {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 809 | }, |
| 810 | expectedActions: []act{ |
| 811 | {"gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 812 | {"apacheLib.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 813 | }, |
| 814 | }, |
| 815 | { |
| 816 | name: "gplcontainernotice", |
| 817 | condition: ImpliesNotice, |
| 818 | roots: []string{"gplContainer.meta_lic"}, |
| 819 | edges: []annotated{ |
| 820 | {"gplContainer.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 821 | }, |
| 822 | expectedActions: []act{ |
| 823 | {"gplContainer.meta_lic", "gplContainer.meta_lic", "restricted"}, |
| 824 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 825 | {"apacheLib.meta_lic", "gplContainer.meta_lic", "restricted"}, |
| 826 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 827 | {"apacheLib.meta_lic", "gplContainer.meta_lic", "restricted"}, |
| 828 | }, |
| 829 | }, |
| 830 | { |
| 831 | name: "gplcontainerrestricted", |
| 832 | condition: ImpliesRestricted, |
| 833 | roots: []string{"gplContainer.meta_lic"}, |
| 834 | edges: []annotated{ |
| 835 | {"gplContainer.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 836 | }, |
| 837 | expectedActions: []act{ |
| 838 | {"gplContainer.meta_lic", "gplContainer.meta_lic", "restricted"}, |
| 839 | {"apacheLib.meta_lic", "gplContainer.meta_lic", "restricted"}, |
| 840 | {"apacheLib.meta_lic", "gplContainer.meta_lic", "restricted"}, |
| 841 | }, |
| 842 | }, |
| 843 | { |
| 844 | name: "gploncontainernotice", |
| 845 | condition: ImpliesNotice, |
| 846 | roots: []string{"apacheContainer.meta_lic"}, |
| 847 | edges: []annotated{ |
| 848 | {"apacheContainer.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 849 | {"apacheContainer.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 850 | }, |
| 851 | expectedActions: []act{ |
| 852 | {"apacheContainer.meta_lic", "apacheContainer.meta_lic", "notice"}, |
| 853 | {"apacheContainer.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 854 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 855 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 856 | {"gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 857 | }, |
| 858 | }, |
| 859 | { |
| 860 | name: "gploncontainerrestricted", |
| 861 | condition: ImpliesRestricted, |
| 862 | roots: []string{"apacheContainer.meta_lic"}, |
| 863 | edges: []annotated{ |
| 864 | {"apacheContainer.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 865 | {"apacheContainer.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 866 | }, |
| 867 | expectedActions: []act{ |
| 868 | {"apacheContainer.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 869 | {"gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 870 | }, |
| 871 | }, |
| 872 | { |
| 873 | name: "gplonbinnotice", |
| 874 | condition: ImpliesNotice, |
| 875 | roots: []string{"apacheBin.meta_lic"}, |
| 876 | edges: []annotated{ |
| 877 | {"apacheBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 878 | {"apacheBin.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 879 | }, |
| 880 | expectedActions: []act{ |
| 881 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
| 882 | {"apacheBin.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 883 | {"apacheLib.meta_lic", "apacheLib.meta_lic", "notice"}, |
| 884 | {"apacheLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 885 | {"gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 886 | }, |
| 887 | }, |
| 888 | { |
| 889 | name: "gplonbinrestricted", |
| 890 | condition: ImpliesRestricted, |
| 891 | roots: []string{"apacheBin.meta_lic"}, |
| 892 | edges: []annotated{ |
| 893 | {"apacheBin.meta_lic", "apacheLib.meta_lic", []string{"static"}}, |
| 894 | {"apacheBin.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 895 | }, |
| 896 | expectedActions: []act{ |
| 897 | {"apacheBin.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 898 | {"apacheLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 899 | {"gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 900 | }, |
| 901 | }, |
| 902 | { |
| 903 | name: "gplonfpdynamicnotice", |
| 904 | condition: ImpliesNotice, |
| 905 | roots: []string{"gplBin.meta_lic"}, |
| 906 | edges: []annotated{ |
| 907 | {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}}, |
| 908 | }, |
| 909 | expectedActions: []act{ |
| 910 | {"gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 911 | }, |
| 912 | }, |
| 913 | { |
| 914 | name: "gplonfpdynamicrestricted", |
| 915 | condition: ImpliesRestricted, |
| 916 | roots: []string{"gplBin.meta_lic"}, |
| 917 | edges: []annotated{ |
| 918 | {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}}, |
| 919 | }, |
| 920 | expectedActions: []act{ |
| 921 | {"gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 922 | }, |
| 923 | }, |
| 924 | { |
| 925 | name: "gplonfpdynamicrestrictedshipped", |
| 926 | condition: ImpliesRestricted, |
| 927 | roots: []string{"gplBin.meta_lic", "apacheLib.meta_lic"}, |
| 928 | edges: []annotated{ |
| 929 | {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}}, |
| 930 | }, |
| 931 | expectedActions: []act{ |
| 932 | {"gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 933 | {"apacheLib.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 934 | }, |
| 935 | }, |
| 936 | { |
| 937 | name: "independentmodulereversenotice", |
| 938 | condition: ImpliesNotice, |
| 939 | roots: []string{"gplWithClasspathException.meta_lic"}, |
| 940 | edges: []annotated{ |
| 941 | {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"dynamic"}}, |
| 942 | }, |
| 943 | expectedActions: []act{ |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 944 | {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "permissive"}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 945 | }, |
| 946 | }, |
| 947 | { |
| 948 | name: "independentmodulereverserestricted", |
| 949 | condition: ImpliesRestricted, |
| 950 | roots: []string{"gplWithClasspathException.meta_lic"}, |
| 951 | edges: []annotated{ |
| 952 | {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"dynamic"}}, |
| 953 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 954 | expectedActions: []act{}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 955 | }, |
| 956 | { |
| 957 | name: "independentmodulereverserestrictedshipped", |
| 958 | condition: ImpliesRestricted, |
| 959 | roots: []string{"gplWithClasspathException.meta_lic", "apacheBin.meta_lic"}, |
| 960 | edges: []annotated{ |
| 961 | {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"dynamic"}}, |
| 962 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 963 | expectedActions: []act{}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 964 | }, |
| 965 | { |
| 966 | name: "independentmodulereversestaticnotice", |
| 967 | condition: ImpliesNotice, |
| 968 | roots: []string{"gplWithClasspathException.meta_lic"}, |
| 969 | edges: []annotated{ |
| 970 | {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"static"}}, |
| 971 | }, |
| 972 | expectedActions: []act{ |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 973 | {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "permissive"}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 974 | {"apacheBin.meta_lic", "apacheBin.meta_lic", "notice"}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 975 | }, |
| 976 | }, |
| 977 | { |
| 978 | name: "independentmodulereversestaticrestricted", |
| 979 | condition: ImpliesRestricted, |
| 980 | roots: []string{"gplWithClasspathException.meta_lic"}, |
| 981 | edges: []annotated{ |
| 982 | {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"static"}}, |
| 983 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 984 | expectedActions: []act{}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 985 | }, |
| 986 | { |
| 987 | name: "dependentmodulereversenotice", |
| 988 | condition: ImpliesNotice, |
| 989 | roots: []string{"gplWithClasspathException.meta_lic"}, |
| 990 | edges: []annotated{ |
| 991 | {"gplWithClasspathException.meta_lic", "dependentModule.meta_lic", []string{"dynamic"}}, |
| 992 | }, |
| 993 | expectedActions: []act{ |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 994 | {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "permissive"}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 995 | }, |
| 996 | }, |
| 997 | { |
| 998 | name: "dependentmodulereverserestricted", |
| 999 | condition: ImpliesRestricted, |
| 1000 | roots: []string{"gplWithClasspathException.meta_lic"}, |
| 1001 | edges: []annotated{ |
| 1002 | {"gplWithClasspathException.meta_lic", "dependentModule.meta_lic", []string{"dynamic"}}, |
| 1003 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 1004 | expectedActions: []act{}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 1005 | }, |
| 1006 | { |
| 1007 | name: "dependentmodulereverserestrictedshipped", |
| 1008 | condition: ImpliesRestricted, |
| 1009 | roots: []string{"gplWithClasspathException.meta_lic", "dependentModule.meta_lic"}, |
| 1010 | edges: []annotated{ |
| 1011 | {"gplWithClasspathException.meta_lic", "dependentModule.meta_lic", []string{"dynamic"}}, |
| 1012 | }, |
Bob Badour | 10f5c48 | 2022-09-20 21:44:17 -0700 | [diff] [blame] | 1013 | expectedActions: []act{}, |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 1014 | }, |
| 1015 | { |
| 1016 | name: "ponrnotice", |
| 1017 | condition: ImpliesNotice, |
| 1018 | roots: []string{"proprietary.meta_lic"}, |
| 1019 | edges: []annotated{ |
| 1020 | {"proprietary.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 1021 | }, |
| 1022 | expectedActions: []act{ |
| 1023 | {"proprietary.meta_lic", "proprietary.meta_lic", "proprietary"}, |
| 1024 | {"proprietary.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 1025 | {"gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 1026 | }, |
| 1027 | }, |
| 1028 | { |
| 1029 | name: "ponrrestricted", |
| 1030 | condition: ImpliesRestricted, |
| 1031 | roots: []string{"proprietary.meta_lic"}, |
| 1032 | edges: []annotated{ |
| 1033 | {"proprietary.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 1034 | }, |
| 1035 | expectedActions: []act{ |
| 1036 | {"gplLib.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 1037 | {"proprietary.meta_lic", "gplLib.meta_lic", "restricted"}, |
| 1038 | }, |
| 1039 | }, |
| 1040 | { |
| 1041 | name: "ponrproprietary", |
| 1042 | condition: ImpliesProprietary, |
| 1043 | roots: []string{"proprietary.meta_lic"}, |
| 1044 | edges: []annotated{ |
| 1045 | {"proprietary.meta_lic", "gplLib.meta_lic", []string{"static"}}, |
| 1046 | }, |
| 1047 | expectedActions: []act{ |
| 1048 | {"proprietary.meta_lic", "proprietary.meta_lic", "proprietary"}, |
| 1049 | }, |
| 1050 | }, |
| 1051 | { |
| 1052 | name: "ronpnotice", |
| 1053 | condition: ImpliesNotice, |
| 1054 | roots: []string{"gplBin.meta_lic"}, |
| 1055 | edges: []annotated{ |
| 1056 | {"gplBin.meta_lic", "proprietary.meta_lic", []string{"static"}}, |
| 1057 | }, |
| 1058 | expectedActions: []act{ |
| 1059 | {"gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 1060 | {"proprietary.meta_lic", "proprietary.meta_lic", "proprietary"}, |
| 1061 | {"proprietary.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 1062 | }, |
| 1063 | }, |
| 1064 | { |
| 1065 | name: "ronprestricted", |
| 1066 | condition: ImpliesRestricted, |
| 1067 | roots: []string{"gplBin.meta_lic"}, |
| 1068 | edges: []annotated{ |
| 1069 | {"gplBin.meta_lic", "proprietary.meta_lic", []string{"static"}}, |
| 1070 | }, |
| 1071 | expectedActions: []act{ |
| 1072 | {"gplBin.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 1073 | {"proprietary.meta_lic", "gplBin.meta_lic", "restricted"}, |
| 1074 | }, |
| 1075 | }, |
| 1076 | { |
| 1077 | name: "ronpproprietary", |
| 1078 | condition: ImpliesProprietary, |
| 1079 | roots: []string{"gplBin.meta_lic"}, |
| 1080 | edges: []annotated{ |
| 1081 | {"gplBin.meta_lic", "proprietary.meta_lic", []string{"static"}}, |
| 1082 | }, |
| 1083 | expectedActions: []act{ |
| 1084 | {"proprietary.meta_lic", "proprietary.meta_lic", "proprietary"}, |
| 1085 | }, |
| 1086 | }, |
| 1087 | { |
| 1088 | name: "noticeonb_e_onotice", |
| 1089 | condition: ImpliesNotice, |
| 1090 | roots: []string{"mitBin.meta_lic"}, |
| 1091 | edges: []annotated{ |
| 1092 | {"mitBin.meta_lic", "by_exception.meta_lic", []string{"static"}}, |
| 1093 | }, |
| 1094 | expectedActions: []act{ |
| 1095 | {"mitBin.meta_lic", "mitBin.meta_lic", "notice"}, |
| 1096 | {"by_exception.meta_lic", "by_exception.meta_lic", "by_exception_only"}, |
| 1097 | }, |
| 1098 | }, |
| 1099 | { |
| 1100 | name: "noticeonb_e_orestricted", |
| 1101 | condition: ImpliesRestricted, |
| 1102 | roots: []string{"mitBin.meta_lic"}, |
| 1103 | edges: []annotated{ |
| 1104 | {"mitBin.meta_lic", "by_exception.meta_lic", []string{"static"}}, |
| 1105 | }, |
| 1106 | expectedActions: []act{}, |
| 1107 | }, |
| 1108 | { |
| 1109 | name: "noticeonb_e_ob_e_o", |
| 1110 | condition: ImpliesByExceptionOnly, |
| 1111 | roots: []string{"mitBin.meta_lic"}, |
| 1112 | edges: []annotated{ |
| 1113 | {"mitBin.meta_lic", "by_exception.meta_lic", []string{"static"}}, |
| 1114 | }, |
| 1115 | expectedActions: []act{ |
| 1116 | {"by_exception.meta_lic", "by_exception.meta_lic", "by_exception_only"}, |
| 1117 | }, |
| 1118 | }, |
| 1119 | { |
| 1120 | name: "b_e_oonnoticenotice", |
| 1121 | condition: ImpliesNotice, |
| 1122 | roots: []string{"by_exception.meta_lic"}, |
| 1123 | edges: []annotated{ |
| 1124 | {"by_exception.meta_lic", "mitLib.meta_lic", []string{"static"}}, |
| 1125 | }, |
| 1126 | expectedActions: []act{ |
| 1127 | {"by_exception.meta_lic", "by_exception.meta_lic", "by_exception_only"}, |
| 1128 | {"mitLib.meta_lic", "mitLib.meta_lic", "notice"}, |
| 1129 | }, |
| 1130 | }, |
| 1131 | { |
| 1132 | name: "b_e_oonnoticerestricted", |
| 1133 | condition: ImpliesRestricted, |
| 1134 | roots: []string{"by_exception.meta_lic"}, |
| 1135 | edges: []annotated{ |
| 1136 | {"by_exception.meta_lic", "mitLib.meta_lic", []string{"static"}}, |
| 1137 | }, |
| 1138 | expectedActions: []act{}, |
| 1139 | }, |
| 1140 | { |
| 1141 | name: "b_e_oonnoticeb_e_o", |
| 1142 | condition: ImpliesByExceptionOnly, |
| 1143 | roots: []string{"by_exception.meta_lic"}, |
| 1144 | edges: []annotated{ |
| 1145 | {"by_exception.meta_lic", "mitLib.meta_lic", []string{"static"}}, |
| 1146 | }, |
| 1147 | expectedActions: []act{ |
| 1148 | {"by_exception.meta_lic", "by_exception.meta_lic", "by_exception_only"}, |
| 1149 | }, |
| 1150 | }, |
| 1151 | { |
| 1152 | name: "noticeonrecipnotice", |
| 1153 | condition: ImpliesNotice, |
| 1154 | roots: []string{"mitBin.meta_lic"}, |
| 1155 | edges: []annotated{ |
| 1156 | {"mitBin.meta_lic", "mplLib.meta_lic", []string{"static"}}, |
| 1157 | }, |
| 1158 | expectedActions: []act{ |
| 1159 | {"mitBin.meta_lic", "mitBin.meta_lic", "notice"}, |
| 1160 | {"mplLib.meta_lic", "mplLib.meta_lic", "reciprocal"}, |
| 1161 | }, |
| 1162 | }, |
| 1163 | { |
| 1164 | name: "noticeonreciprecip", |
| 1165 | condition: ImpliesReciprocal, |
| 1166 | roots: []string{"mitBin.meta_lic"}, |
| 1167 | edges: []annotated{ |
| 1168 | {"mitBin.meta_lic", "mplLib.meta_lic", []string{"static"}}, |
| 1169 | }, |
| 1170 | expectedActions: []act{ |
| 1171 | {"mplLib.meta_lic", "mplLib.meta_lic", "reciprocal"}, |
| 1172 | }, |
| 1173 | }, |
| 1174 | { |
| 1175 | name: "reciponnoticenotice", |
| 1176 | condition: ImpliesNotice, |
| 1177 | roots: []string{"mplBin.meta_lic"}, |
| 1178 | edges: []annotated{ |
| 1179 | {"mplBin.meta_lic", "mitLib.meta_lic", []string{"static"}}, |
| 1180 | }, |
| 1181 | expectedActions: []act{ |
| 1182 | {"mplBin.meta_lic", "mplBin.meta_lic", "reciprocal"}, |
| 1183 | {"mitLib.meta_lic", "mitLib.meta_lic", "notice"}, |
| 1184 | }, |
| 1185 | }, |
| 1186 | { |
| 1187 | name: "reciponnoticerecip", |
| 1188 | condition: ImpliesReciprocal, |
| 1189 | roots: []string{"mplBin.meta_lic"}, |
| 1190 | edges: []annotated{ |
| 1191 | {"mplBin.meta_lic", "mitLib.meta_lic", []string{"static"}}, |
| 1192 | }, |
| 1193 | expectedActions: []act{ |
| 1194 | {"mplBin.meta_lic", "mplBin.meta_lic", "reciprocal"}, |
| 1195 | }, |
| 1196 | }, |
| 1197 | } |
| 1198 | for _, tt := range tests { |
| 1199 | t.Run(tt.name, func(t *testing.T) { |
| 1200 | stderr := &bytes.Buffer{} |
| 1201 | lg, err := toGraph(stderr, tt.roots, tt.edges) |
| 1202 | if err != nil { |
Colin Cross | 179ec3e | 2022-01-27 15:47:09 -0800 | [diff] [blame] | 1203 | t.Errorf("unexpected test data error: got %s, want no error", err) |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 1204 | return |
| 1205 | } |
| 1206 | expectedAs := toActionSet(lg, tt.expectedActions) |
| 1207 | ResolveTopDownConditions(lg) |
| 1208 | actualAs := WalkActionsForCondition(lg, tt.condition) |
| 1209 | checkResolvesActions(lg, actualAs, expectedAs, t) |
Bob Badour | 9ee7d03 | 2021-10-25 16:51:48 -0700 | [diff] [blame] | 1210 | }) |
| 1211 | } |
| 1212 | } |
Ibrahim Kanouche | e7c33de | 2022-09-22 18:17:41 +0000 | [diff] [blame^] | 1213 | |
| 1214 | func TestWalkTopDownBreadthFirst(t *testing.T) { |
| 1215 | tests := []struct { |
| 1216 | name string |
| 1217 | roots []string |
| 1218 | edges []annotated |
| 1219 | expectedResult []string |
| 1220 | }{ |
| 1221 | { |
| 1222 | name: "bin/bin1", |
| 1223 | roots: []string{"bin/bin1.meta_lic"}, |
| 1224 | expectedResult: []string{ |
| 1225 | "testdata/notice/bin/bin1.meta_lic", |
| 1226 | "testdata/notice/lib/liba.so.meta_lic", |
| 1227 | "testdata/notice/lib/libc.a.meta_lic", |
| 1228 | }, |
| 1229 | }, |
| 1230 | { |
| 1231 | name: "bin/bin2", |
| 1232 | roots: []string{"bin/bin2.meta_lic"}, |
| 1233 | expectedResult: []string{ |
| 1234 | "testdata/notice/bin/bin2.meta_lic", |
| 1235 | "testdata/notice/lib/libb.so.meta_lic", |
| 1236 | "testdata/notice/lib/libd.so.meta_lic", |
| 1237 | }, |
| 1238 | }, |
| 1239 | { |
| 1240 | name: "bin/bin3", |
| 1241 | roots: []string{"bin/bin3.meta_lic"}, |
| 1242 | expectedResult: []string{ |
| 1243 | "testdata/notice/bin/bin3.meta_lic", |
| 1244 | }, |
| 1245 | }, |
| 1246 | { |
| 1247 | name: "lib/liba.so", |
| 1248 | roots: []string{"lib/liba.so.meta_lic"}, |
| 1249 | expectedResult: []string{ |
| 1250 | "testdata/notice/lib/liba.so.meta_lic", |
| 1251 | }, |
| 1252 | }, |
| 1253 | { |
| 1254 | name: "lib/libb.so", |
| 1255 | roots: []string{"lib/libb.so.meta_lic"}, |
| 1256 | expectedResult: []string{ |
| 1257 | "testdata/notice/lib/libb.so.meta_lic", |
| 1258 | }, |
| 1259 | }, |
| 1260 | { |
| 1261 | name: "lib/libc.so", |
| 1262 | roots: []string{"lib/libc.a.meta_lic"}, |
| 1263 | expectedResult: []string{ |
| 1264 | "testdata/notice/lib/libc.a.meta_lic", |
| 1265 | }, |
| 1266 | }, |
| 1267 | { |
| 1268 | name: "lib/libd.so", |
| 1269 | roots: []string{"lib/libd.so.meta_lic"}, |
| 1270 | expectedResult: []string{ |
| 1271 | "testdata/notice/lib/libd.so.meta_lic", |
| 1272 | }, |
| 1273 | }, |
| 1274 | { |
| 1275 | name: "highest.apex", |
| 1276 | roots: []string{"highest.apex.meta_lic"}, |
| 1277 | expectedResult: []string{ |
| 1278 | "testdata/notice/highest.apex.meta_lic", |
| 1279 | "testdata/notice/bin/bin1.meta_lic", |
| 1280 | "testdata/notice/bin/bin2.meta_lic", |
| 1281 | "testdata/notice/lib/liba.so.meta_lic", |
| 1282 | "testdata/notice/lib/libb.so.meta_lic", |
| 1283 | "testdata/notice/lib/liba.so.meta_lic", |
| 1284 | "testdata/notice/lib/libc.a.meta_lic", |
| 1285 | "testdata/notice/lib/libb.so.meta_lic", |
| 1286 | "testdata/notice/lib/libd.so.meta_lic", |
| 1287 | }, |
| 1288 | }, |
| 1289 | { |
| 1290 | name: "container.zip", |
| 1291 | roots: []string{"container.zip.meta_lic"}, |
| 1292 | expectedResult: []string{ |
| 1293 | "testdata/notice/container.zip.meta_lic", |
| 1294 | "testdata/notice/bin/bin1.meta_lic", |
| 1295 | "testdata/notice/bin/bin2.meta_lic", |
| 1296 | "testdata/notice/lib/liba.so.meta_lic", |
| 1297 | "testdata/notice/lib/libb.so.meta_lic", |
| 1298 | "testdata/notice/lib/liba.so.meta_lic", |
| 1299 | "testdata/notice/lib/libc.a.meta_lic", |
| 1300 | "testdata/notice/lib/libb.so.meta_lic", |
| 1301 | "testdata/notice/lib/libd.so.meta_lic", |
| 1302 | }, |
| 1303 | }, |
| 1304 | { |
| 1305 | name: "application", |
| 1306 | roots: []string{"application.meta_lic"}, |
| 1307 | expectedResult: []string{ |
| 1308 | "testdata/notice/application.meta_lic", |
| 1309 | "testdata/notice/bin/bin3.meta_lic", |
| 1310 | "testdata/notice/lib/liba.so.meta_lic", |
| 1311 | "testdata/notice/lib/libb.so.meta_lic", |
| 1312 | }, |
| 1313 | }, |
| 1314 | { |
| 1315 | name: "bin/bin1&lib/liba", |
| 1316 | roots: []string{"bin/bin1.meta_lic","lib/liba.so.meta_lic"}, |
| 1317 | expectedResult: []string{ |
| 1318 | "testdata/notice/bin/bin1.meta_lic", |
| 1319 | "testdata/notice/lib/liba.so.meta_lic", |
| 1320 | "testdata/notice/lib/liba.so.meta_lic", |
| 1321 | "testdata/notice/lib/libc.a.meta_lic", |
| 1322 | }, |
| 1323 | }, |
| 1324 | { |
| 1325 | name: "bin/bin2&lib/libd", |
| 1326 | roots: []string{"bin/bin2.meta_lic", "lib/libd.so.meta_lic"}, |
| 1327 | expectedResult: []string{ |
| 1328 | "testdata/notice/bin/bin2.meta_lic", |
| 1329 | "testdata/notice/lib/libd.so.meta_lic", |
| 1330 | "testdata/notice/lib/libb.so.meta_lic", |
| 1331 | "testdata/notice/lib/libd.so.meta_lic", |
| 1332 | }, |
| 1333 | }, |
| 1334 | { |
| 1335 | name: "application&bin/bin3", |
| 1336 | roots: []string{"application.meta_lic", "bin/bin3.meta_lic"}, |
| 1337 | expectedResult: []string{ |
| 1338 | "testdata/notice/application.meta_lic", |
| 1339 | "testdata/notice/bin/bin3.meta_lic", |
| 1340 | "testdata/notice/bin/bin3.meta_lic", |
| 1341 | "testdata/notice/lib/liba.so.meta_lic", |
| 1342 | "testdata/notice/lib/libb.so.meta_lic", |
| 1343 | }, |
| 1344 | }, |
| 1345 | { |
| 1346 | name: "highest.apex&container.zip", |
| 1347 | roots: []string{"highest.apex.meta_lic", "container.zip.meta_lic"}, |
| 1348 | expectedResult: []string{ |
| 1349 | "testdata/notice/highest.apex.meta_lic", |
| 1350 | "testdata/notice/container.zip.meta_lic", |
| 1351 | "testdata/notice/bin/bin1.meta_lic", |
| 1352 | "testdata/notice/bin/bin2.meta_lic", |
| 1353 | "testdata/notice/lib/liba.so.meta_lic", |
| 1354 | "testdata/notice/lib/libb.so.meta_lic", |
| 1355 | "testdata/notice/lib/liba.so.meta_lic", |
| 1356 | "testdata/notice/lib/libc.a.meta_lic", |
| 1357 | "testdata/notice/lib/libb.so.meta_lic", |
| 1358 | "testdata/notice/lib/libd.so.meta_lic", |
| 1359 | "testdata/notice/bin/bin1.meta_lic", |
| 1360 | "testdata/notice/bin/bin2.meta_lic", |
| 1361 | "testdata/notice/lib/liba.so.meta_lic", |
| 1362 | "testdata/notice/lib/libb.so.meta_lic", |
| 1363 | "testdata/notice/lib/liba.so.meta_lic", |
| 1364 | "testdata/notice/lib/libc.a.meta_lic", |
| 1365 | "testdata/notice/lib/libb.so.meta_lic", |
| 1366 | "testdata/notice/lib/libd.so.meta_lic", |
| 1367 | }, |
| 1368 | }, |
| 1369 | } |
| 1370 | |
| 1371 | for _, tt := range tests { |
| 1372 | t.Run(tt.name, func(t *testing.T) { |
| 1373 | stderr := &bytes.Buffer{} |
| 1374 | actualOut := &bytes.Buffer{} |
| 1375 | |
| 1376 | rootFiles := make([]string, 0, len(tt.roots)) |
| 1377 | for _, r := range tt.roots { |
| 1378 | rootFiles = append(rootFiles, "testdata/notice/"+r) |
| 1379 | } |
| 1380 | |
| 1381 | lg, err := ReadLicenseGraph(GetFS(""), stderr, rootFiles) |
| 1382 | |
| 1383 | if err != nil { |
| 1384 | t.Errorf("unexpected test data error: got %s, want no error", err) |
| 1385 | return |
| 1386 | } |
| 1387 | |
| 1388 | expectedRst := tt.expectedResult |
| 1389 | |
| 1390 | WalkTopDownBreadthFirst(nil, lg, func(lg *LicenseGraph, tn *TargetNode, path TargetEdgePath) bool { |
| 1391 | fmt.Fprintln(actualOut, tn.Name()) |
| 1392 | return true |
| 1393 | }) |
| 1394 | |
| 1395 | actualRst := strings.Split(actualOut.String(), "\n") |
| 1396 | |
| 1397 | if len(actualRst) > 0 { |
| 1398 | actualRst = actualRst[:len(actualRst)-1] |
| 1399 | } |
| 1400 | |
| 1401 | t.Logf("actual nodes visited: %s", actualOut.String()) |
| 1402 | t.Logf("expected nodes visited: %s", strings.Join(expectedRst, "\n")) |
| 1403 | |
| 1404 | if len(actualRst) != len(expectedRst) { |
| 1405 | t.Errorf("WalkTopDownBreadthFirst: number of visited nodes is different: got %d, want %d", len(actualRst), len(expectedRst)) |
| 1406 | } |
| 1407 | |
| 1408 | for i := 0; i < len(actualRst) && i < len(expectedRst); i++ { |
| 1409 | if actualRst[i] != expectedRst[i] { |
| 1410 | t.Errorf("WalkTopDownBreadthFirst: lines differ at index %d: got %q, want %q", i, actualRst[i], expectedRst[i]) |
| 1411 | break |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | if len(actualRst) < len(expectedRst) { |
| 1416 | t.Errorf("WalkTopDownBreadthFirst: extra lines at %d: got %q, want nothing", len(actualRst), expectedRst[len(actualRst)]) |
| 1417 | } |
| 1418 | |
| 1419 | if len(expectedRst) < len(actualRst) { |
| 1420 | t.Errorf("WalkTopDownBreadthFirst: missing lines at %d: got nothing, want %q", len(expectedRst), actualRst[len(expectedRst)]) |
| 1421 | } |
| 1422 | }) |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | func TestWalkTopDownBreadthFirstWithoutDuplicates(t *testing.T) { |
| 1427 | tests := []struct { |
| 1428 | name string |
| 1429 | roots []string |
| 1430 | edges []annotated |
| 1431 | expectedResult []string |
| 1432 | }{ |
| 1433 | { |
| 1434 | name: "bin/bin1", |
| 1435 | roots: []string{"bin/bin1.meta_lic"}, |
| 1436 | expectedResult: []string{ |
| 1437 | "testdata/notice/bin/bin1.meta_lic", |
| 1438 | "testdata/notice/lib/liba.so.meta_lic", |
| 1439 | "testdata/notice/lib/libc.a.meta_lic", |
| 1440 | }, |
| 1441 | }, |
| 1442 | { |
| 1443 | name: "bin/bin2", |
| 1444 | roots: []string{"bin/bin2.meta_lic"}, |
| 1445 | expectedResult: []string{ |
| 1446 | "testdata/notice/bin/bin2.meta_lic", |
| 1447 | "testdata/notice/lib/libb.so.meta_lic", |
| 1448 | "testdata/notice/lib/libd.so.meta_lic", |
| 1449 | }, |
| 1450 | }, |
| 1451 | { |
| 1452 | name: "bin/bin3", |
| 1453 | roots: []string{"bin/bin3.meta_lic"}, |
| 1454 | expectedResult: []string{ |
| 1455 | "testdata/notice/bin/bin3.meta_lic", |
| 1456 | }, |
| 1457 | }, |
| 1458 | { |
| 1459 | name: "lib/liba.so", |
| 1460 | roots: []string{"lib/liba.so.meta_lic"}, |
| 1461 | expectedResult: []string{ |
| 1462 | "testdata/notice/lib/liba.so.meta_lic", |
| 1463 | }, |
| 1464 | }, |
| 1465 | { |
| 1466 | name: "lib/libb.so", |
| 1467 | roots: []string{"lib/libb.so.meta_lic"}, |
| 1468 | expectedResult: []string{ |
| 1469 | "testdata/notice/lib/libb.so.meta_lic", |
| 1470 | }, |
| 1471 | }, |
| 1472 | { |
| 1473 | name: "lib/libc.so", |
| 1474 | roots: []string{"lib/libc.a.meta_lic"}, |
| 1475 | expectedResult: []string{ |
| 1476 | "testdata/notice/lib/libc.a.meta_lic", |
| 1477 | }, |
| 1478 | }, |
| 1479 | { |
| 1480 | name: "lib/libd.so", |
| 1481 | roots: []string{"lib/libd.so.meta_lic"}, |
| 1482 | expectedResult: []string{ |
| 1483 | "testdata/notice/lib/libd.so.meta_lic", |
| 1484 | }, |
| 1485 | }, |
| 1486 | { |
| 1487 | name: "highest.apex", |
| 1488 | roots: []string{"highest.apex.meta_lic"}, |
| 1489 | expectedResult: []string{ |
| 1490 | "testdata/notice/highest.apex.meta_lic", |
| 1491 | "testdata/notice/bin/bin1.meta_lic", |
| 1492 | "testdata/notice/bin/bin2.meta_lic", |
| 1493 | "testdata/notice/lib/liba.so.meta_lic", |
| 1494 | "testdata/notice/lib/libb.so.meta_lic", |
| 1495 | "testdata/notice/lib/libc.a.meta_lic", |
| 1496 | "testdata/notice/lib/libd.so.meta_lic", |
| 1497 | }, |
| 1498 | }, |
| 1499 | { |
| 1500 | name: "container.zip", |
| 1501 | roots: []string{"container.zip.meta_lic"}, |
| 1502 | expectedResult: []string{ |
| 1503 | "testdata/notice/container.zip.meta_lic", |
| 1504 | "testdata/notice/bin/bin1.meta_lic", |
| 1505 | "testdata/notice/bin/bin2.meta_lic", |
| 1506 | "testdata/notice/lib/liba.so.meta_lic", |
| 1507 | "testdata/notice/lib/libb.so.meta_lic", |
| 1508 | "testdata/notice/lib/libc.a.meta_lic", |
| 1509 | "testdata/notice/lib/libd.so.meta_lic", |
| 1510 | }, |
| 1511 | }, |
| 1512 | { |
| 1513 | name: "application", |
| 1514 | roots: []string{"application.meta_lic"}, |
| 1515 | expectedResult: []string{ |
| 1516 | "testdata/notice/application.meta_lic", |
| 1517 | "testdata/notice/bin/bin3.meta_lic", |
| 1518 | "testdata/notice/lib/liba.so.meta_lic", |
| 1519 | "testdata/notice/lib/libb.so.meta_lic", |
| 1520 | }, |
| 1521 | }, |
| 1522 | { |
| 1523 | name: "bin/bin1&lib/liba", |
| 1524 | roots: []string{"bin/bin1.meta_lic", "lib/liba.so.meta_lic"}, |
| 1525 | expectedResult: []string{ |
| 1526 | "testdata/notice/bin/bin1.meta_lic", |
| 1527 | "testdata/notice/lib/liba.so.meta_lic", |
| 1528 | "testdata/notice/lib/libc.a.meta_lic", |
| 1529 | }, |
| 1530 | }, |
| 1531 | { |
| 1532 | name: "bin/bin2&lib/libd", |
| 1533 | roots: []string{"bin/bin2.meta_lic", "lib/libd.so.meta_lic"}, |
| 1534 | expectedResult: []string{ |
| 1535 | "testdata/notice/bin/bin2.meta_lic", |
| 1536 | "testdata/notice/lib/libd.so.meta_lic", |
| 1537 | "testdata/notice/lib/libb.so.meta_lic", |
| 1538 | }, |
| 1539 | }, |
| 1540 | { |
| 1541 | name: "application&bin/bin3", |
| 1542 | roots: []string{"application.meta_lic", "bin/bin3.meta_lic"}, |
| 1543 | expectedResult: []string{ |
| 1544 | "testdata/notice/application.meta_lic", |
| 1545 | "testdata/notice/bin/bin3.meta_lic", |
| 1546 | "testdata/notice/lib/liba.so.meta_lic", |
| 1547 | "testdata/notice/lib/libb.so.meta_lic", |
| 1548 | }, |
| 1549 | }, |
| 1550 | { |
| 1551 | name: "highest.apex&container.zip", |
| 1552 | roots: []string{"highest.apex.meta_lic", "container.zip.meta_lic"}, |
| 1553 | expectedResult: []string{ |
| 1554 | "testdata/notice/highest.apex.meta_lic", |
| 1555 | "testdata/notice/container.zip.meta_lic", |
| 1556 | "testdata/notice/bin/bin1.meta_lic", |
| 1557 | "testdata/notice/bin/bin2.meta_lic", |
| 1558 | "testdata/notice/lib/liba.so.meta_lic", |
| 1559 | "testdata/notice/lib/libb.so.meta_lic", |
| 1560 | "testdata/notice/lib/libc.a.meta_lic", |
| 1561 | "testdata/notice/lib/libd.so.meta_lic", |
| 1562 | }, |
| 1563 | }, |
| 1564 | } |
| 1565 | |
| 1566 | for _, tt := range tests { |
| 1567 | t.Run(tt.name, func(t *testing.T) { |
| 1568 | stderr := &bytes.Buffer{} |
| 1569 | actualOut := &bytes.Buffer{} |
| 1570 | |
| 1571 | rootFiles := make([]string, 0, len(tt.roots)) |
| 1572 | for _, r := range tt.roots { |
| 1573 | rootFiles = append(rootFiles, "testdata/notice/"+r) |
| 1574 | } |
| 1575 | |
| 1576 | lg, err := ReadLicenseGraph(GetFS(""), stderr, rootFiles) |
| 1577 | |
| 1578 | if err != nil { |
| 1579 | t.Errorf("unexpected test data error: got %s, want no error", err) |
| 1580 | return |
| 1581 | } |
| 1582 | |
| 1583 | expectedRst := tt.expectedResult |
| 1584 | |
| 1585 | //Keeping track of the visited nodes |
| 1586 | //Only add to actualOut if not visited |
| 1587 | visitedNodes := make(map[string]struct{}) |
| 1588 | WalkTopDownBreadthFirst(nil, lg, func(lg *LicenseGraph, tn *TargetNode, path TargetEdgePath) bool { |
| 1589 | if _, alreadyVisited := visitedNodes[tn.Name()]; alreadyVisited { |
| 1590 | return false |
| 1591 | } |
| 1592 | fmt.Fprintln(actualOut, tn.Name()) |
| 1593 | visitedNodes[tn.Name()] = struct{}{} |
| 1594 | return true |
| 1595 | }) |
| 1596 | |
| 1597 | actualRst := strings.Split(actualOut.String(), "\n") |
| 1598 | |
| 1599 | if len(actualRst) > 0 { |
| 1600 | actualRst = actualRst[:len(actualRst)-1] |
| 1601 | } |
| 1602 | |
| 1603 | t.Logf("actual nodes visited: %s", actualOut.String()) |
| 1604 | t.Logf("expected nodes visited: %s", strings.Join(expectedRst, "\n")) |
| 1605 | |
| 1606 | if len(actualRst) != len(expectedRst) { |
| 1607 | t.Errorf("WalkTopDownBreadthFirst: number of visited nodes is different: got %d, want %d", len(actualRst), len(expectedRst)) |
| 1608 | } |
| 1609 | |
| 1610 | for i := 0; i < len(actualRst) && i < len(expectedRst); i++ { |
| 1611 | if actualRst[i] != expectedRst[i] { |
| 1612 | t.Errorf("WalkTopDownBreadthFirst: lines differ at index %d: got %q, want %q", i, actualRst[i], expectedRst[i]) |
| 1613 | break |
| 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | if len(actualRst) < len(expectedRst) { |
| 1618 | t.Errorf("WalkTopDownBreadthFirst: extra lines at %d: got %q, want nothing", len(actualRst), expectedRst[len(actualRst)]) |
| 1619 | } |
| 1620 | |
| 1621 | if len(expectedRst) < len(actualRst) { |
| 1622 | t.Errorf("WalkTopDownBreadthFirst: missing lines at %d: got nothing, want %q", len(expectedRst), actualRst[len(expectedRst)]) |
| 1623 | } |
| 1624 | }) |
| 1625 | } |
| 1626 | } |