@@ -19,14 +19,21 @@ import (
19
19
"io/fs"
20
20
"os"
21
21
"path/filepath"
22
+ "sort"
23
+ "strings"
22
24
"testing"
23
25
24
26
"sigs.k8s.io/yaml"
25
27
)
26
28
27
29
// Test that the license didn't change for the same module
28
30
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 )
30
37
31
38
if err := filepath .Walk ("modules" , func (p string , info fs.FileInfo , err error ) error {
32
39
if err != nil {
@@ -46,30 +53,35 @@ func TestLicensesForConsistency(t *testing.T) {
46
53
return fmt .Errorf ("error parsing %q: %w" , p , err )
47
54
}
48
55
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
+ })
50
64
return nil
51
65
}); err != nil {
52
66
t .Fatalf ("error during walk: %v" , err )
53
67
}
54
68
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 ]
66
76
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" :
70
80
// license changed after v1.11.2
81
+ case "sigs.k8s.io/[email protected] " :
82
+ // license changed after v1.3.0
71
83
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 )
73
85
}
74
86
}
75
87
0 commit comments