-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlicense_test.go
54 lines (49 loc) · 1.48 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
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": {},
"Apache-2.0": {},
"BSD-3-Clause": {},
"BSD-2-Clause": {},
"ISC": {},
"CC-BY-SA-4.0": {},
"MPL-2.0": {},
}
knownUndectedLicenses = map[string]string{
// bufpipe was later added the MIT license: https://github.com/acomagu/bufpipe/blob/cd7a5f79d3c413d14c0c60fd31dae7b397fc955a/LICENSE
"github.com/acomagu/[email protected]": "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)
}
}
}
}