forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatasource_test.go
140 lines (117 loc) · 3.07 KB
/
datasource_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
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
createdDataSourceJSON = `{"id":1,"uid":"myuid0001","message":"Datasource added", "name": "test_datasource"}`
)
func TestNewDataSource(t *testing.T) {
server, client := gapiTestTools(t, 200, createdDataSourceJSON)
defer server.Close()
ds := &DataSource{
Name: "foo",
Type: "cloudwatch",
URL: "http://some-url.com",
Access: "access",
IsDefault: true,
JSONData: JSONData{
AssumeRoleArn: "arn:aws:iam::123:role/some-role",
AuthType: "keys",
CustomMetricsNamespaces: "SomeNamespace",
DefaultRegion: "us-east-1",
TLSSkipVerify: true,
},
SecureJSONData: SecureJSONData{
AccessKey: "123",
SecretKey: "456",
},
}
created, err := client.NewDataSource(ds)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(created))
if created != 1 {
t.Error("datasource creation response should return the created datasource ID")
}
}
func TestNewPrometheusDataSource(t *testing.T) {
server, client := gapiTestTools(t, 200, createdDataSourceJSON)
defer server.Close()
ds := &DataSource{
Name: "foo_prometheus",
Type: "prometheus",
URL: "http://some-url.com",
Access: "access",
IsDefault: true,
JSONData: JSONData{
HTTPMethod: "POST",
QueryTimeout: "60s",
TimeInterval: "1m",
},
}
created, err := client.NewDataSource(ds)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(created))
if created != 1 {
t.Error("datasource creation response should return the created datasource ID")
}
}
func TestNewPrometheusSigV4DataSource(t *testing.T) {
server, client := gapiTestTools(t, 200, createdDataSourceJSON)
defer server.Close()
ds := &DataSource{
Name: "sigv4_prometheus",
Type: "prometheus",
URL: "http://some-url.com",
Access: "access",
IsDefault: true,
JSONData: JSONData{
HTTPMethod: "POST",
SigV4Auth: true,
SigV4AuthType: "keys",
SigV4Region: "us-east-1",
},
SecureJSONData: SecureJSONData{
SigV4AccessKey: "123",
SigV4SecretKey: "456",
},
}
created, err := client.NewDataSource(ds)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(created))
if created != 1 {
t.Error("datasource creation response should return the created datasource ID")
}
}
func TestNewElasticsearchDataSource(t *testing.T) {
server, client := gapiTestTools(t, 200, createdDataSourceJSON)
defer server.Close()
ds := &DataSource{
Name: "foo_elasticsearch",
Type: "elasticsearch",
URL: "http://some-url.com",
IsDefault: true,
JSONData: JSONData{
EsVersion: "7.0.0",
TimeField: "time",
Interval: "1m",
LogMessageField: "message",
LogLevelField: "field",
MaxConcurrentShardRequests: 8,
},
}
created, err := client.NewDataSource(ds)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(created))
if created != 1 {
t.Error("datasource creation response should return the created datasource ID")
}
}