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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package gapi | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type DatasourceCache struct { | ||
Message string `json:"message"` | ||
DatasourceID int64 `json:"dataSourceID"` | ||
DatasourceUID string `json:"dataSourceUID"` | ||
Enabled bool `json:"enabled"` | ||
TTLQueriesMs int64 `json:"ttlQueriesMs"` | ||
TTLResourcesMs int64 `json:"ttlResourcesMs"` | ||
UseDefaultTLS bool `json:"useDefaultTTL"` | ||
DefaultTTLMs int64 `json:"defaultTTLMs"` | ||
Created string `json:"created"` | ||
Updated string `json:"updated"` | ||
} | ||
|
||
// DatasourceCache fetch datasource cache configuration | ||
func (c *Client) DatasourceCache(id int64) (*DatasourceCache, error) { | ||
path := fmt.Sprintf("/api/datasources/%d/cache", id) | ||
cache := &DatasourceCache{} | ||
err := c.request("GET", path, nil, nil, cache) | ||
if err != nil { | ||
return cache, fmt.Errorf("error getting cache at %s: %w", path, err) | ||
} | ||
return cache, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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" | ||
}` | ||
) | ||
|
||
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", | ||
} | ||
|
||
t.Run("check data", func(t *testing.T) { | ||
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") | ||
} | ||
}) | ||
} |