This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
/
datasource_cache_test.go
84 lines (76 loc) · 2.02 KB
/
datasource_cache_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
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
getDatasourceCacheJSON = `
{
"message": "Data source cache settings loaded",
"dataSourceID": 1,
"dataSourceUID": "jZrmlLCGka",
"enabled": true,
"useDefaultTTL": false,
"ttlQueriesMs": 60000,
"ttlResourcesMs": 300000,
"defaultTTLMs": 300000,
"created": "2023-04-21T11:49:22-04:00",
"updated": "2023-04-24T17:03:40-04:00"
}`
updateDatasourceCacheJSON = `
{
"message": "Data source cache settings updated",
"dataSourceID": 1,
"dataSourceUID": "jZrmlLCGka",
"enabled": true,
"useDefaultTTL": false,
"ttlQueriesMs": 60000,
"ttlResourcesMs": 300000,
"defaultTTLMs": 300000,
"created": "2023-04-21T11:49:22-04:00",
"updated": "2023-04-24T17:03:40-04:00"
}`
)
func TestDatasourceCache(t *testing.T) {
client := gapiTestTools(t, 200, getDatasourceCacheJSON)
resp, err := client.DatasourceCache(1)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
expects := DatasourceCache{
Message: "Data source cache settings loaded",
DatasourceID: 1,
DatasourceUID: "jZrmlLCGka",
Enabled: true,
UseDefaultTLS: false,
TTLQueriesMs: 60000,
TTLResourcesMs: 300000,
DefaultTTLMs: 300000,
Created: "2023-04-21T11:49:22-04:00",
Updated: "2023-04-24T17:03:40-04:00",
}
if resp.Enabled != expects.Enabled ||
resp.DatasourceUID != expects.DatasourceUID ||
resp.UseDefaultTLS != expects.UseDefaultTLS ||
resp.TTLQueriesMs != expects.TTLQueriesMs ||
resp.TTLResourcesMs != expects.TTLResourcesMs ||
resp.DefaultTTLMs != expects.DefaultTTLMs {
t.Error("Not correctly parsing returned datasource cache")
}
}
func TestUpdateDatasourceCache(t *testing.T) {
client := gapiTestTools(t, 200, updateDatasourceCacheJSON)
payload := &DatasourceCachePayload{
DatasourceID: 1,
DatasourceUID: "jZrmlLCGka",
Enabled: true,
UseDefaultTLS: true,
TTLQueriesMs: 6000,
TTLResourcesMs: 30000,
}
err := client.UpdateDatasourceCache(1, payload)
if err != nil {
t.Error(err)
}
}