Commit 34d7f8a4 by bergquist

dashboards as cfg: property path replaces folder

parent 18350796
......@@ -34,9 +34,15 @@ type fileReader struct {
}
func NewDashboardFileReader(cfg *DashboardsAsConfig, log log.Logger) (*fileReader, error) {
path, ok := cfg.Options["folder"].(string)
var path string
path, ok := cfg.Options["path"].(string)
if !ok {
return nil, fmt.Errorf("Failed to load dashboards. folder param is not a string")
path, ok = cfg.Options["folder"].(string)
if !ok {
return nil, fmt.Errorf("Failed to load dashboards. path param is not a string")
}
log.Warn("[Deprecated] The folder property is deprecated. Please use path instead.")
}
if _, err := os.Stat(path); os.IsNotExist(err) {
......
......@@ -42,7 +42,7 @@ func TestDashboardFileReader(t *testing.T) {
}
Convey("Can read default dashboard", func() {
cfg.Options["folder"] = defaultDashboards
cfg.Options["path"] = defaultDashboards
cfg.Folder = "Team A"
reader, err := NewDashboardFileReader(cfg, logger)
......@@ -67,7 +67,7 @@ func TestDashboardFileReader(t *testing.T) {
})
Convey("Should not update dashboards when db is newer", func() {
cfg.Options["folder"] = oneDashboard
cfg.Options["path"] = oneDashboard
fakeRepo.getDashboard = append(fakeRepo.getDashboard, &models.Dashboard{
Updated: time.Now().Add(time.Hour),
......@@ -84,7 +84,7 @@ func TestDashboardFileReader(t *testing.T) {
})
Convey("Can read default dashboard and replace old version in database", func() {
cfg.Options["folder"] = oneDashboard
cfg.Options["path"] = oneDashboard
stat, _ := os.Stat(oneDashboard + "/dashboard1.json")
......@@ -115,7 +115,7 @@ func TestDashboardFileReader(t *testing.T) {
})
Convey("Broken dashboards should not cause error", func() {
cfg.Options["folder"] = brokenDashboards
cfg.Options["path"] = brokenDashboards
_, err := NewDashboardFileReader(cfg, logger)
So(err, ShouldBeNil)
......@@ -167,7 +167,7 @@ func TestDashboardFileReader(t *testing.T) {
OrgId: 1,
Folder: "",
Options: map[string]interface{}{
"folder": defaultDashboards,
"path": defaultDashboards,
},
}
......@@ -184,6 +184,30 @@ func TestDashboardFileReader(t *testing.T) {
So(shouldSkip, ShouldBeNil)
})
})
Convey("Can use bpth path and folder as dashboard path", func() {
cfg := &DashboardsAsConfig{
Name: "Default",
Type: "file",
OrgId: 1,
Folder: "",
Options: map[string]interface{}{},
}
Convey("using path parameter", func() {
cfg.Options["path"] = defaultDashboards
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
So(err, ShouldBeNil)
So(reader.Path, ShouldEqual, defaultDashboards)
})
Convey("using folder as options", func() {
cfg.Options["folder"] = defaultDashboards
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
So(err, ShouldBeNil)
So(reader.Path, ShouldEqual, defaultDashboards)
})
})
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment