forked from rancher/trash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trash_test.go
55 lines (48 loc) · 1.3 KB
/
trash_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
package main
import (
"fmt"
"go/parser"
"go/token"
"testing"
"github.com/Sirupsen/logrus"
"github.com/stretchr/testify/require"
)
func TestParentPackages(t *testing.T) {
assert := require.New(t)
packages := parentPackages("", "github.com/stretchr/testify/require")
assert.Len(packages, 4)
assert.True(packages["github.com"])
assert.True(packages["github.com/stretchr"])
assert.True(packages["github.com/stretchr/testify"])
assert.True(packages["github.com/stretchr/testify/require"])
}
func TestParseDir(t *testing.T) {
assert := require.New(t)
fset := token.NewFileSet()
pkgs, err := parser.ParseDir(fset, ".", nil, parser.ImportsOnly)
if err != nil {
assert.Fail(err.Error())
return
}
for pkgName, pkg := range pkgs {
fmt.Printf("pkg: %s\n", pkgName)
if len(pkg.Files) == 0 {
fmt.Println(" (no files)")
}
for name, f := range pkg.Files {
fmt.Println(" " + name)
for _, v := range f.Imports {
fmt.Println(" " + v.Path.Value[1:len(v.Path.Value)-1])
}
}
}
}
func TestListPackages(t *testing.T) {
assert := require.New(t)
p := listPackages("github.com/srcclr/trash", "vendor")
logrus.Debug(p)
assert.Equal(3, len(p))
assert.Contains(p, "github.com/srcclr/trash")
assert.Contains(p, "github.com/srcclr/trash/util")
assert.Contains(p, "github.com/srcclr/trash/conf")
}