forked from frapposelli/wwhrd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwalker_test.go
54 lines (38 loc) · 1.15 KB
/
walker_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 main
import (
"path/filepath"
"testing"
"github.com/ryanuber/go-license"
"github.com/stretchr/testify/assert"
)
//TestWalkImports test walking imports
func TestWalkImports(t *testing.T) {
dir, rm := mockGoPackageDir(t, "TestWalkImports")
defer rm()
pkgs, err := WalkImports(dir)
assert.NoError(t, err)
res := make(map[string]bool)
res["github.com/fake/package"] = true
res["github.com/fake/nested/inside/a/package"] = true
assert.Equal(t, res, pkgs)
}
//TestWalkImports test walking imports
func TestGetLicenses(t *testing.T) {
dir, rm := mockGoPackageDir(t, "TestGetLicenses")
defer rm()
pkgs, err := WalkImports(dir)
assert.NoError(t, err)
lics := GetLicenses(dir, pkgs)
res := make(map[string]*license.License)
var lic license.License
var lic2 license.License
lic.File = filepath.Join(dir, "vendor/github.com/fake/package", "LICENSE")
lic.Text = mockLicense
lic.Type = "FreeBSD"
lic2.File = filepath.Join(dir, "vendor/github.com/fake/nested", "LICENSE")
lic2.Text = mockLicense
lic2.Type = "FreeBSD"
res["github.com/fake/package"] = &lic
res["github.com/fake/nested/inside/a/package"] = &lic2
assert.Equal(t, res, lics)
}