forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_test.go
144 lines (129 loc) · 2.54 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
136
137
138
139
140
141
142
143
144
package gapi
import (
"testing"
"time"
"github.com/gobs/pretty"
)
var (
getReportJSON = `
{
"id": 4,
"userId": 0,
"orgId": 1,
"dashboards": [
{
"dashboard": {
"id": 33,
"uid": "nErXDvCkzz",
"name": "Terraform Acceptance Test"
},
"timeRange": {
"from": "now-1h",
"to": "now"
}
}
],
"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"
},
"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{
Name: "My Report",
Recipients: "test@test.com",
Schedule: ReportSchedule{
StartDate: &now,
EndDate: nil,
Frequency: "custom",
IntervalFrequency: "weeks",
IntervalAmount: 2,
WorkdaysOnly: true,
TimeZone: "GMT",
},
Dashboards: []ReportDashboard{
{
Dashboard: ReportDashboardIdentifier{
ID: 33,
UID: "nErXDvCkzz",
},
TimeRange: ReportDashboardTimeRange{
From: "now-1h",
To: "now",
},
},
},
Options: ReportOptions{
Orientation: "landscape",
Layout: "grid",
},
EnableDashboardURL: true,
EnableCSV: true,
}
)
func TestReport(t *testing.T) {
client := gapiTestTools(t, 200, getReportJSON)
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) {
client := gapiTestTools(t, 200, createReportJSON)
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) {
client := gapiTestTools(t, 200, "")
err := client.UpdateReport(testReport)
if err != nil {
t.Fatal(err)
}
}
func TestDeleteReport(t *testing.T) {
client := gapiTestTools(t, 200, "")
err := client.DeleteReport(4)
if err != nil {
t.Fatal(err)
}
}