2021-09-10 09:44:47 -05:00
|
|
|
package grafanads
|
|
|
|
|
|
|
|
import (
|
2021-12-14 08:22:40 -06:00
|
|
|
"context"
|
2021-09-10 09:44:47 -05:00
|
|
|
"encoding/json"
|
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
|
2021-11-01 04:53:33 -05:00
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
2021-09-10 09:44:47 -05:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
2021-12-14 08:22:40 -06:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2021-09-10 09:44:47 -05:00
|
|
|
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/experimental"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func asJSON(v interface{}) json.RawMessage {
|
|
|
|
b, _ := json.Marshal(v)
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadFolderListing(t *testing.T) {
|
2021-12-14 08:22:40 -06:00
|
|
|
ds := newService(&setting.Cfg{StaticRootPath: "../../../public"}, &fakePluginStore{})
|
2021-09-10 09:44:47 -05:00
|
|
|
dr := ds.doListQuery(backend.DataQuery{
|
|
|
|
QueryType: "x",
|
|
|
|
JSON: asJSON(listQueryModel{
|
|
|
|
Path: "testdata",
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
err := experimental.CheckGoldenDataResponse(path.Join("testdata", "list.golden.txt"), &dr, true)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadCSVFile(t *testing.T) {
|
2021-12-14 08:22:40 -06:00
|
|
|
ds := newService(&setting.Cfg{StaticRootPath: "../../../public"}, &fakePluginStore{})
|
2021-09-10 09:44:47 -05:00
|
|
|
dr := ds.doReadQuery(backend.DataQuery{
|
|
|
|
QueryType: "x",
|
|
|
|
JSON: asJSON(readQueryModel{
|
|
|
|
Path: "testdata/js_libraries.csv",
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
err := experimental.CheckGoldenDataResponse(path.Join("testdata", "jslib.golden.txt"), &dr, true)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2021-12-14 08:22:40 -06:00
|
|
|
type fakePluginStore struct {
|
|
|
|
plugins.Store
|
2021-09-10 09:44:47 -05:00
|
|
|
}
|
|
|
|
|
2021-12-14 08:22:40 -06:00
|
|
|
func (ps *fakePluginStore) AddWithFactory(_ context.Context, _ string, _ backendplugin.PluginFactoryFunc, _ plugins.PluginPathResolver) error {
|
2021-09-10 09:44:47 -05:00
|
|
|
return nil
|
|
|
|
}
|