fix lint errors
Some checks failed
Lint / golangci-lint (push) Failing after 10m25s
Declarative Tests / test (push) Failing after 7s
Declarative Tests / build-fedora (push) Failing after 1m55s
Declarative Tests / build-ubuntu-focal (push) Failing after 1m17s

This commit is contained in:
Matthew Rich 2024-09-27 00:20:51 +00:00
parent b08d025567
commit 3ceb355773
2 changed files with 23 additions and 7 deletions

View File

@ -9,6 +9,8 @@ import (
"fmt"
"decl/internal/data"
"decl/internal/folio"
"decl/internal/codec"
"io"
)
func init() {
@ -37,6 +39,22 @@ func (g *Generic[Value]) SetParsedURI(uri *url.URL) error {
return nil
}
func (g *Generic[Value]) Load(r io.Reader) (err error) {
err = codec.NewYAMLDecoder(r).Decode(g)
if err == nil {
_, err = g.Read(context.Background())
}
return err
}
func (g *Generic[Value]) LoadYAML(yamlData string) (err error) {
err = codec.NewYAMLStringDecoder(yamlData).Decode(g)
if err == nil {
_, err = g.Read(context.Background())
}
return err
}
func (g *Generic[Value]) Clone() data.Configuration {
jsonGeneric, _ := json.Marshal(g)
clone := NewGeneric[Value]()

View File

@ -27,10 +27,10 @@ values:
bar: quuz
`
testConfig := NewBlock()
e := testConfig.LoadBlock(configBlockYaml)
testConfig := NewGeneric[any]()
e := testConfig.LoadYAML(configBlockYaml)
assert.Nil(t, e)
assert.Equal(t, "foo", testConfig.Name)
jsonDoc, jsonErr := json.Marshal(testConfig)
assert.Nil(t, jsonErr)
@ -39,11 +39,9 @@ values:
assert.Nil(t, schemaErr)
}
/*
func TestSchemaValidateSchema(t *testing.T) {
s := NewSchema("document")
assert.NotNil(t, s)
assert.Nil(t, s.ValidateSchema())
}
*/