forked from markbates/pkger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkger_test.go
96 lines (75 loc) · 1.81 KB
/
pkger_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
package pkger
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func Test_Parse(t *testing.T) {
r := require.New(t)
pt, err := Parse("github.com/rocket/ship:/little")
r.NoError(err)
r.Equal("github.com/rocket/ship", pt.Pkg)
r.Equal("/little", pt.Name)
}
func Test_Current(t *testing.T) {
r := require.New(t)
info, err := Current()
r.NoError(err)
r.Equal("github.com/markbates/pkger", info.ImportPath)
}
func Test_Info(t *testing.T) {
r := require.New(t)
info, err := Info("github.com/markbates/pkger")
r.NoError(err)
r.Equal("github.com/markbates/pkger", info.ImportPath)
}
func Test_Create(t *testing.T) {
r := require.New(t)
MkdirAll("/tmp", 0755)
defer RemoveAll("/tmp")
f, err := Create("/tmp/test.create")
r.NoError(err)
r.Equal("github.com/markbates/pkger:/tmp/test.create", f.Name())
r.NoError(f.Close())
}
func Test_MkdirAll(t *testing.T) {
r := require.New(t)
_, err := Open("/tmp")
r.Error(err)
r.NoError(MkdirAll("/tmp", 0755))
defer RemoveAll("/tmp")
f, err := Open("/tmp")
r.NoError(err)
r.Equal("github.com/markbates/pkger:/tmp", f.Name())
r.NoError(f.Close())
}
func Test_Stat(t *testing.T) {
r := require.New(t)
info, err := Stat("/go.mod")
r.NoError(err)
r.Equal("go.mod", info.Name())
}
func Test_Walk(t *testing.T) {
r := require.New(t)
files := map[string]os.FileInfo{}
err := Walk("/pkging/pkgtest/testdata/ref", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
files[path] = info
return nil
})
r.NoError(err)
r.True(len(files) > 10)
}
func Test_Remove(t *testing.T) {
r := require.New(t)
MkdirAll("/tmp", 0755)
defer RemoveAll("/tmp")
f, err := Create("/tmp/test.create")
r.NoError(err)
r.NoError(f.Close())
r.NoError(Remove("/tmp/test.create"))
_, err = Stat("/tmp/test.create")
r.Error(err)
}