Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit 23dda90

Browse files
Add test
1 parent a44616e commit 23dda90

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

report_test.go

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package gapi
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/gobs/pretty"
8+
)
9+
10+
var (
11+
getReportJSON = `
12+
{
13+
"id": 4,
14+
"userId": 0,
15+
"orgId": 1,
16+
"dashboardId": 33,
17+
"dashboardName": "Terraform Acceptance Test",
18+
"dashboardUid": "",
19+
"name": "My Report",
20+
"recipients": "test@test.com",
21+
"replyTo": "",
22+
"message": "",
23+
"schedule": {
24+
"startDate": "2020-01-01T00:00:00Z",
25+
"endDate": null,
26+
"frequency": "custom",
27+
"intervalFrequency": "weeks",
28+
"intervalAmount": 2,
29+
"workdaysOnly": true,
30+
"dayOfMonth": "1",
31+
"day": "wednesday",
32+
"hour": 0,
33+
"minute": 0,
34+
"timeZone": "GMT"
35+
},
36+
"options": {
37+
"orientation": "landscape",
38+
"layout": "grid",
39+
"timeRange": {
40+
"from": "now-1h",
41+
"to": "now"
42+
}
43+
},
44+
"templateVars": {},
45+
"enableDashboardUrl": true,
46+
"enableCsv": true,
47+
"state": "",
48+
"created": "2022-01-11T15:09:13Z",
49+
"updated": "2022-01-11T16:18:34Z"
50+
}
51+
`
52+
createReportJSON = `
53+
{
54+
"id": 4
55+
}
56+
`
57+
now = time.Now()
58+
testReport = Report{
59+
DashboardID: 33,
60+
Name: "My Report",
61+
Recipients: "test@test.com",
62+
Schedule: ReportSchedule{
63+
StartDate: &now,
64+
EndDate: nil,
65+
Frequency: "custom",
66+
IntervalFrequency: "weeks",
67+
IntervalAmount: 2,
68+
WorkdaysOnly: true,
69+
TimeZone: "GMT",
70+
},
71+
Options: ReportOptions{
72+
Orientation: "landscape",
73+
Layout: "grid",
74+
TimeRange: ReportTimeRange{
75+
From: "now-1h",
76+
To: "now",
77+
},
78+
},
79+
EnableDashboardURL: true,
80+
EnableCSV: true,
81+
}
82+
)
83+
84+
func TestReport(t *testing.T) {
85+
server, client := gapiTestTools(t, 200, getReportJSON)
86+
defer server.Close()
87+
88+
report := int64(4)
89+
resp, err := client.Report(report)
90+
if err != nil {
91+
t.Fatal(err)
92+
}
93+
94+
t.Log(pretty.PrettyFormat(resp))
95+
96+
if resp.ID != report || resp.Name != "My Report" {
97+
t.Error("Not correctly parsing returned report.")
98+
}
99+
}
100+
101+
func TestNewReport(t *testing.T) {
102+
server, client := gapiTestTools(t, 200, createReportJSON)
103+
defer server.Close()
104+
105+
resp, err := client.NewReport(testReport)
106+
if err != nil {
107+
t.Fatal(err)
108+
}
109+
110+
t.Log(pretty.PrettyFormat(resp))
111+
112+
if resp != 4 {
113+
t.Error("Not correctly parsing returned creation message.")
114+
}
115+
}
116+
117+
func TestUpdateReport(t *testing.T) {
118+
server, client := gapiTestTools(t, 200, "")
119+
defer server.Close()
120+
121+
err := client.UpdateReport(testReport)
122+
if err != nil {
123+
t.Fatal(err)
124+
}
125+
}
126+
127+
func TestDeleteReport(t *testing.T) {
128+
server, client := gapiTestTools(t, 200, "")
129+
defer server.Close()
130+
131+
err := client.DeleteReport(4)
132+
if err != nil {
133+
t.Fatal(err)
134+
}
135+
}

0 commit comments

Comments
 (0)