mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
provisioning: enable relative path's
this commit enable relatives path for provisioning dashboards. this enables easier dev setups
This commit is contained in:
parent
b253284acc
commit
c7acbcdaf5
@ -5,5 +5,5 @@ providers:
|
|||||||
folder: 'Bulk dashboards'
|
folder: 'Bulk dashboards'
|
||||||
type: file
|
type: file
|
||||||
options:
|
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)
|
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{
|
return &fileReader{
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
Path: path,
|
Path: absPath,
|
||||||
log: log,
|
log: log,
|
||||||
dashboardService: dashboards.NewProvisioningService(),
|
dashboardService: dashboards.NewProvisioningService(),
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -15,14 +15,57 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
defaultDashboards = "./testdata/test-dashboards/folder-one"
|
defaultDashboards = "testdata/test-dashboards/folder-one"
|
||||||
brokenDashboards = "./testdata/test-dashboards/broken-dashboards"
|
brokenDashboards = "testdata/test-dashboards/broken-dashboards"
|
||||||
oneDashboard = "./testdata/test-dashboards/one-dashboard"
|
oneDashboard = "testdata/test-dashboards/one-dashboard"
|
||||||
containingId = "./testdata/test-dashboards/containing-id"
|
containingId = "testdata/test-dashboards/containing-id"
|
||||||
|
|
||||||
fakeService *fakeDashboardProvisioningService
|
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) {
|
func TestDashboardFileReader(t *testing.T) {
|
||||||
Convey("Dashboard file reader", t, func() {
|
Convey("Dashboard file reader", t, func() {
|
||||||
bus.ClearBusHandlers()
|
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() {
|
Reset(func() {
|
||||||
dashboards.NewProvisioningService = origNewDashboardProvisioningService
|
dashboards.NewProvisioningService = origNewDashboardProvisioningService
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user