-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathpath_utils_test.go
63 lines (53 loc) · 1.29 KB
/
path_utils_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
package gitbase
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
fixtures "gopkg.in/src-d/go-git-fixtures.v3"
)
func TestPatternMatches(t *testing.T) {
wd, err := os.Getwd()
require.NoError(t, err)
testCases := []struct {
path string
expected []string
}{
{"cmd", []string{
filepath.Join(wd, "cmd"),
}},
{"cmd/*", []string{
filepath.Join(wd, "cmd/gitbase"),
}},
{"cmd/gitbase/*", []string{
filepath.Join(wd, "cmd/gitbase/command"),
filepath.Join(wd, "cmd/gitbase/main.go"),
}},
{"cmd/../cmd/gitbase/*", []string{
filepath.Join(wd, "cmd/gitbase/command"),
filepath.Join(wd, "cmd/gitbase/main.go"),
}},
}
for _, test := range testCases {
t.Run(test.path, func(t *testing.T) {
files, err := PatternMatches(test.path)
require.NoError(t, err)
require.Exactly(t, test.expected, files)
})
}
}
func TestIsGitRepo(t *testing.T) {
var require = require.New(t)
ok, err := IsGitRepo("/do/not/exist")
require.NoError(err)
require.False(ok)
path := fixtures.Basic().ByTag("worktree").One().Worktree().Root()
ok, err = IsGitRepo(path)
require.NoError(err)
require.True(ok)
}
func TestIsSivaFile(t *testing.T) {
var require = require.New(t)
require.True(IsSivaFile("is.siva"))
require.False(IsSivaFile("not-siva"))
}