forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_test.go
135 lines (120 loc) · 2.49 KB
/
report_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
package gapi
import (
"testing"
"time"
"github.com/gobs/pretty"
)
var (
getReportJSON = `
{
"id": 4,
"userId": 0,
"orgId": 1,
"dashboardId": 33,
"dashboardName": "Terraform Acceptance Test",
"dashboardUid": "",
"name": "My Report",
"recipients": "test@test.com",
"replyTo": "",
"message": "",
"schedule": {
"startDate": "2020-01-01T00:00:00Z",
"endDate": null,
"frequency": "custom",
"intervalFrequency": "weeks",
"intervalAmount": 2,
"workdaysOnly": true,
"dayOfMonth": "1",
"day": "wednesday",
"hour": 0,
"minute": 0,
"timeZone": "GMT"
},
"options": {
"orientation": "landscape",
"layout": "grid",
"timeRange": {
"from": "now-1h",
"to": "now"
}
},
"templateVars": {},
"enableDashboardUrl": true,
"enableCsv": true,
"state": "",
"created": "2022-01-11T15:09:13Z",
"updated": "2022-01-11T16:18:34Z"
}
`
createReportJSON = `
{
"id": 4
}
`
now = time.Now()
testReport = Report{
DashboardID: 33,
Name: "My Report",
Recipients: "test@test.com",
Schedule: ReportSchedule{
StartDate: &now,
EndDate: nil,
Frequency: "custom",
IntervalFrequency: "weeks",
IntervalAmount: 2,
WorkdaysOnly: true,
TimeZone: "GMT",
},
Options: ReportOptions{
Orientation: "landscape",
Layout: "grid",
TimeRange: ReportTimeRange{
From: "now-1h",
To: "now",
},
},
EnableDashboardURL: true,
EnableCSV: true,
}
)
func TestReport(t *testing.T) {
server, client := gapiTestTools(t, 200, getReportJSON)
defer server.Close()
report := int64(4)
resp, err := client.Report(report)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
if resp.ID != report || resp.Name != "My Report" {
t.Error("Not correctly parsing returned report.")
}
}
func TestNewReport(t *testing.T) {
server, client := gapiTestTools(t, 200, createReportJSON)
defer server.Close()
resp, err := client.NewReport(testReport)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
if resp != 4 {
t.Error("Not correctly parsing returned creation message.")
}
}
func TestUpdateReport(t *testing.T) {
server, client := gapiTestTools(t, 200, "")
defer server.Close()
err := client.UpdateReport(testReport)
if err != nil {
t.Fatal(err)
}
}
func TestDeleteReport(t *testing.T) {
server, client := gapiTestTools(t, 200, "")
defer server.Close()
err := client.DeleteReport(4)
if err != nil {
t.Fatal(err)
}
}