Commit 5a766240 by bergquist

provisioning: createWalkFn doesnt have to be attached to the filereader anymore

parent e93fe9db
...@@ -29,7 +29,6 @@ type fileReader struct { ...@@ -29,7 +29,6 @@ type fileReader struct {
Path string Path string
log log.Logger log log.Logger
dashboardRepo dashboards.Repository dashboardRepo dashboards.Repository
createWalk func(filesOnDisk map[string]os.FileInfo) filepath.WalkFunc
} }
func NewDashboardFileReader(cfg *DashboardsAsConfig, log log.Logger) (*fileReader, error) { func NewDashboardFileReader(cfg *DashboardsAsConfig, log log.Logger) (*fileReader, error) {
...@@ -53,7 +52,6 @@ func NewDashboardFileReader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade ...@@ -53,7 +52,6 @@ func NewDashboardFileReader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade
Path: path, Path: path,
log: log, log: log,
dashboardRepo: dashboards.GetRepository(), dashboardRepo: dashboards.GetRepository(),
createWalk: createWalkFn,
}, nil }, nil
} }
...@@ -102,7 +100,7 @@ func (fr *fileReader) startWalkingDisk() error { ...@@ -102,7 +100,7 @@ func (fr *fileReader) startWalkingDisk() error {
} }
filesFoundOnDisk := map[string]os.FileInfo{} filesFoundOnDisk := map[string]os.FileInfo{}
err = filepath.Walk(fr.Path, fr.createWalk(filesFoundOnDisk)) err = filepath.Walk(fr.Path, createWalkFn(filesFoundOnDisk))
if err != nil { if err != nil {
return err return err
} }
......
...@@ -144,28 +144,15 @@ func TestDashboardFileReader(t *testing.T) { ...@@ -144,28 +144,15 @@ func TestDashboardFileReader(t *testing.T) {
}) })
Convey("Walking the folder with dashboards", func() { Convey("Walking the folder with dashboards", func() {
cfg := &DashboardsAsConfig{
Name: "Default",
Type: "file",
OrgId: 1,
Folder: "",
Options: map[string]interface{}{
"path": defaultDashboards,
},
}
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
So(err, ShouldBeNil)
noFiles := map[string]os.FileInfo{} noFiles := map[string]os.FileInfo{}
Convey("should skip dirs that starts with .", func() { Convey("should skip dirs that starts with .", func() {
shouldSkip := reader.createWalk(noFiles)("path", &FakeFileInfo{isDirectory: true, name: ".folder"}, nil) shouldSkip := createWalkFn(noFiles)("path", &FakeFileInfo{isDirectory: true, name: ".folder"}, nil)
So(shouldSkip, ShouldEqual, filepath.SkipDir) So(shouldSkip, ShouldEqual, filepath.SkipDir)
}) })
Convey("should keep walking if file is not .json", func() { Convey("should keep walking if file is not .json", func() {
shouldSkip := reader.createWalk(noFiles)("path", &FakeFileInfo{isDirectory: true, name: "folder"}, nil) shouldSkip := createWalkFn(noFiles)("path", &FakeFileInfo{isDirectory: true, name: "folder"}, nil)
So(shouldSkip, ShouldBeNil) So(shouldSkip, ShouldBeNil)
}) })
}) })
......
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