-
Notifications
You must be signed in to change notification settings - Fork 72
/
license_test.go
80 lines (65 loc) · 1.37 KB
/
license_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2019 - 2024 StreamNative, Inc.. All Rights Reserved..
package main
import (
"os"
"path/filepath"
"regexp"
"strings"
"testing"
)
var goFileCheck = regexp.MustCompile(`// Copyright \(c\) 2019 - 2024 StreamNative, Inc\.\. All Rights Reserved\.\.
`)
var otherCheck = regexp.MustCompile(`#
# Copyright \(c\) 2019 - 2024 StreamNative, Inc\.\. All Rights Reserved\.\.
#
`)
var skip = map[string]bool{
"charts/function-mesh-operator/crds": true,
"charts/pulsar-operator/crds": true,
"test-values": true,
}
func TestLicense(t *testing.T) {
err := filepath.Walk(".", func(path string, fi os.FileInfo, err error) error {
for k, _ := range skip {
if strings.Contains(path, k) {
return nil
}
}
if skip[path] {
return nil
}
if err != nil {
return err
}
switch filepath.Ext(path) {
case ".go":
src, err := os.ReadFile(path)
if err != nil {
return nil
}
// Find license
if !goFileCheck.Match(src) {
t.Errorf("%v: license header not present", path)
return nil
}
case ".yaml":
fallthrough
case ".conf":
src, err := os.ReadFile(path)
if err != nil {
return nil
}
// Find license
if !otherCheck.Match(src) {
t.Errorf("%v: license header not present", path)
return nil
}
default:
return nil
}
return nil
})
if err != nil {
t.Fatal(err)
}
}