forked from go-git/go-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus_test.go
More file actions
121 lines (106 loc) · 2.54 KB
/
status_test.go
File metadata and controls
121 lines (106 loc) · 2.54 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package git
import (
"path/filepath"
"testing"
"github.com/go-git/go-billy/v6/memfs"
"github.com/go-git/go-git/v6/storage/memory"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestStatusReturnsFullPaths(t *testing.T) {
files := []string{
filepath.Join("a", "a"),
filepath.Join("b", "a"),
filepath.Join("c", "b", "a"),
filepath.Join("d", "b", "a"),
filepath.Join("e", "b", "c", "a"),
}
tests := []struct {
name string
doChange bool
strategy StatusStrategy
expected map[string]bool
}{
{
name: "strategy:Empty with changes",
doChange: true,
strategy: Empty,
expected: map[string]bool{
"a/a": true,
"b/a": true,
"c/b/a": true,
},
},
{
name: "strategy:Empty without changes",
doChange: false,
strategy: Empty,
expected: map[string]bool{},
},
{
name: "strategy:Preload with changes",
doChange: true,
strategy: Preload,
expected: map[string]bool{
"a/a": true,
"b/a": true,
"c/b/a": true,
"d/b/a": true,
"e/b/c/a": true,
},
},
{
name: "strategy:Preload without changes",
doChange: false,
strategy: Preload,
expected: map[string]bool{
"a/a": true,
"b/a": true,
"c/b/a": true,
"d/b/a": true,
"e/b/c/a": true,
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
r, err := Init(memory.NewStorage(), WithWorkTree(memfs.New()))
require.NoError(t, err)
w, err := r.Worktree()
require.NoError(t, err)
for _, fname := range files {
file, err := w.Filesystem.Create(fname)
require.NoError(t, err)
_, err = file.Write([]byte("foo"))
require.NoError(t, err)
file.Close()
_, err = w.Add(file.Name())
require.NoError(t, err)
}
_, err = w.Commit("foo", &CommitOptions{All: true})
require.NoError(t, err)
if tc.doChange {
for _, fname := range (files)[:len(files)-2] {
file, err := w.Filesystem.Create(fname)
require.NoError(t, err)
_, err = file.Write([]byte("fooo"))
require.NoError(t, err)
err = file.Close()
require.NoError(t, err)
}
}
status, err := w.StatusWithOptions(
StatusOptions{
Strategy: tc.strategy,
},
)
require.NoError(t, err)
for file := range status {
yes, ok := tc.expected[file]
assert.True(t, ok, "unexpected file %q", file)
assert.True(t, yes, "%q should not be marked as changed", file)
}
assert.Len(t, status, len(tc.expected), "length mismatch between status and expected files")
})
}
}