2017-11-30 10:43:28 -06:00
|
|
|
package dashboards
|
2017-11-23 04:29:06 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-01-24 07:20:16 -06:00
|
|
|
"github.com/grafana/grafana/pkg/log"
|
2017-11-23 04:29:06 -06:00
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
simpleDashboardConfig string = "./test-configs/dashboards-from-disk"
|
2017-12-08 04:33:15 -06:00
|
|
|
brokenConfigs string = "./test-configs/broken-configs"
|
2017-11-23 04:29:06 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDashboardsAsConfig(t *testing.T) {
|
|
|
|
Convey("Dashboards as configuration", t, func() {
|
|
|
|
|
|
|
|
Convey("Can read config file", func() {
|
|
|
|
|
2018-01-24 08:54:11 -06:00
|
|
|
cfgProvider := configReader{path: simpleDashboardConfig, log: log.New("test-logger")}
|
|
|
|
cfg, err := cfgProvider.readConfig()
|
2017-11-23 04:29:06 -06:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("readConfig return an error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
So(len(cfg), ShouldEqual, 2)
|
|
|
|
|
|
|
|
ds := cfg[0]
|
|
|
|
|
|
|
|
So(ds.Name, ShouldEqual, "general dashboards")
|
|
|
|
So(ds.Type, ShouldEqual, "file")
|
|
|
|
So(ds.OrgId, ShouldEqual, 2)
|
|
|
|
So(ds.Folder, ShouldEqual, "developers")
|
2017-11-28 09:57:14 -06:00
|
|
|
So(ds.Editable, ShouldBeTrue)
|
2017-11-23 04:29:06 -06:00
|
|
|
|
|
|
|
So(len(ds.Options), ShouldEqual, 1)
|
2018-01-16 10:35:28 -06:00
|
|
|
So(ds.Options["path"], ShouldEqual, "/var/lib/grafana/dashboards")
|
2017-11-23 04:29:06 -06:00
|
|
|
|
|
|
|
ds2 := cfg[1]
|
|
|
|
|
|
|
|
So(ds2.Name, ShouldEqual, "default")
|
|
|
|
So(ds2.Type, ShouldEqual, "file")
|
|
|
|
So(ds2.OrgId, ShouldEqual, 1)
|
|
|
|
So(ds2.Folder, ShouldEqual, "")
|
2017-11-28 09:57:14 -06:00
|
|
|
So(ds2.Editable, ShouldBeFalse)
|
2017-11-23 04:29:06 -06:00
|
|
|
|
|
|
|
So(len(ds2.Options), ShouldEqual, 1)
|
2018-01-16 10:35:28 -06:00
|
|
|
So(ds2.Options["path"], ShouldEqual, "/var/lib/grafana/dashboards")
|
2017-11-23 04:29:06 -06:00
|
|
|
})
|
2017-12-08 03:50:11 -06:00
|
|
|
|
2018-01-24 07:20:16 -06:00
|
|
|
Convey("Should skip invalid path", func() {
|
2017-12-08 03:50:11 -06:00
|
|
|
|
2018-01-24 08:54:11 -06:00
|
|
|
cfgProvider := configReader{path: "/invalid-directory", log: log.New("test-logger")}
|
|
|
|
cfg, err := cfgProvider.readConfig()
|
2017-12-08 03:50:11 -06:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("readConfig return an error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
So(len(cfg), ShouldEqual, 0)
|
2018-01-24 07:20:16 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Should skip broken config files", func() {
|
|
|
|
|
2018-01-24 08:54:11 -06:00
|
|
|
cfgProvider := configReader{path: brokenConfigs, log: log.New("test-logger")}
|
|
|
|
cfg, err := cfgProvider.readConfig()
|
2018-01-24 07:20:16 -06:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("readConfig return an error %v", err)
|
|
|
|
}
|
2017-12-08 03:50:11 -06:00
|
|
|
|
2018-01-24 07:20:16 -06:00
|
|
|
So(len(cfg), ShouldEqual, 0)
|
2017-12-08 03:50:11 -06:00
|
|
|
})
|
2017-11-23 04:29:06 -06:00
|
|
|
})
|
|
|
|
}
|