From 3ceb3557731ef81c8f15a3c8a4c442d1b6ada400 Mon Sep 17 00:00:00 2001 From: Matthew Rich Date: Fri, 27 Sep 2024 00:20:51 +0000 Subject: [PATCH] fix lint errors --- internal/config/generic.go | 18 ++++++++++++++++++ internal/config/schema_test.go | 12 +++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/internal/config/generic.go b/internal/config/generic.go index f278724..7a27fa1 100644 --- a/internal/config/generic.go +++ b/internal/config/generic.go @@ -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]() diff --git a/internal/config/schema_test.go b/internal/config/schema_test.go index 44c18c4..08ae697 100644 --- a/internal/config/schema_test.go +++ b/internal/config/schema_test.go @@ -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) + s := NewSchema("document") + assert.NotNil(t, s) assert.Nil(t, s.ValidateSchema()) } -*/