-
Notifications
You must be signed in to change notification settings - Fork 0
/
gosvn_test.go
143 lines (132 loc) · 3.03 KB
/
gosvn_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
package svn
import (
"io/ioutil"
"log"
"os"
"path"
"testing"
"time"
)
const localSVNPath = "testrepo"
var svn *SVN
var localSVN *SVN
var svnurl string
var workDir string
func init() {
svnurl = os.Getenv("TEST_SVNURL")
workDir = os.Getenv("WORKDIR")
var err error
opts := &Options{Echo: os.Getenv("ECHO") != "", WorkDir: workDir, Timeout: 3 * time.Second, Username: os.Getenv("SVNUSER"), Password: os.Getenv("SVNPASSWD")}
svn, err = NewSVN(svnurl, opts)
if err != nil {
log.Fatal(err)
}
localSVN, err = NewSVN(localSVNPath, opts)
if err != nil {
log.Fatal(err)
}
InitLocalRepo()
}
func InitLocalRepo() {
if err := svn.Checkout("", localSVNPath); err != nil {
log.Fatal(err)
}
if err := localSVN.Mkdir(DefaultBranchesDir); err != nil {
log.Fatal(err)
}
if err := localSVN.Mkdir(DefaultTrunkDir); err != nil {
log.Fatal(err)
}
if err := localSVN.Mkdir(DefaultTagsDir); err != nil {
log.Fatal(err)
}
}
func TestSVNAddCommit(t *testing.T) {
fn := path.Join(workDir, localSVNPath, DefaultTrunkDir, "sample.txt")
fp, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, 0644)
fp.WriteString("# SVN Test File\n")
if err != nil {
t.Fatal(err)
}
defer fp.Close()
if err := localSVN.Add(fn, nil); err != nil {
t.Fatal(err)
}
if err := localSVN.Commit(localSVNPath, "add sample.txt", nil); err != nil {
t.Fatal(err)
}
}
func TestSVNAddCommit2(t *testing.T) {
fn := path.Join(workDir, localSVNPath, DefaultTrunkDir, "sample.txt")
fp, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, 0644)
fp.WriteString("# SVN Test File Line\n")
if err != nil {
t.Fatal(err)
}
defer fp.Close()
if err := localSVN.Commit(localSVNPath, "update sample.txt", nil); err != nil {
t.Fatal(err)
}
}
func TestCleanUp(t *testing.T) {
if err := localSVN.Cleanup(localSVNPath); err != nil {
t.Error(err)
}
}
func inArray(a []string, str string) bool {
for _, s := range a {
if str == s {
return true
}
}
return false
}
func TestNewBranch(t *testing.T) {
bn := "develop"
if err := svn.NewBranch(bn, "create branch develop"); err != nil {
t.Fatal(err)
}
if branches, err := svn.Branches(); err != nil {
t.Error(err)
} else if !inArray(branches, bn) {
t.Error("new branch fail, not exists")
}
}
func TestNewTag(t *testing.T) {
tn := "v0.1"
if err := svn.NewTag(tn, "create tag v0.1"); err != nil {
t.Fatal(err)
}
if tages, err := svn.Tags(); err != nil {
t.Error(err)
} else if !inArray(tages, tn) {
t.Error("new tag fail, not exists")
}
}
func TestLog(t *testing.T) {
lr, err := svn.Log(path.Join(svn.trunkDir, "sample.txt"))
if err != nil {
t.Fatal(err)
}
if len(lr.Logentrys) != 2 {
t.Errorf("log error expect 2 logentry get %d", len(lr.Logentrys))
}
}
func TestExport(t *testing.T) {
err := svn.Export("trunk/sample.txt", "/tmp/sample.txt", "-r", "1")
if err != nil {
t.Fatal(err)
}
fp, err := os.Open("/tmp/sample.txt")
if err != nil {
t.Fatal(err)
}
defer fp.Close()
data, err := ioutil.ReadAll(fp)
if err != nil {
t.Fatal(err)
}
if string(data) != "# SVN Test File\n" {
t.Error("Export File Err")
}
}