Skip to content

Commit

Permalink
upgraded to yaml.v3
Browse files Browse the repository at this point in the history
* fixes #245

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
  • Loading branch information
fredbi committed Dec 8, 2023
1 parent 1d20135 commit 337c930
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
3 changes: 1 addition & 2 deletions go.mod
Expand Up @@ -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 (
Expand All @@ -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
3 changes: 1 addition & 2 deletions yamlpc/yaml.go
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions yamlpc/yaml_test.go
Expand Up @@ -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])
}

0 comments on commit 337c930

Please sign in to comment.