-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore_test.go
62 lines (49 loc) · 1.92 KB
/
restore_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
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 TestRestoreUsingForUntrackedFiles(t *testing.T) {
gittest.InitRepository(t, gittest.WithFiles("main.go", ".github/ci.yaml", "go.mod"))
untracked := [2]git.FileStatusIndicator{git.Untracked, git.Untracked}
client, _ := git.NewClient()
err := client.RestoreUsing([]git.FileStatus{
{Indicators: untracked, Path: "main.go"},
{Indicators: untracked, Path: ".github/"},
{Indicators: untracked, Path: "go.mod"},
})
require.NoError(t, err)
statuses := gittest.PorcelainStatus(t)
assert.Empty(t, statuses)
}
func TestRestoreUsingForModifiedFiles(t *testing.T) {
gittest.InitRepository(t, gittest.WithCommittedFiles("main.go", "doc.go"))
gittest.WriteFile(t, "main.go", "updated", 0o644)
gittest.WriteFile(t, "doc.go", "updated", 0o644)
gittest.StageFile(t, "main.go")
client, _ := git.NewClient()
err := client.RestoreUsing([]git.FileStatus{
{Indicators: [2]git.FileStatusIndicator{git.Modified, git.Untracked}, Path: "main.go"},
{Indicators: [2]git.FileStatusIndicator{git.Untracked, git.Modified}, Path: "doc.go"},
})
require.NoError(t, err)
statuses := gittest.PorcelainStatus(t)
assert.Empty(t, statuses)
}
func TestRestoreUsingForRenamedFiles(t *testing.T) {
gittest.InitRepository(t, gittest.WithCommittedFiles("main.go", "cache.go", "keys.go"))
gittest.Move(t, "cache.go", "internal/cache/cache.go")
gittest.Move(t, "keys.go", "internal/cache/keys.go")
renamed := [2]git.FileStatusIndicator{git.Renamed, git.Unmodified}
client, _ := git.NewClient()
err := client.RestoreUsing([]git.FileStatus{
{Indicators: renamed, Path: "cache.go -> internal/cache/cache.go"},
{Indicators: renamed, Path: "keys.go -> internal/cache/keys.go"},
})
require.NoError(t, err)
statuses := gittest.PorcelainStatus(t)
assert.Empty(t, statuses)
}