forked from grafana-tools/sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rest-datasource_integration_test.go
74 lines (62 loc) · 1.57 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
70
71
72
73
74
package sdk_test
import (
"context"
"fmt"
"testing"
sdk "github.com/kubermatic/grafanasdk"
"github.com/stretchr/testify/assert"
)
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)
}
assert.Equal(t, dsRetrieved.Name, ds.Name, fmt.Sprintf("got wrong name: expected %s, was %s", dsRetrieved.Name, ds.Name))
//assert.NotNilf(t)
ds.Name = "elasticsdksource"
ds.ID = dsRetrieved.ID
ds.UID = "ZrY0GDS7z"
readOnly := false
ds.ReadOnly = &readOnly
ds.TypeLogoURL = "www.duckduckgo.com"
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")
}
}