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

This commit is contained in:
bergquist
2018-02-09 15:33:54 +01:00
parent e93fe9db25
commit 5a76624003
2 changed files with 3 additions and 18 deletions

View File

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

View File

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