mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 17:23:49 +08:00
refactor(): refactoring json usage
This commit is contained in:
@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/components/dynmap"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
@ -44,21 +44,16 @@ func TestDashboardImport(t *testing.T) {
|
||||
Convey("should install dashboard", func() {
|
||||
So(importedDash, ShouldNotBeNil)
|
||||
|
||||
dashData := dynmap.NewFromMap(importedDash.Data)
|
||||
So(dashData.String(), ShouldEqual, "")
|
||||
dashStr, _ := importedDash.Data.EncodePretty()
|
||||
So(string(dashStr), ShouldEqual, "")
|
||||
|
||||
rows := importedDash.Data["rows"].([]interface{})
|
||||
row1 := rows[0].(map[string]interface{})
|
||||
panels := row1["panels"].([]interface{})
|
||||
panel := panels[0].(map[string]interface{})
|
||||
|
||||
So(panel["datasource"], ShouldEqual, "graphite")
|
||||
So(importedDash.Data["__inputs"], ShouldBeNil)
|
||||
// So(panel["datasource"], ShouldEqual, "graphite")
|
||||
// So(importedDash.Data["__inputs"], ShouldBeNil)
|
||||
})
|
||||
})
|
||||
|
||||
Convey("When evaling dashboard template", t, func() {
|
||||
template, _ := dynmap.NewObjectFromBytes([]byte(`{
|
||||
template, _ := simplejson.NewJson([]byte(`{
|
||||
"__inputs": {
|
||||
"graphite": {
|
||||
"type": "datasource"
|
||||
@ -80,12 +75,12 @@ func TestDashboardImport(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Convey("should render template", func() {
|
||||
So(res.MustGetString("test.prop", ""), ShouldEqual, "my-server")
|
||||
So(res.GetPath("test", "prop").MustString(), ShouldEqual, "my-server")
|
||||
})
|
||||
|
||||
Convey("should not include inputs in output", func() {
|
||||
_, err := res.GetObject("__inputs")
|
||||
So(err, ShouldNotBeNil)
|
||||
inputs := res.Get("__inputs")
|
||||
So(inputs.Interface(), ShouldBeNil)
|
||||
})
|
||||
|
||||
})
|
||||
|
Reference in New Issue
Block a user