-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconflict_test.go
More file actions
108 lines (104 loc) · 2.44 KB
/
Copy pathconflict_test.go
File metadata and controls
108 lines (104 loc) · 2.44 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
package patch2pr
import (
"errors"
"testing"
)
func TestConflictError(t *testing.T) {
for i, tc := range []struct {
Conflict Conflict
Error string
}{
{
Conflict{},
"conflict",
},
{
Conflict{File: "path/to/file.txt"},
"path/to/file.txt: conflict",
},
{
Conflict{File: "path/to/file.txt", Type: ConflictNewFileExists},
"path/to/file.txt: conflict: new file already exists",
},
{
Conflict{File: "path/to/file.txt", Type: ConflictDeletedFileMissing},
"path/to/file.txt: conflict: deleted file does not exist",
},
{
Conflict{File: "path/to/file.txt", Type: ConflictModifiedFileMissing},
"path/to/file.txt: conflict: modified file does not exist",
},
{
Conflict{File: "path/to/file.txt", Type: ConflictContent},
"path/to/file.txt: conflict: content",
},
{
Conflict{File: "path/to/file.txt", Line: 23, Type: ConflictContent},
"path/to/file.txt:23: conflict: content",
},
} {
want := tc.Error
if got := tc.Conflict.Error(); got != want {
t.Errorf("case %d: Error(): want %q, got %q", i, want, got)
}
}
}
func TestConflictIs(t *testing.T) {
defaultConflict := Conflict{
Type: ConflictModifiedFileMissing,
File: "path/to/file.txt",
}
for name, tc := range map[string]struct {
Conflict Conflict
Target error
Match bool
}{
"nil": {
Conflict: defaultConflict,
Target: nil,
Match: false,
},
"otherType": {
Conflict: defaultConflict,
Target: errors.New("different error"),
Match: false,
},
"emptyConflictMatches": {
Conflict: defaultConflict,
Target: &Conflict{},
Match: true,
},
"typeOnlyMatch": {
Conflict: defaultConflict,
Target: &Conflict{Type: ConflictModifiedFileMissing},
Match: true,
},
"fileOnlyMatch": {
Conflict: defaultConflict,
Target: &Conflict{File: "path/to/file.txt"},
Match: true,
},
"typeAndFileMatch": {
Conflict: defaultConflict,
Target: &Conflict{Type: ConflictModifiedFileMissing, File: "path/to/file.txt"},
Match: true,
},
"differentType": {
Conflict: defaultConflict,
Target: &Conflict{Type: ConflictContent},
Match: false,
},
"differentFile": {
Conflict: defaultConflict,
Target: &Conflict{File: "path/to/other/file.txt"},
Match: false,
},
} {
want := tc.Match
t.Run(name, func(t *testing.T) {
if got := tc.Conflict.Is(tc.Target); got != want {
t.Errorf("Is(target): want %t, got %t", want, got)
}
})
}
}