Commit c7acbcda by bergquist

provisioning: enable relative path's

this commit enable relatives path for provisioning dashboards.
this enables easier dev setups
parent b253284a
......@@ -5,5 +5,5 @@ providers:
folder: 'Bulk dashboards'
type: file
options:
path: /home/carl/go/src/github.com/grafana/grafana/devenv/dashboards/bulk-testing
path: devenv/dashboards/bulk-testing
......@@ -47,9 +47,15 @@ func NewDashboardFileReader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade
log.Error("Cannot read directory", "error", err)
}
absPath, err := filepath.Abs(path)
if err != nil {
log.Error("Could not create absolute path ", "path", path)
absPath = path //if .Abs return an error we fallback to path
}
return &fileReader{
Cfg: cfg,
Path: path,
Path: absPath,
log: log,
dashboardService: dashboards.NewProvisioningService(),
}, nil
......
......@@ -15,14 +15,57 @@ import (
)
var (
defaultDashboards = "./testdata/test-dashboards/folder-one"
brokenDashboards = "./testdata/test-dashboards/broken-dashboards"
oneDashboard = "./testdata/test-dashboards/one-dashboard"
containingId = "./testdata/test-dashboards/containing-id"
defaultDashboards = "testdata/test-dashboards/folder-one"
brokenDashboards = "testdata/test-dashboards/broken-dashboards"
oneDashboard = "testdata/test-dashboards/one-dashboard"
containingId = "testdata/test-dashboards/containing-id"
fakeService *fakeDashboardProvisioningService
)
func TestCreatingNewDashboardFileReader(t *testing.T) {
Convey("creating new dashboard file reader", t, 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, ShouldNotEqual, "")
})
Convey("using folder as options", func() {
cfg.Options["folder"] = defaultDashboards
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
So(err, ShouldBeNil)
So(reader.Path, ShouldNotEqual, "")
})
Convey("using full path", func() {
cfg.Options["folder"] = "/var/lib/grafana/dashboards"
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
So(err, ShouldBeNil)
So(reader.Path, ShouldEqual, "/var/lib/grafana/dashboards")
So(filepath.IsAbs(reader.Path), ShouldBeTrue)
})
Convey("using relative path", func() {
cfg.Options["folder"] = defaultDashboards
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
So(err, ShouldBeNil)
So(filepath.IsAbs(reader.Path), ShouldBeTrue)
})
})
}
func TestDashboardFileReader(t *testing.T) {
Convey("Dashboard file reader", t, func() {
bus.ClearBusHandlers()
......@@ -170,30 +213,6 @@ func TestDashboardFileReader(t *testing.T) {
})
})
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)
})
})
Reset(func() {
dashboards.NewProvisioningService = origNewDashboardProvisioningService
})
......
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