-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: update licensescan tests to recognize sigs.k8s.io/yaml license…
… change The Apache license was added in 1.4.0
- Loading branch information
Showing
1 changed file
with
29 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,14 +19,21 @@ import ( | |
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"sort" | ||
"strings" | ||
"testing" | ||
|
||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
// Test that the license didn't change for the same module | ||
func TestLicensesForConsistency(t *testing.T) { | ||
files := make(map[string]*moduleInfo) | ||
type moduleVersion struct { | ||
ModuleInfo *moduleInfo | ||
Version string | ||
} | ||
|
||
modules := make(map[string][]*moduleVersion) | ||
|
||
if err := filepath.Walk("modules", func(p string, info fs.FileInfo, err error) error { | ||
if err != nil { | ||
|
@@ -46,30 +53,35 @@ func TestLicensesForConsistency(t *testing.T) { | |
return fmt.Errorf("error parsing %q: %w", p, err) | ||
} | ||
|
||
files[p] = m | ||
modulePath := filepath.Dir(p) | ||
modulePath = strings.TrimPrefix(modulePath, "modules/") | ||
version := filepath.Base(p) | ||
version = strings.TrimSuffix(version, ".yaml") | ||
modules[modulePath] = append(modules[modulePath], &moduleVersion{ | ||
ModuleInfo: m, | ||
Version: version, | ||
}) | ||
return nil | ||
}); err != nil { | ||
t.Fatalf("error during walk: %v", err) | ||
} | ||
|
||
for f1, m1 := range files { | ||
dir := filepath.Dir(f1) | ||
for f2, m2 := range files { | ||
// Only compare pairs once | ||
if f1 >= f2 { | ||
continue | ||
} | ||
|
||
if filepath.Dir(f2) != dir { | ||
continue | ||
} | ||
for module, versions := range modules { | ||
sort.Slice(versions, func(i, j int) bool { | ||
return versions[i].Version < versions[j].Version | ||
}) | ||
for i := 0; i < len(versions)-1; i++ { | ||
v1 := versions[i] | ||
v2 := versions[i+1] | ||
|
||
if m1.License != m2.License { | ||
switch f1 { | ||
case "modules/github.com/klauspost/compress/v1.11.2.yaml": | ||
if v1.ModuleInfo.License != v2.ModuleInfo.License { | ||
switch module + "@" + v1.Version { | ||
case "github.com/klauspost/compress@v1.11.2": | ||
// license changed after v1.11.2 | ||
case "sigs.k8s.io/[email protected]": | ||
// license changed after v1.3.0 | ||
default: | ||
t.Errorf("license mismatch: %v=%v, %v=%v", f1, m1.License, f2, m2.License) | ||
t.Errorf("license mismatch: %v %v=%v, %v=%v", module, v1.Version, v1.ModuleInfo.License, v2.Version, v2.ModuleInfo.License) | ||
} | ||
} | ||
|
||
|