This repository has been archived by the owner on Jun 20, 2020. It is now read-only.
/
change_test.go
101 lines (98 loc) · 1.88 KB
/
change_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
package main
import (
"github.com/fsouza/gogit/git"
"launchpad.net/goetveld/rietveld"
"os"
"os/exec"
"path/filepath"
"reflect"
"testing"
)
func createRepository() (*git.Repository, string) {
path, err := filepath.Abs(".repo")
if err != nil {
panic(err)
}
err = os.MkdirAll(path, 0700)
if err != nil {
panic(err)
}
repo, err := git.NewRepository(path, false)
if err != nil {
panic(err)
}
return repo, path
}
func TestCreateCL(t *testing.T) {
repo, path := createRepository()
defer repo.Free()
defer os.RemoveAll(path)
config, err := repo.Config()
if err != nil {
t.Error(err)
t.FailNow()
}
defer config.Free()
if err != nil {
t.Error(err)
t.FailNow()
}
cwd, err := os.Getwd()
if err != nil {
t.Error(err)
t.FailNow()
}
os.Chdir(path)
defer os.Chdir(cwd)
err = exec.Command("touch", "readme").Run()
if err != nil {
t.Error(err)
t.FailNow()
}
err = exec.Command("git", "add", "readme").Run()
if err != nil {
t.Error(err)
t.FailNow()
}
err = exec.Command("git", "commit", "-m", "added readme").Run()
if err != nil {
t.Error(err)
t.FailNow()
}
err = exec.Command("git", "checkout", "-b", "patch").Run()
if err != nil {
t.Error(err)
t.FailNow()
}
err = exec.Command("touch", "readme2").Run()
if err != nil {
t.Error(nil)
t.FailNow()
}
err = exec.Command("git", "add", "readme2").Run()
if err != nil {
t.Error(err)
t.FailNow()
}
err = exec.Command("git", "commit", "-m", "added readme2").Run()
if err != nil {
t.Error(err)
t.FailNow()
}
fake := fakerietveld{}
ch := ChangeManager{
crclient: &fake,
repo: repo,
}
issue, err := ch.New("master")
if err != nil {
t.Error(err)
t.FailNow()
}
expected := map[string]*rietveld.Issue{
"upload": issue,
}
if !reflect.DeepEqual(fake.actions, expected) {
t.Errorf("Should upload issue to rietveld server, but did not. Got %+v, want %+v.", fake.actions, expected)
}
}