diff --git a/go.mod b/go.mod index aa00a87..59b1254 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( go.opentelemetry.io/otel v1.17.0 go.opentelemetry.io/otel/sdk v1.17.0 go.opentelemetry.io/otel/trace v1.17.0 - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.1 ) require ( @@ -32,7 +32,6 @@ require ( go.mongodb.org/mongo-driver v1.13.1 // indirect go.opentelemetry.io/otel/metric v1.17.0 // indirect golang.org/x/sys v0.14.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) go 1.19 diff --git a/yamlpc/yaml.go b/yamlpc/yaml.go index b30d377..a1a0a58 100644 --- a/yamlpc/yaml.go +++ b/yamlpc/yaml.go @@ -18,8 +18,7 @@ import ( "io" "github.com/go-openapi/runtime" - - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) // YAMLConsumer creates a consumer for yaml data diff --git a/yamlpc/yaml_test.go b/yamlpc/yaml_test.go index daf5e2e..a51ff55 100644 --- a/yamlpc/yaml_test.go +++ b/yamlpc/yaml_test.go @@ -71,3 +71,37 @@ func TestFailYAMLReader(t *testing.T) { cons := YAMLConsumer() require.Error(t, cons.Consume(&failReaderWriter{}, nil)) } + +func TestYAMLConsumerObject(t *testing.T) { + const yamlDoc = ` +--- +name: fred +id: 123 +attributes: + height: 12.3 + weight: 45 + list: + - a + - b +` + cons := YAMLConsumer() + var data struct { + Name string + ID int + Attributes struct { + Height float64 + Weight uint64 + List []string + } + } + require.NoError(t, + cons.Consume(bytes.NewBufferString(yamlDoc), &data), + ) + + assert.Equal(t, "fred", data.Name) + assert.Equal(t, 123, data.ID) + assert.InDelta(t, 12.3, data.Attributes.Height, 1e-9) + assert.Equal(t, uint64(45), data.Attributes.Weight) + assert.Len(t, data.Attributes.List, 2) + assert.Equal(t, "a", data.Attributes.List[0]) +}