-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdiff_test.go
More file actions
185 lines (180 loc) · 4.36 KB
/
diff_test.go
File metadata and controls
185 lines (180 loc) · 4.36 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package diffence
import (
"testing"
)
type wantErr struct {
header bool
fPath bool
}
func TestDiffPush(t *testing.T) {
type fields struct {
ignorer Matcher
Items []DiffItem
Error error
}
type args struct {
in string
}
tests := []struct {
name string
fields fields
want DiffItem
args args
}{
{
name: "Diff.Push() - Commit ID Header",
fields: fields{},
args: args{
in: "17949087b8e0c9179345e8dbb7b6705b49c93c77 Adds results logger" +
"\n" +
"diff --git a/web/src/main/resources/db/migration/V0_4__AdminPassword.sql b/web/src/main/resources/db/migration/V0_4__AdminPassword.sql" +
"\n" +
"index 82366e3..5fc99b9 100644",
},
want: DiffItem{
commit: "17949087b8e0c9179345e8dbb7b6705b49c93c77",
fPath: "web/src/main/resources/db/migration/V0_4__AdminPassword.sql",
},
},
{
name: "Diff.Push() - Commit ID Header",
fields: fields{},
args: args{
in: "diff --git a/web/src/main/resources/db/migration/V0_4__AdminPassword.sql b/web/src/main/resources/db/migration/V0_4__AdminPassword.sql" +
"\n" +
"index 82366e3..5fc99b9 100644",
},
want: DiffItem{
commit: "",
fPath: "web/src/main/resources/db/migration/V0_4__AdminPassword.sql",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
d := &Diff{
ignorer: tt.fields.ignorer,
Items: tt.fields.Items,
Error: tt.fields.Error,
}
d.Push(tt.args.in)
equals(t, tt.want.fPath, d.Items[0].fPath)
equals(t, tt.want.commit, d.Items[0].commit)
})
}
}
func TestExtractFilePath(t *testing.T) {
type args struct {
in string
}
tests := []struct {
name string
args args
want DiffItem
wantErr wantErr
}{
{
name: "extractFilePath - Admin Password",
args: args{
in: "diff --git a/web/src/main/resources/db/migration/V0_4__AdminPassword.sql b/web/src/main/resources/db/migration/V0_4__AdminPassword.sql" +
"\n" +
"index 82366e3..5fc99b9 100644",
},
want: DiffItem{fPath: "web/src/main/resources/db/migration/V0_4__AdminPassword.sql"},
wantErr: wantErr{false, false},
},
{
name: "extractFilePath",
args: args{
in: "diff --git a/lib/check.go b/lib/check.go" +
"\n" +
"index 82366e3..5fc99b9 100644",
},
want: DiffItem{fPath: "lib/check.go"},
wantErr: wantErr{false, false},
},
{
name: "extractFilePath",
args: args{
in: "diff --git a/README.md b/README.md" +
"\n" +
"index 82366e3..5fc99b9 100644",
},
want: DiffItem{fPath: "README.md"},
wantErr: wantErr{false, false},
},
{
name: "extractFilePath",
args: args{
in: "diff --git a/TODO.md b/TODO.md" +
"\n" +
"index 82366e3..5fc99b9 100644",
},
want: DiffItem{fPath: "TODO.md"},
wantErr: wantErr{false, false},
},
{
name: "extractFilePath",
args: args{
in: "hello world",
},
want: DiffItem{fPath: ""},
wantErr: wantErr{true, true},
},
{
name: "extractFilePath",
args: args{
in: "diff --git a/cmd/diffence/main.go b/cmd/diffence/main.go" +
"\n" +
"index 08044af..098342c 100644",
},
want: DiffItem{fPath: "cmd/diffence/main.go"},
wantErr: wantErr{false, false},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fPath, errFilepath := extractFilePath(tt.args.in)
equals(t, tt.wantErr.fPath, errFilepath != nil)
equals(t, tt.want.fPath, fPath)
})
}
}
func Test_beginsWithHash(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "beginsWithHash - Commit ID Header",
args: args{
s: "17949087b8e0c9179345e8dbb7b6705b49c93c77 Adds results logger" +
"\n" +
"diff --git a/web/src/main/resources/db/migration/V0_4__AdminPassword.sql b/web/src/main/resources/db/migration/V0_4__AdminPassword.sql" +
"\n" +
"index 82366e3..5fc99b9 100644",
},
want: true,
},
{
name: "beginsWithHash - Diff Header",
args: args{
s: "diff --git a/web/src/main/resources/db/migration/V0_4__AdminPassword.sql b/web/src/main/resources/db/migration/V0_4__AdminPassword.sql" +
"\n" +
"index 82366e3..5fc99b9 100644",
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := beginsWithHash(tt.args.s); got != tt.want {
t.Errorf("beginsWithHash() = %v, want %v", got, tt.want)
}
})
}
}