-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathlicense_test.go
More file actions
52 lines (47 loc) · 1.47 KB
/
Copy pathlicense_test.go
File metadata and controls
52 lines (47 loc) · 1.47 KB
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
package maiao
import (
"io/ioutil"
"strings"
"testing"
pkggodevclient "github.com/guseggert/pkggodev-client"
"github.com/stretchr/testify/require"
"golang.org/x/mod/modfile"
)
var (
acceptedLicenses = map[string]struct{}{
"MIT": struct{}{},
"Apache-2.0": struct{}{},
"BSD-3-Clause": struct{}{},
"BSD-2-Clause": struct{}{},
"ISC": struct{}{},
}
knownUndectedLicenses = map[string]string{
// bufpipe was later added the MIT license: https://github.com/acomagu/bufpipe/blob/cd7a5f79d3c413d14c0c60fd31dae7b397fc955a/LICENSE
"github.com/acomagu/bufpipe@v1.0.3": "MIT",
}
)
func TestLicenses(t *testing.T) {
b, err := ioutil.ReadFile("go.mod")
require.NoError(t, err)
file, err := modfile.Parse("go.mod", b, nil)
require.NoError(t, err)
client := pkggodevclient.New()
for _, req := range file.Require {
pkg, err := client.DescribePackage(pkggodevclient.DescribePackageRequest{
Package: req.Mod.Path,
})
require.NoError(t, err)
licences := strings.Split(pkg.License, ",")
for _, license := range licences {
license = strings.TrimSpace(license)
if license == "None detected" {
if known, ok := knownUndectedLicenses[req.Mod.String()]; ok {
license = known
}
}
if _, ok := acceptedLicenses[license]; !ok {
t.Errorf("dependency %s is using unexpected license %s. Check that this license complies with MIT in which maiao is released and update the checks accordingly or change dependency", req.Mod, license)
}
}
}
}