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