-
Notifications
You must be signed in to change notification settings - Fork 0
/
stage_test.go
69 lines (55 loc) · 1.69 KB
/
stage_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
package git_test
import (
"testing"
git "github.com/purpleclay/gitz"
"github.com/purpleclay/gitz/gittest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestStage(t *testing.T) {
gittest.InitRepository(t, gittest.WithFiles("file.txt", "dir1/file.txt", "dir2/file.txt"))
client, _ := git.NewClient()
_, err := client.Stage()
require.NoError(t, err)
status := gittest.PorcelainStatus(t)
assert.ElementsMatch(t, []string{
"A file.txt",
"A dir1/file.txt",
"A dir2/file.txt",
}, status)
}
func TestStageWithPathSpecs(t *testing.T) {
files := []string{
"file.txt",
"dir1/file.txt",
"dir1/file.gif",
"dir2/file.txt",
}
gittest.InitRepository(t, gittest.WithFiles(files...))
client, _ := git.NewClient()
_, err := client.Stage(git.WithPathSpecs("file.txt", "dir1/*.gif"))
require.NoError(t, err)
status := gittest.PorcelainStatus(t)
assert.ElementsMatch(t, []string{
"A file.txt",
"?? dir1/file.txt",
"A dir1/file.gif",
"?? dir2/",
}, status)
}
func TestStageWithPathSpecsIgnoresEmptyPathSpecs(t *testing.T) {
gittest.InitRepository(t, gittest.WithFiles("file1.txt", "file2.txt"))
client, _ := git.NewClient()
_, err := client.Stage(git.WithPathSpecs(" ", " file2.txt "))
require.NoError(t, err)
status := gittest.PorcelainStatus(t)
assert.ElementsMatch(t, []string{"?? file1.txt", "A file2.txt"}, status)
}
func TestStaged(t *testing.T) {
gittest.InitRepository(t, gittest.WithFiles("README.md"),
gittest.WithStagedFiles("go.mod", "pkg/config/config.go"))
client, _ := git.NewClient()
staged, err := client.Staged()
require.NoError(t, err)
assert.ElementsMatch(t, []string{"go.mod", "pkg/config/config.go"}, staged)
}