mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
ae09ccbf79
* Add integration with Jeager Add Jaeger datasource and modify derived fields in loki to allow for opening a trace in Jager in separate split. Modifies build so that this branch docker images are pushed to docker hub Add a traceui dir with docker-compose and provision files for demoing.:wq * Enable docker logger plugin to send logs to loki * Add placeholder zipkin datasource * Fixed rebase issues, added enhanceDataFrame to non-legacy code path * Trace selector for jaeger query field * Fix logs default mode for Loki * Fix loading jaeger query field services on split * Updated grafana image in traceui/compose file * Fix prettier error * Hide behind feature flag, clean up unused code. * Fix tests * Fix tests * Cleanup code and review feedback * Remove traceui directory * Remove circle build changes * Fix feature toggles object * Fix merge issues * Fix some null errors * Fix test after strict null changes * Review feedback fixes * Fix toggle name Co-authored-by: David Kaltschmidt <david.kaltschmidt@gmail.com>
106 lines
2.6 KiB
Go
106 lines
2.6 KiB
Go
package plugins
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
"gopkg.in/ini.v1"
|
|
)
|
|
|
|
func TestDashboardImport(t *testing.T) {
|
|
pluginScenario("When importing a plugin dashboard", t, func() {
|
|
origNewDashboardService := dashboards.NewService
|
|
mock := &dashboards.FakeDashboardService{}
|
|
dashboards.MockDashboardService(mock)
|
|
|
|
cmd := ImportDashboardCommand{
|
|
PluginId: "test-app",
|
|
Path: "dashboards/connections.json",
|
|
OrgId: 1,
|
|
User: &models.SignedInUser{UserId: 1, OrgRole: models.ROLE_ADMIN},
|
|
Inputs: []ImportDashboardInput{
|
|
{Name: "*", Type: "datasource", Value: "graphite"},
|
|
},
|
|
}
|
|
|
|
err := ImportDashboard(&cmd)
|
|
So(err, ShouldBeNil)
|
|
|
|
Convey("should install dashboard", func() {
|
|
So(cmd.Result, ShouldNotBeNil)
|
|
|
|
resultStr, _ := mock.SavedDashboards[0].Dashboard.Data.EncodePretty()
|
|
expectedBytes, _ := ioutil.ReadFile("testdata/test-app/dashboards/connections_result.json")
|
|
expectedJson, _ := simplejson.NewJson(expectedBytes)
|
|
expectedStr, _ := expectedJson.EncodePretty()
|
|
|
|
So(string(resultStr), ShouldEqual, string(expectedStr))
|
|
|
|
panel := mock.SavedDashboards[0].Dashboard.Data.Get("rows").GetIndex(0).Get("panels").GetIndex(0)
|
|
So(panel.Get("datasource").MustString(), ShouldEqual, "graphite")
|
|
})
|
|
|
|
Reset(func() {
|
|
dashboards.NewService = origNewDashboardService
|
|
})
|
|
})
|
|
|
|
Convey("When evaling dashboard template", t, func() {
|
|
template, _ := simplejson.NewJson([]byte(`{
|
|
"__inputs": [
|
|
{
|
|
"name": "DS_NAME",
|
|
"type": "datasource"
|
|
}
|
|
],
|
|
"test": {
|
|
"prop": "${DS_NAME}"
|
|
}
|
|
}`))
|
|
|
|
evaluator := &DashTemplateEvaluator{
|
|
template: template,
|
|
inputs: []ImportDashboardInput{
|
|
{Name: "*", Type: "datasource", Value: "my-server"},
|
|
},
|
|
}
|
|
|
|
res, err := evaluator.Eval()
|
|
So(err, ShouldBeNil)
|
|
|
|
Convey("should render template", func() {
|
|
So(res.GetPath("test", "prop").MustString(), ShouldEqual, "my-server")
|
|
})
|
|
|
|
Convey("should not include inputs in output", func() {
|
|
inputs := res.Get("__inputs")
|
|
So(inputs.Interface(), ShouldBeNil)
|
|
})
|
|
|
|
})
|
|
}
|
|
|
|
func pluginScenario(desc string, t *testing.T, fn func()) {
|
|
Convey("Given a plugin", t, func() {
|
|
setting.Raw = ini.Empty()
|
|
sec, _ := setting.Raw.NewSection("plugin.test-app")
|
|
_, err := sec.NewKey("path", "testdata/test-app")
|
|
So(err, ShouldBeNil)
|
|
|
|
pm := &PluginManager{
|
|
Cfg: &setting.Cfg{
|
|
FeatureToggles: map[string]bool{},
|
|
},
|
|
}
|
|
err = pm.Init()
|
|
So(err, ShouldBeNil)
|
|
|
|
Convey(desc, fn)
|
|
})
|
|
}
|