Move health check to the backend (#2120)
This PR moves the health check to backend only leaving in the frontend the functionality to test the dbconnector datasource. Leaving the `dbconnector.testDataSource` should be fine since the datasource types we allow for db connection with Zabbix already are backend datasources, and so their health requests would go through the backend. Verified: Clicking test and seeing a `health` request go out. IMPORTANT: While testing this in the UI, I found a bug with the config editor - whenever a change is made in the UI and tested, the changes don't take effect (i.e. disabling trends, keeps `trends` set to `true`, enabling db connection keep `dbConnectionEnabled` set to `false` and so on.). Created a separate [issue](https://github.com/orgs/grafana/projects/457/views/40?pane=issue&itemId=3627315751&issue=grafana%7Coss-big-tent-squad%7C132) to fix this Fixes https://github.com/grafana/oss-big-tent-squad/issues/124 Fixes https://github.com/grafana/grafana-zabbix/issues/2004
This commit is contained in:
committed by
GitHub
parent
631d3bdc4f
commit
89ae290942
@@ -7,21 +7,12 @@ import (
|
||||
"github.com/alexanderzobnin/grafana-zabbix/pkg/settings"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
)
|
||||
|
||||
var basicDatasourceInfo = &backend.DataSourceInstanceSettings{
|
||||
ID: 1,
|
||||
Name: "TestDatasource",
|
||||
URL: "http://zabbix.org/zabbix",
|
||||
JSONData: []byte(`{"username":"username", "password":"password", "cacheTTL":"10m"}`),
|
||||
}
|
||||
|
||||
var emptyParams = map[string]interface{}{}
|
||||
|
||||
func TestLogin(t *testing.T) {
|
||||
zabbixClient, _ := MockZabbixClient(basicDatasourceInfo, `{"result":"secretauth"}`, 200)
|
||||
zabbixClient, _ := MockZabbixClient(BasicDatasourceInfo, `{"result":"secretauth"}`, 200)
|
||||
err := zabbixClient.Authenticate(context.Background())
|
||||
|
||||
assert.NoError(t, err)
|
||||
@@ -29,7 +20,7 @@ func TestLogin(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoginError(t *testing.T) {
|
||||
zabbixClient, _ := MockZabbixClient(basicDatasourceInfo, `{"result":""}`, 500)
|
||||
zabbixClient, _ := MockZabbixClient(BasicDatasourceInfo, `{"result":""}`, 500)
|
||||
err := zabbixClient.Authenticate(context.Background())
|
||||
|
||||
assert.Error(t, err)
|
||||
@@ -37,7 +28,7 @@ func TestLoginError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestZabbixAPIQuery(t *testing.T) {
|
||||
zabbixClient, _ := MockZabbixClient(basicDatasourceInfo, `{"result":"test"}`, 200)
|
||||
zabbixClient, _ := MockZabbixClient(BasicDatasourceInfo, `{"result":"test"}`, 200)
|
||||
resp, err := zabbixClient.Request(context.Background(), &ZabbixAPIRequest{Method: "test.get", Params: emptyParams})
|
||||
|
||||
assert.NoError(t, err)
|
||||
@@ -50,7 +41,7 @@ func TestZabbixAPIQuery(t *testing.T) {
|
||||
func TestCachedQuery(t *testing.T) {
|
||||
// Using methods with caching enabled
|
||||
query := &ZabbixAPIRequest{Method: "host.get", Params: emptyParams}
|
||||
zabbixClient, _ := MockZabbixClient(basicDatasourceInfo, `{"result":"testOld"}`, 200)
|
||||
zabbixClient, _ := MockZabbixClient(BasicDatasourceInfo, `{"result":"testOld"}`, 200)
|
||||
|
||||
// Run query first time
|
||||
resp, err := zabbixClient.Request(context.Background(), query)
|
||||
@@ -72,7 +63,7 @@ func TestCachedQuery(t *testing.T) {
|
||||
func TestNonCachedQuery(t *testing.T) {
|
||||
// Using methods with caching disabled
|
||||
query := &ZabbixAPIRequest{Method: "history.get", Params: emptyParams}
|
||||
zabbixClient, _ := MockZabbixClient(basicDatasourceInfo, `{"result":"testOld"}`, 200)
|
||||
zabbixClient, _ := MockZabbixClient(BasicDatasourceInfo, `{"result":"testOld"}`, 200)
|
||||
|
||||
// Run query first time
|
||||
resp, err := zabbixClient.Request(context.Background(), query)
|
||||
@@ -93,7 +84,7 @@ func TestNonCachedQuery(t *testing.T) {
|
||||
|
||||
func TestItemTagCache(t *testing.T) {
|
||||
zabbixClient, _ := MockZabbixClient(
|
||||
basicDatasourceInfo,
|
||||
BasicDatasourceInfo,
|
||||
`{"result":[{"itemid":"1","name":"test1"}]}`,
|
||||
200,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user