-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclient_test.go
86 lines (67 loc) · 2.05 KB
/
client_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
package gong
import (
"fmt"
. "gopkg.in/check.v1"
"testing"
)
func TestClient(t *testing.T) { TestingT(t) }
type ClientSuite struct{}
var _ = Suite(&ClientSuite{})
type FakeClient struct{}
func (f *FakeClient) FormatField(fieldName string, value string) string {
return ""
}
func (f *FakeClient) GetAuthFields() map[string]bool {
return map[string]bool{}
}
func (f *FakeClient) GetName() string {
return "fakeclient"
}
func (f *FakeClient) Authenticate(field map[string]string) bool {
return false
}
func (f *FakeClient) Start(issueType, issueID string) (string, error) {
return fmt.Sprintf("%s/%s", issueType, issueID), nil
}
func (f *FakeClient) Browse(branchName string) (string, error) {
return "https://www.fake.com/FAKE-1111", nil
}
func (f *FakeClient) Comment(branchName, comment string) error {
return nil
}
func (f *FakeClient) PrepareCommitMessage(branchName, commitMessage string) string {
return "Fake commit message"
}
func (f *FakeClient) Create() (string, error) {
return "This is the URL", nil
}
func (s *ClientSuite) TestClientStartIssue(c *C) {
client := &FakeClient{}
branchName, _ := Start(client, "feature", "111")
c.Assert(branchName, Equals, "feature/111")
}
func (s *ClientSuite) TestBrowse(c *C) {
client := &FakeClient{}
branchName := "feature/FAKE-1111-some-issue-title"
url, _ := Browse(client, branchName)
c.Assert(url, Equals, "https://www.fake.com/FAKE-1111")
}
func (s *ClientSuite) TestComment(c *C) {
client := &FakeClient{}
branchName := "feature/FAKE-1111-some-issue-title"
comment := "This is a sample comment"
err := Comment(client, branchName, comment)
c.Assert(err, Equals, nil)
}
func (s *ClientSuite) TestPrepareCommitMessage(c *C) {
client := &FakeClient{}
branchName := "feature/FAKE-1111-some-issue-title"
commitMessage := "This is a sample comment"
newMessage := PrepareCommitMessage(client, branchName, commitMessage)
c.Assert(newMessage, Equals, "Fake commit message")
}
func (s *ClientSuite) TestCreate(c *C) {
client := &FakeClient{}
url, _ := Create(client)
c.Assert(url, Equals, "This is the URL")
}