forked from grafana-tools/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest-datasource_integration_test.go
69 lines (57 loc) · 1.38 KB
/
rest-datasource_integration_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
package sdk_test
import (
"context"
"testing"
"github.com/grafana-tools/sdk"
)
func Test_Datasource_CRUD(t *testing.T) {
shouldSkip(t)
client := getClient(t)
ctx := context.Background()
datasources, err := client.GetAllDatasources(ctx)
if err != nil {
t.Fatal(err)
}
if len(datasources) != 0 {
t.Fatalf("expected to get zero datasources, got %#v", datasources)
}
db := "grafanasdk"
ds := sdk.Datasource{
Name: "elastic_datasource",
Type: "elasticsearch",
IsDefault: false,
Database: &db,
URL: "http://1.2.3.4",
Access: "direct",
JSONData: map[string]string{
"esVersion": "5",
"timeField": "@timestamp",
"maxConcurrentShardRequests": "256",
},
}
status, err := client.CreateDatasource(ctx, ds)
if err != nil {
t.Fatal(err)
}
dsRetrieved, err := client.GetDatasource(ctx, uint(*status.ID))
if err != nil {
t.Fatal(err)
}
if dsRetrieved.Name != ds.Name {
t.Fatalf("got wrong name: expected %s, was %s", dsRetrieved.Name, ds.Name)
}
ds.Name = "elasticsdksource"
ds.ID = dsRetrieved.ID
status, err = client.UpdateDatasource(ctx, ds)
if err != nil {
t.Fatal(err)
}
_, err = client.DeleteDatasourceByName(ctx, "elasticsdksource")
if err != nil {
t.Fatal(err)
}
_, err = client.GetDatasource(ctx, uint(*status.ID))
if err == nil {
t.Fatalf("expected the datasource to be deleted")
}
}