fix issue: continue loading docs even if one has an error
This commit is contained in:
parent
486281525a
commit
8df03c455c
@ -50,7 +50,7 @@ func Load(uri folio.URI) (documents []data.Document, err error) {
|
|||||||
|
|
||||||
func BuiltInDocuments() (documents []data.Document, err error) {
|
func BuiltInDocuments() (documents []data.Document, err error) {
|
||||||
|
|
||||||
docFs := fs.NewWalkDir(documentFiles, "", func(fsys fs.FS, path string, file fs.DirEntry) (err error) {
|
docFs := fs.NewWalkDir(documentFiles, "", func(fsys fs.FS, path string, file fs.DirEntry) (walkErr error) {
|
||||||
u := folio.URI(fmt.Sprintf("file://%s", path))
|
u := folio.URI(fmt.Sprintf("file://%s", path))
|
||||||
slog.Info("BuiltInDocuments()", "file", u)
|
slog.Info("BuiltInDocuments()", "file", u)
|
||||||
|
|
||||||
@ -64,6 +64,6 @@ func BuiltInDocuments() (documents []data.Document, err error) {
|
|||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
err = docFs.Walk(nil)
|
docFs.Walk(nil)
|
||||||
return documents, err
|
return documents, err
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"decl/tests/tempdir"
|
"decl/tests/tempdir"
|
||||||
"decl/internal/folio"
|
"decl/internal/folio"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var TempDir tempdir.Path = "testbuiltin"
|
var TempDir tempdir.Path = "testbuiltin"
|
||||||
@ -27,23 +28,32 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
func TestBuiltInLoad(t *testing.T) {
|
func TestBuiltInLoad(t *testing.T) {
|
||||||
docs, err := Load("file://documents/facter.jx.yaml")
|
docs, err := Load("file://documents/facter.jx.yaml")
|
||||||
assert.Nil(t, err)
|
if ! errors.Is(err, os.ErrNotExist) {
|
||||||
assert.Greater(t, len(docs), 0)
|
assert.Nil(t, err)
|
||||||
|
assert.Greater(t, len(docs), 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuiltInDocuments(t *testing.T) {
|
func TestBuiltInDocuments(t *testing.T) {
|
||||||
docs, err := BuiltInDocuments()
|
docs, err := BuiltInDocuments()
|
||||||
assert.Nil(t, err)
|
|
||||||
config, ok := folio.DocumentRegistry.GetDocument("file://documents/facter.jx.yaml")
|
|
||||||
|
|
||||||
assert.True(t, ok)
|
|
||||||
assert.Greater(t, len(docs), 0)
|
assert.Greater(t, len(docs), 0)
|
||||||
|
if ! errors.Is(err, os.ErrNotExist) {
|
||||||
|
assert.Nil(t, err)
|
||||||
|
config, ok := folio.DocumentRegistry.GetDocument("file://documents/facter.jx.yaml")
|
||||||
|
|
||||||
slog.Info("TestBuiltInDocuments()", "docuemnt", config)
|
assert.True(t, ok)
|
||||||
|
|
||||||
assert.True(t, config.HasConfig("facts"))
|
slog.Info("TestBuiltInDocuments()", "docuemnt", config)
|
||||||
c := config.GetConfig("facts")
|
|
||||||
v, e := c.GetValue("virtual")
|
assert.True(t, config.HasConfig("facts"))
|
||||||
assert.Nil(t, e)
|
c := config.GetConfig("facts")
|
||||||
assert.Equal(t, "physical", v)
|
v, e := c.GetValue("virtual")
|
||||||
|
assert.Nil(t, e)
|
||||||
|
assert.Equal(t, "physical", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
systemConfig, systemExists := folio.DocumentRegistry.GetDocument("file://documents/system.jx.yaml")
|
||||||
|
assert.True(t, systemExists)
|
||||||
|
|
||||||
|
assert.True(t, systemConfig.HasConfig("system"))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user