-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil_test.go
69 lines (62 loc) · 1.31 KB
/
util_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
import (
"fmt"
"io"
"os"
"testing"
)
func TestParsePatchsetWithCover(t *testing.T) {
file, err := os.Open("fixtures/with-cover.patch")
defer func() {
_ = file.Close()
}()
if err != nil {
t.Fatal(err.Error())
}
actual, err := ParsePatchset(file)
if err != nil {
t.Fatal(err.Error())
}
expected := []*Patch{
{Title: "Add torch deps"},
{Title: "feat: lets build an rnn"},
{Title: "chore: add torch to requirements"},
}
if len(actual) != len(expected) {
t.Fatalf("patches not same length (expected:%d, actual:%d)\n", len(expected), len(actual))
}
for idx, act := range actual {
exp := expected[idx]
if exp.Title != act.Title {
t.Fatalf("title does not match expected (expected:%s, actual:%s)", exp.Title, act.Title)
}
}
}
func TestPatchToDiff(t *testing.T) {
file, err := os.Open("fixtures/single.patch")
defer func() {
_ = file.Close()
}()
if err != nil {
t.Fatal(err.Error())
}
fileExp, err := os.Open("fixtures/single.diff")
defer func() {
_ = file.Close()
}()
if err != nil {
t.Fatal(err.Error())
}
actual, err := patchToDiff(file)
if err != nil {
t.Fatal(err.Error())
}
by, err := io.ReadAll(fileExp)
if err != nil {
t.Fatal("cannot read expected file")
}
if actual != string(by) {
fmt.Println(actual)
t.Fatal("diff does not match expected")
}
}