forked from markbates/pkger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkgtest.go
92 lines (68 loc) · 1.58 KB
/
pkgtest.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
package pkgtest
import (
"fmt"
"os"
"testing"
"github.com/rhomber/pkger/here"
"github.com/rhomber/pkger/pkging"
"github.com/stretchr/testify/require"
)
type AllFn func(ref *Ref) (pkging.Pkger, error)
func All(t *testing.T, fn AllFn) {
r := require.New(t)
type tf func(*testing.T, *Ref, pkging.Pkger)
tests := map[string]tf{
"Create": CreateTest,
"Current": CurrentTest,
"HTTP": HTTPTest,
"Info": InfoTest,
"MkdirAll": MkdirAllTest,
"Open": OpenTest,
"Remove": RemoveTest,
"RemoveAll": RemoveAllTest,
"Stat": StatTest,
"Walk": WalkTest,
}
ref, err := NewRef()
r.NoError(err)
defer os.RemoveAll(ref.Dir)
pkg, err := fn(ref)
r.NoError(err)
for n, tt := range tests {
t.Run(fmt.Sprintf("%T/%s", pkg, n), func(st *testing.T) {
st.Parallel()
r := require.New(st)
ref, err := NewRef()
r.NoError(err)
defer os.RemoveAll(ref.Dir)
pkg, err := fn(ref)
r.NoError(err)
tt(st, ref, pkg)
})
}
}
func CmpFileInfo(t *testing.T, a os.FileInfo, b os.FileInfo) {
t.Helper()
r := require.New(t)
r.Equal(a.IsDir(), b.IsDir())
r.Equal(a.Name(), b.Name())
r.NotZero(b.ModTime())
if a.IsDir() {
r.True(b.Mode().IsDir(), b.Mode().String())
return
}
r.True(b.Mode().IsRegular(), b.Mode().String())
}
func cmpHereInfo(t *testing.T, a here.Info, b here.Info) {
t.Helper()
r := require.New(t)
r.NotZero(a)
r.NotZero(b)
r.Equal(a.ImportPath, b.ImportPath)
r.Equal(a.Name, b.Name)
am := a.Module
bm := b.Module
r.Equal(am.Path, bm.Path)
r.Equal(am.Main, bm.Main)
r.Equal(am.GoVersion, bm.GoVersion)
}