diff --git a/pkg/models/dashboards.go b/pkg/models/dashboards.go index 863e2275f90..cdcc4d52364 100644 --- a/pkg/models/dashboards.go +++ b/pkg/models/dashboards.go @@ -49,7 +49,7 @@ func NewDashboard(title string) *Dashboard { // GetTags turns the tags in data json into go string array func (dash *Dashboard) GetTags() []string { jsonTags := dash.Data["tags"] - if jsonTags == nil { + if jsonTags == nil || jsonTags == "" { return []string{} } diff --git a/pkg/models/dashboard_test.go b/pkg/models/dashboards_test.go similarity index 53% rename from pkg/models/dashboard_test.go rename to pkg/models/dashboards_test.go index 0828e51480f..b0b6796c4d8 100644 --- a/pkg/models/dashboard_test.go +++ b/pkg/models/dashboards_test.go @@ -15,4 +15,17 @@ func TestDashboardModel(t *testing.T) { So(dashboard.Slug, ShouldEqual, "grafana-play-home") }) + Convey("Given a dashboard json", t, func() { + json := map[string]interface{}{ + "title": "test dash", + } + + Convey("With tags as string value", func() { + json["tags"] = "" + dash := NewDashboardFromJson(json) + + So(len(dash.GetTags()), ShouldEqual, 0) + }) + }) + }