-
Notifications
You must be signed in to change notification settings - Fork 16
/
gopack_test.go
46 lines (41 loc) · 1020 Bytes
/
gopack_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
package main
import (
"fmt"
"testing"
)
func TestUnusedDep(t *testing.T) {
errors := findErrors(fmt.Sprintf("%s/unused-dep", GopackTestProjects), t)
if len(errors) != 1 {
t.Fatalf("expected 1 error, found %d\n", len(errors))
}
e := errors[0]
if e.Kind != UnusedDep {
t.Errorf("expected unused dependency error\n")
}
}
func TestUnmanagedImport(t *testing.T) {
errors := findErrors(fmt.Sprintf("%s/unmanaged-import", GopackTestProjects), t)
if len(errors) != 1 {
t.Fatalf("expected 1 error, found %d\n", len(errors))
}
e := errors[0]
if e.Kind != UnmanagedImport {
t.Errorf("expected unmanaged import error\n")
}
}
func findErrors(dir string, t *testing.T) []*ProjectError {
c := NewConfig(dir)
d, err := c.LoadDependencyModel(NewGraph())
p, err := AnalyzeSourceTree(dir)
if err != nil {
t.Fatal(err)
}
errors := d.Validate(p)
PrintErrors(errors, t)
return errors
}
func PrintErrors(errors []*ProjectError, t *testing.T) {
for _, e := range errors {
t.Logf("%s\n", e.String())
}
}