Skip to content

Commit 4952e6c

Browse files
authored
licensescan: Add simple license crosscheck (#3682)
1 parent 8eb9958 commit 4952e6c

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tools/licensescan/licensedb_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/fs"
6+
"os"
7+
"path/filepath"
8+
"testing"
9+
10+
"sigs.k8s.io/yaml"
11+
)
12+
13+
// Test that the license didn't change for the same module
14+
func TestLicensesForConsistency(t *testing.T) {
15+
files := make(map[string]*moduleInfo)
16+
17+
if err := filepath.Walk("modules", func(p string, info fs.FileInfo, err error) error {
18+
if err != nil {
19+
return err
20+
}
21+
22+
if info.IsDir() {
23+
return nil
24+
}
25+
b, err := os.ReadFile(p)
26+
if err != nil {
27+
return fmt.Errorf("error reading file %q: %w", p, err)
28+
}
29+
30+
m := &moduleInfo{}
31+
if err := yaml.Unmarshal(b, m); err != nil {
32+
return fmt.Errorf("error parsing %q: %w", p, err)
33+
}
34+
35+
files[p] = m
36+
return nil
37+
}); err != nil {
38+
t.Fatalf("error during walk: %v", err)
39+
}
40+
41+
for f1, m1 := range files {
42+
dir := filepath.Dir(f1)
43+
for f2, m2 := range files {
44+
// Only compare pairs once
45+
if f1 >= f2 {
46+
continue
47+
}
48+
49+
if filepath.Dir(f2) != dir {
50+
continue
51+
}
52+
53+
if m1.License != m2.License {
54+
switch f1 {
55+
case "modules/github.com/klauspost/compress/v1.11.2.yaml":
56+
// license changed after v1.11.2
57+
default:
58+
t.Errorf("license mismatch: %v=%v, %v=%v", f1, m1.License, f2, m2.License)
59+
}
60+
}
61+
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)