-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos_test.go
60 lines (56 loc) · 1011 Bytes
/
os_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
package funny
import (
"github.com/stretchr/testify/require"
"os"
"path/filepath"
"testing"
)
func TestBackTracePath(t *testing.T) {
wd, _ := os.Getwd()
type args struct {
path string
}
tests := []struct {
name string
args args
wantPath string
wantFileInfo func(os.FileInfo) bool
err error
}{
{
".git",
args{path: ".git"},
filepath.Join(wd, ".git"),
func(info os.FileInfo) bool {
return info.IsDir()
},
nil,
},
{
"go.mod",
args{path: "go.mod"},
filepath.Join(wd, "go.mod"),
func(info os.FileInfo) bool {
return !info.IsDir()
},
nil,
},
{
"..git",
args{path: "..git"},
"",
func(info os.FileInfo) bool {
return info == nil
},
os.ErrNotExist,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1, err := BacktracePathFromCurrentDir(tt.args.path)
require.True(t, err == tt.err)
require.Equal(t, tt.wantPath, got)
require.True(t, tt.wantFileInfo(got1))
})
}
}