File tree Expand file tree Collapse file tree 3 files changed +36
-4
lines changed
Expand file tree Collapse file tree 3 files changed +36
-4
lines changed Original file line number Diff line number Diff 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
2020require (
@@ -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
3837go 1.19
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments