-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsvn_test.go
207 lines (157 loc) · 4.65 KB
/
svn_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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package svn
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func TestBasic(t *testing.T) {
r, err := Open("testdata/sample")
if err != nil {
t.Fatalf("Failed to open repo: %s", err.Error())
}
defer r.Close()
rev, err := r.LatestRevision()
if err != nil {
t.Fatalf("Failed to get latest revision: %s", err.Error())
}
if rev <= 0 {
t.Errorf("Expected latest revision to be positive, got %d", rev)
}
c, err := r.CommitInfo(1)
if err != nil {
t.Fatalf("Failed to get commit info for the first revision: %s", err.Error())
}
if c.Author != "lz" {
t.Fatalf("Wrong author: '%s'", c.Author)
}
commits, err := r.Commits(1, 2)
if err != nil {
t.Fatalf("Failed to get commits: %s", err.Error())
}
commitsCount := len(commits)
if commitsCount != 2 {
t.Errorf("Expected 2 commits, got %d", commitsCount)
}
for _, commit := range commits {
if commit.Author != "lz" {
t.Errorf("Wrong author: '%s'", commit.Author)
}
}
rev, err = r.LastPathRev("trunk/Makefile", 6)
if err != nil {
t.Errorf("Failed to get rev: %s", err.Error())
} else if rev != 5 {
t.Errorf("Expected rev 5, got %d", rev)
}
commits, err = r.History("trunk", 0, rev, 2)
if err != nil {
t.Fatalf("Failed to get history: %s", err.Error())
}
if len(commits) != 2 {
t.Errorf("Expected history call to return 2 commits, got %d", len(commits))
}
entries, err := r.Tree("trunk", 5)
if err != nil {
t.Fatalf("Failed to get tree for trunk: %s", err.Error())
}
if len(entries) != 2 {
t.Errorf("Expected the number of entries in trunk/ folder at rev 5 to equal 2, got %d", len(entries))
}
if size, err := r.FileSize("trunk/Makefile", 6); err != nil {
t.Fatalf("Failed to get file size: %s", err.Error())
} else {
exp := int64(1279)
if size != exp {
t.Errorf("Wrong file size, expected %d, got %d", exp, size)
}
}
mimeExp := "application/octet-stream"
if mime, err := r.MimeType("trunk/images/play.png", 7); err != nil {
t.Fatalf("Failed to get mime type: %s", err.Error())
} else {
if mimeExp != mime {
t.Errorf("Wrong file mime type, expected %s, got %s", mimeExp, mime)
}
}
if reader, err := r.FileContent("trunk/TODO", 6); err != nil {
t.Fatalf("Failed to read file content: %s", err.Error())
} else {
data, err := ioutil.ReadAll(reader)
if err != nil {
t.Fatalf("Failed to read from reader: %s", err.Error())
}
if string(data) != "Readme\n" {
t.Errorf("Wrong trunk/TODO content: %s", string(data))
}
}
ci, err := r.Changeset(5, false)
if err != nil {
t.Errorf("Failed to get changeset: %s", err.Error())
}
diff := `Index: trunk/Makefile
===================================================================
--- trunk/Makefile (revision 4)
+++ trunk/Makefile (revision 5)
@@ -1,3 +1,4 @@
+# Make file to build newbc project
export GOPATH := $(CURDIR)
export LIBGIT_INSTALL_PREFIX := $(CURDIR)/vendor/libgit2_bin
export LIBGIT_SRC_PATH := $(CURDIR)/vendor/libgit2
`
if ci.ChangedPaths["trunk/Makefile"].Diff != diff {
t.Errorf("Wrong file diff:\n%s\n\nExpected:\n%s", ci.ChangedPaths["trunk/Makefile"].Diff, diff)
}
ci, err = r.Changeset(6, false)
if err != nil {
t.Fatalf("Failed to get changeset 6: %s", err.Error())
}
diff = `Index: trunk/TODO
===================================================================
--- trunk/TODO (revision 0)
+++ trunk/TODO (revision 6)
@@ -0,0 +1 @@
+Readme
`
if ci.ChangedPaths["trunk/TODO"].Diff != diff {
t.Errorf("Wrong file diff:\n%s\n\nExpected:\n%s", ci.ChangedPaths["trunk/TODO"].Diff, diff)
}
ci, err = r.Changeset(9, true)
if err != nil {
t.Fatalf("Failed to get changeset 9: %s", err.Error())
}
if len(ci.ChangedPaths["trunk/Makefile"].Diff) > 0 {
t.Errorf("Empty diff expected, but got \n%s", ci.ChangedPaths["trunk/Makefile"].Diff)
}
log := "White space change"
if ci.Commit.Log != log {
t.Errorf("Bad commit log message, expected '%s', got '%s'", log, ci.Commit.Log)
}
value, err := r.PropGet("trunk/img", 10, "svn:special")
if err != nil {
t.Errorf("Can not get prop: %s", err.Error())
}
if value != "*" {
t.Errorf("Bad prop value for svn:special, got: %s", value)
}
props, err := r.PropList("trunk/img", 10)
if err != nil {
t.Errorf("Failed to get prop list: %s", err.Error())
}
if len(props) != 1 {
t.Errorf("number of properties should be 1, got %d", len(props))
}
testPropKey := "svn:special"
testPropVal := "*"
if props[testPropKey] != testPropVal {
t.Errorf("expected to get:%q, got: %q", testPropVal, props[testPropKey])
}
}
func TestCreateRepo(t *testing.T) {
path := filepath.Join(os.TempDir(), "svn-repo")
os.RemoveAll(path)
err := Create(path)
if err != nil {
t.Fatalf("Failed to create repo: %s", err.Error())
}
}