This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
datasource_test.go
75 lines (62 loc) · 1.57 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
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
createdDataSourceJSON = `{"id":1,"message":"Datasource added", "name": "test_datasource"}`
)
func TestNewDataSource(t *testing.T) {
server, client := gapiTestTools(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.Error(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(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.Error(err)
}
t.Log(pretty.PrettyFormat(created))
if created != 1 {
t.Error("datasource creation response should return the created datasource ID")
}
}