-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathissue_test.go
164 lines (134 loc) · 3.75 KB
/
issue_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
package sentry
import (
"fmt"
"testing"
raven "github.com/getsentry/sentry-go"
)
func createMessagesHelper(t *testing.T, client *Client, org Organization, project Project, numOfMessages int) {
dsnkey, err := client.CreateClientKey(org, project, "testing key")
if err != nil {
t.Fatal(err)
}
scope := raven.NewScope()
scope.SetExtra("server", "app-node-01")
ravenClient, err := raven.NewClient(raven.ClientOptions{
Dsn: dsnkey.DSN.Secret,
Transport: raven.NewHTTPSyncTransport(),
})
hub := raven.NewHub(ravenClient, scope)
if err != nil {
t.Fatal(err)
}
for i := 0; i <= numOfMessages; i++ {
hub.CaptureMessage(fmt.Sprintf("failed to execute on id %d", i))
}
}
func TestIssueResource(t *testing.T) {
client := newTestClient(t)
org, err := client.GetOrganization(getDefaultOrg())
if err != nil {
t.Fatal(err)
}
team, cleanup := createTeamHelper(t)
defer cleanup()
project, cleanupproj := createProjectHelper(t, team)
defer cleanupproj()
createMessagesHelper(t, client, org, project, 10)
t.Run("Get all issues with a query of resolved", func(t *testing.T) {
query := "is:resolved"
issues, _, err := client.GetIssues(org, project, nil, nil, &query)
if err != nil {
t.Error(err)
}
if len(issues) >= 1 {
t.Error("Should have not had any issues marked as resolved")
}
})
t.Run("Get all issues for a project", func(t *testing.T) {
issues, link, err := client.GetIssues(org, project, nil, nil, nil)
if err != nil {
t.Error(err)
}
if len(issues) <= 0 {
t.Fatal("No issues found for this project")
}
if link.Previous.Results {
t.Error("Should be no new results")
}
t.Run("Get issues with statsPeriod of 14 days", func(t *testing.T) {
period := "14d"
issues, _, err := client.GetIssues(org, project, &period, nil, nil)
if err != nil {
t.Error(err)
}
if len(issues) <= 0 {
t.Fatal("No issues found for this project")
}
for _, issue := range issues {
if issue.Stats.FourteenDays == nil {
t.Fatal("We should be able to get 14 days of stats for this issue but didn't")
}
}
})
t.Run("Get hashes for issue", func(t *testing.T) {
hashes, link, err := client.GetIssueHashes(issues[0])
if err != nil {
t.Error(err)
}
if len(hashes) == 0 {
t.Error("Should be at least one hash in list")
}
if link.Next.Results {
t.Error("Should not be any other results but there is some")
}
})
t.Run("Get the issue only", func(t *testing.T) {
issue, err := client.GetIssue(*issues[0].ID)
if err != nil {
t.Errorf("Failed to get issue: %s", err)
}
if *issue.ID != *issues[0].ID {
t.Error("Somehow not the same ID? How is this possible")
}
})
t.Run("Get events for this issue", func(t *testing.T) {
events, _, err := client.GetIssueEvents(issues[0])
if err != nil {
t.Error(err)
}
if len(events) == 0 {
t.Errorf("Should be at least more than 1 event %v", events)
}
})
t.Run("Modify first issue found in project", func(t *testing.T) {
firstIssue := issues[0]
resolved := Resolved
firstIssue.Status = &resolved
firstIssue.StatusDetails = &map[string]interface{}{
"inNextRelease": true,
}
if err := client.UpdateIssue(firstIssue); err != nil {
t.Error(err)
}
if *firstIssue.Status != Resolved {
t.Error("Status did not get updated")
}
details, ok := (*firstIssue.StatusDetails)["inNextRelease"].(bool)
if !ok {
t.Error("Status details did not get updated")
}
if !details {
t.Error("Status details did not get updated")
}
t.Run("Delete the first issue in this project", func(t *testing.T) {
err := client.DeleteIssue(firstIssue)
if err != nil {
t.Error(err)
}
})
})
})
if err := client.DeleteTeam(org, team); err != nil {
t.Error(err)
}
}