mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
provisioning: createWalkFn doesnt have to be attached to the filereader anymore
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user