-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredmine_test.go
153 lines (137 loc) · 3.31 KB
/
redmine_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
package redmine
import (
"testing"
"github.com/rs/zerolog"
)
func TestNew(t *testing.T) {
logger := zerolog.New(nil)
api := &mockAPI{projectID: 123, userID: 456}
r, err := New(
withAPI(api),
WithLog(&logger),
WithHost("https://redmine.example.com"),
WithAPIKey("your_api_key"),
WithProjectIdentifier("my-project"),
WithTrackerID(1),
WithWaitingForOperatorStatusID(1),
WithWaitingForCustomerStatusID(2),
WithDoneStatusID(3),
)
if err != nil {
t.Fatalf("Expected no error, but got %v", err)
}
if r == nil {
t.Fatal("Expected Redmine client, but got nil")
}
if r.cfg.ProjectID != 123 {
t.Errorf("Expected ProjectID to be 123, but got %d", r.cfg.ProjectID)
}
if r.cfg.UserID != 456 {
t.Errorf("Expected UserID to be 456, but got %d", r.cfg.UserID)
}
}
func TestNewIssue(t *testing.T) {
logger := zerolog.New(nil)
r, _ := New(
WithLog(&logger),
WithHost("https://redmine.example.com"),
WithAPIKey("your_api_key"),
WithProjectID(123),
WithUserID(456),
WithTrackerID(1),
WithWaitingForOperatorStatusID(1),
WithWaitingForCustomerStatusID(2),
WithDoneStatusID(3),
)
r.cfg.api = &mockAPI{}
issueID, err := r.NewIssue("Test Issue", "email", "[email protected]", "This is a test issue.")
if err != nil {
t.Fatalf("Expected no error, but got %v", err)
}
if issueID != 123 {
t.Errorf("Expected issue ID to be 123, but got %d", issueID)
}
}
func TestUpdateIssue(t *testing.T) {
logger := zerolog.New(nil)
r, _ := New(
WithLog(&logger),
WithHost("https://redmine.example.com"),
WithAPIKey("your_api_key"),
WithProjectID(123),
WithUserID(456),
WithTrackerID(1),
WithWaitingForOperatorStatusID(1),
WithWaitingForCustomerStatusID(2),
WithDoneStatusID(3),
)
r.cfg.api = &mockAPI{}
statusID := r.StatusToID(Done)
err := r.UpdateIssue(123, statusID, "Closing issue.")
if err != nil {
t.Fatalf("Expected no error, but got %v", err)
}
}
func TestIsClosed(t *testing.T) {
logger := zerolog.New(nil)
r, _ := New(
WithLog(&logger),
WithHost("https://redmine.example.com"),
WithAPIKey("your_api_key"),
WithProjectID(123),
WithUserID(456),
WithTrackerID(1),
WithWaitingForOperatorStatusID(1),
WithWaitingForCustomerStatusID(2),
WithDoneStatusID(3),
)
r.cfg.api = &mockAPI{}
closed, err := r.IsClosed(123)
if err != nil {
t.Fatalf("Expected no error, but got %v", err)
}
if !closed {
t.Error("Expected issue to be closed, but it was not")
}
}
func TestGetNotes(t *testing.T) {
logger := zerolog.New(nil)
r, _ := New(
WithLog(&logger),
WithHost("https://redmine.example.com"),
WithAPIKey("your_api_key"),
WithProjectID(123),
WithUserID(456),
WithTrackerID(1),
WithWaitingForOperatorStatusID(1),
WithWaitingForCustomerStatusID(2),
WithDoneStatusID(3),
)
r.cfg.api = &mockAPI{}
notes, err := r.GetNotes(123)
if err != nil {
t.Fatalf("Expected no error, but got %v", err)
}
if notes != nil {
t.Errorf("Expected no notes, but got %v", notes)
}
}
func TestRedmineShutdown(_ *testing.T) {
logger := zerolog.New(nil)
r, _ := New(
WithLog(&logger),
WithHost("https://redmine.example.com"),
WithAPIKey("your_api_key"),
WithProjectID(123),
WithUserID(456),
WithTrackerID(1),
WithWaitingForOperatorStatusID(1),
WithWaitingForCustomerStatusID(2),
WithDoneStatusID(3),
)
r.wg.Add(1)
go func() {
defer r.wg.Done()
}()
r.Shutdown()
}