-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsrc_test.go
48 lines (38 loc) · 1.02 KB
/
src_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
package assets
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSrc(t *testing.T) {
t.Run("found", func(t *testing.T) {
assert := assert.New(t)
c := caller
defer func() { caller = c }()
caller = func(skip int) (pc uintptr, file string, line int, ok bool) {
path, err := filepath.Abs("testdata/main.go")
assert.NoError(err)
return uintptr(0), path, 0, true
}
s := Src("assets")
path, err := s.Path()
assert.NoError(err)
assetsPath, err := filepath.Abs("testdata/assets")
assert.NoError(err)
assert.Equal(assetsPath, path)
assert.NoError(s.Close())
})
t.Run("not found", func(t *testing.T) {
assert := assert.New(t)
c := caller
defer func() { caller = c }()
caller = func(skip int) (pc uintptr, file string, line int, ok bool) {
path, err := filepath.Abs("testdata/main.go")
assert.NoError(err)
return uintptr(0), path, 0, true
}
s := Src("I hope you don't have this weirdly named directory")
_, err := s.Path()
assert.Error(err)
})
}