-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
dir_test.go
107 lines (83 loc) · 2.05 KB
/
dir_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package here
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func Test_Dir(t *testing.T) {
r := require.New(t)
root, err := os.Getwd()
r.NoError(err)
info, err := Dir(root)
r.NoError(err)
sanityCheck(t, info)
}
func Test_Dir_NonGoDir(t *testing.T) {
r := require.New(t)
root, err := os.Getwd()
r.NoError(err)
empty := filepath.Join(root, "..", "empty")
os.MkdirAll(empty, 0755)
defer os.RemoveAll(empty)
info, err := Dir(empty)
r.NoError(err)
r.NotZero(info)
r.Equal(empty, info.Dir)
r.Equal("", info.Module.GoMod)
r.Equal("", info.ImportPath)
r.Equal("empty", info.Name)
r.Empty(info.GoFiles)
r.Empty(info.Imports)
}
func Test_Dir_Within(t *testing.T) {
r := require.New(t)
root, err := os.Getwd()
r.NoError(err)
cmd := filepath.Join(root, "cmd")
info, err := Dir(cmd)
r.NoError(err)
r.NotZero(info)
r.Equal(cmd, info.Dir)
r.Equal(filepath.Join(root, "go.mod"), info.Module.GoMod)
r.Equal("github.com/gobuffalo/here", info.ImportPath)
r.Equal("cmd", info.Name)
r.Empty(info.GoFiles)
r.Empty(info.Imports)
}
func Test_Dir_CmdHere(t *testing.T) {
r := require.New(t)
root, err := os.Getwd()
r.NoError(err)
cmd := filepath.Join(root, "cmd", "here")
info, err := Dir(cmd)
r.NoError(err)
r.NotZero(info)
r.Equal(cmd, info.Dir)
r.Equal(filepath.Join(root, "go.mod"), info.Module.GoMod)
r.Equal("github.com/gobuffalo/here/cmd/here", info.ImportPath)
r.Equal("main", info.Name)
r.NotEmpty(info.GoFiles)
r.NotEmpty(info.Imports)
}
func Test_Dir_File(t *testing.T) {
r := require.New(t)
root, err := os.Getwd()
r.NoError(err)
cmd := filepath.Join(root, "cmd", "here", "main.go")
info, err := Dir(cmd)
r.NoError(err)
r.NotZero(info)
r.Equal(filepath.Dir(cmd), info.Dir)
r.Equal(filepath.Join(root, "go.mod"), info.Module.GoMod)
r.Equal("github.com/gobuffalo/here/cmd/here", info.ImportPath)
r.Equal("main", info.Name)
r.NotEmpty(info.GoFiles)
r.NotEmpty(info.Imports)
}
func Test_Dir_Unknown(t *testing.T) {
r := require.New(t)
info, err := Dir("/unknown")
r.Error(err)
r.Zero(info)
}