-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtlog_test.go
More file actions
81 lines (77 loc) · 1.68 KB
/
Copy pathtlog_test.go
File metadata and controls
81 lines (77 loc) · 1.68 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
package main
import (
"io"
"os"
"testing"
)
var (
tests = []struct {
Filename string
Reader io.Reader
Revisions int
Files int
CheckRevision string
Who string
Skip bool
}{
{
Filename: "tests/multipart1",
Revisions: 55,
Files: 3,
CheckRevision: "e5b622e57b2b08f20828ead059db36338c6a54b0",
Who: "gregkh",
Skip: true,
},
{
Filename: "tests/multipart2",
Revisions: 2982,
Files: 5,
CheckRevision: "14a832498c23cf480243222189066a8006182b9d",
Who: "sfr",
Skip: false,
},
}
)
func TestRevisions(t *testing.T) {
for _, test := range tests {
if test.Skip {
continue
}
f, _ := os.Open(test.Filename)
files, _ := ParseMail(f)
if len(files) != test.Files {
t.Fatalf("%s: Expected %d files, got %d", test.Filename, test.Files, len(files))
}
w, revs := WorkRevisions(files)
if len(revs) != test.Revisions {
t.Fatalf("%s: Expected %d revisions, got %d", test.Filename, test.Revisions, len(revs))
}
if w != test.Who {
t.Fatalf("%s: Expected %s, got %s", test.Filename, test.Who, w)
}
}
}
func TestWorkDB(t *testing.T) {
os.Remove("test.db")
InitDB("test.db")
count := int64(0)
for _, test := range tests {
if test.Skip {
continue
}
f, _ := os.Open(test.Filename)
files, err := ParseMail(f)
if err != nil {
t.Fatal(err)
}
tlogEntry := WorkTLog(test.Filename, files)
AddCommit(tlogEntry)
err = db.Table("revisions").Where("\"commit\" = ?", test.CheckRevision).Count(&count).Error
if err != nil {
t.Fatal(err)
}
if count == 0 {
t.Fatalf("didn't find revision after insertion")
}
}
}