Skip to content

Commit 337c930

Browse files
committed
upgraded to yaml.v3
* fixes #245 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent 1d20135 commit 337c930

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
go.opentelemetry.io/otel v1.17.0
1515
go.opentelemetry.io/otel/sdk v1.17.0
1616
go.opentelemetry.io/otel/trace v1.17.0
17-
gopkg.in/yaml.v2 v2.4.0
17+
gopkg.in/yaml.v3 v3.0.1
1818
)
1919

2020
require (
@@ -32,7 +32,6 @@ require (
3232
go.mongodb.org/mongo-driver v1.13.1 // indirect
3333
go.opentelemetry.io/otel/metric v1.17.0 // indirect
3434
golang.org/x/sys v0.14.0 // indirect
35-
gopkg.in/yaml.v3 v3.0.1 // indirect
3635
)
3736

3837
go 1.19

yamlpc/yaml.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import (
1818
"io"
1919

2020
"github.com/go-openapi/runtime"
21-
22-
"gopkg.in/yaml.v2"
21+
"gopkg.in/yaml.v3"
2322
)
2423

2524
// YAMLConsumer creates a consumer for yaml data

yamlpc/yaml_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,37 @@ func TestFailYAMLReader(t *testing.T) {
7171
cons := YAMLConsumer()
7272
require.Error(t, cons.Consume(&failReaderWriter{}, nil))
7373
}
74+
75+
func TestYAMLConsumerObject(t *testing.T) {
76+
const yamlDoc = `
77+
---
78+
name: fred
79+
id: 123
80+
attributes:
81+
height: 12.3
82+
weight: 45
83+
list:
84+
- a
85+
- b
86+
`
87+
cons := YAMLConsumer()
88+
var data struct {
89+
Name string
90+
ID int
91+
Attributes struct {
92+
Height float64
93+
Weight uint64
94+
List []string
95+
}
96+
}
97+
require.NoError(t,
98+
cons.Consume(bytes.NewBufferString(yamlDoc), &data),
99+
)
100+
101+
assert.Equal(t, "fred", data.Name)
102+
assert.Equal(t, 123, data.ID)
103+
assert.InDelta(t, 12.3, data.Attributes.Height, 1e-9)
104+
assert.Equal(t, uint64(45), data.Attributes.Weight)
105+
assert.Len(t, data.Attributes.List, 2)
106+
assert.Equal(t, "a", data.Attributes.List[0])
107+
}

0 commit comments

Comments
 (0)