Skip to content

Commit d272347

Browse files
committed
tests: update licensescan tests to recognize sigs.k8s.io/yaml license change
The Apache license was added in 1.4.0
1 parent 7e77cd5 commit d272347

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

tools/licensescan/licensedb_test.go

+29-17
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,21 @@ import (
1919
"io/fs"
2020
"os"
2121
"path/filepath"
22+
"sort"
23+
"strings"
2224
"testing"
2325

2426
"sigs.k8s.io/yaml"
2527
)
2628

2729
// Test that the license didn't change for the same module
2830
func TestLicensesForConsistency(t *testing.T) {
29-
files := make(map[string]*moduleInfo)
31+
type moduleVersion struct {
32+
ModuleInfo *moduleInfo
33+
Version string
34+
}
35+
36+
modules := make(map[string][]*moduleVersion)
3037

3138
if err := filepath.Walk("modules", func(p string, info fs.FileInfo, err error) error {
3239
if err != nil {
@@ -46,30 +53,35 @@ func TestLicensesForConsistency(t *testing.T) {
4653
return fmt.Errorf("error parsing %q: %w", p, err)
4754
}
4855

49-
files[p] = m
56+
modulePath := filepath.Dir(p)
57+
modulePath = strings.TrimPrefix(modulePath, "modules/")
58+
version := filepath.Base(p)
59+
version = strings.TrimSuffix(version, ".yaml")
60+
modules[modulePath] = append(modules[modulePath], &moduleVersion{
61+
ModuleInfo: m,
62+
Version: version,
63+
})
5064
return nil
5165
}); err != nil {
5266
t.Fatalf("error during walk: %v", err)
5367
}
5468

55-
for f1, m1 := range files {
56-
dir := filepath.Dir(f1)
57-
for f2, m2 := range files {
58-
// Only compare pairs once
59-
if f1 >= f2 {
60-
continue
61-
}
62-
63-
if filepath.Dir(f2) != dir {
64-
continue
65-
}
69+
for module, versions := range modules {
70+
sort.Slice(versions, func(i, j int) bool {
71+
return versions[i].Version < versions[j].Version
72+
})
73+
for i := 0; i < len(versions)-1; i++ {
74+
v1 := versions[i]
75+
v2 := versions[i+1]
6676

67-
if m1.License != m2.License {
68-
switch f1 {
69-
case "modules/github.com/klauspost/compress/v1.11.2.yaml":
77+
if v1.ModuleInfo.License != v2.ModuleInfo.License {
78+
switch module + "@" + v1.Version {
79+
case "github.com/klauspost/compress@v1.11.2":
7080
// license changed after v1.11.2
81+
case "sigs.k8s.io/[email protected]":
82+
// license changed after v1.3.0
7183
default:
72-
t.Errorf("license mismatch: %v=%v, %v=%v", f1, m1.License, f2, m2.License)
84+
t.Errorf("license mismatch: %v %v=%v, %v=%v", module, v1.Version, v1.ModuleInfo.License, v2.Version, v2.ModuleInfo.License)
7385
}
7486
}
7587

0 commit comments

Comments
 (0)