refactor(): refactoring json usage

This commit is contained in:
Torkel Ödegaard
2016-03-12 00:13:06 +01:00
parent 40b2f00dc5
commit 3fb0b71822
8 changed files with 68 additions and 86 deletions

View File

@ -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)
})
})