Skip to content

Commit 9954948

Browse files
authored
Switch YAML library used to sigs.k8s.io/yaml (#11)
* Update tests * Ensure old contract respecting Marshaller interface is maintained
1 parent e45d916 commit 9954948

File tree

26 files changed

+1347
-118
lines changed

26 files changed

+1347
-118
lines changed

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ require (
77
github.com/mattn/go-isatty v0.0.11
88
github.com/stretchr/testify v1.7.1
99
github.com/vito/go-interact v1.0.1
10-
gopkg.in/yaml.v2 v2.3.0
10+
sigs.k8s.io/yaml v1.3.0
1111
)
1212

1313
require (
14-
github.com/davecgh/go-spew v1.1.0 // indirect
14+
github.com/davecgh/go-spew v1.1.1 // indirect
1515
github.com/mattn/go-colorable v0.1.4 // indirect
1616
github.com/pmezard/go-difflib v1.0.0 // indirect
1717
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
1818
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
19+
gopkg.in/yaml.v2 v2.4.0 // indirect
1920
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
2021
)

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835 h1:mYQweUIBD+TB
22
github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835/go.mod h1:dYeVsKp1vvK8XjdTPR1gF+uk+9doxKeO3hqQTOCr7T4=
33
github.com/creack/pty v1.1.7 h1:6pwm8kMQKCmgUg0ZHTm5+/YvRK0s3THD/28+T6/kk4A=
44
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
5-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
65
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
7+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
78
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
89
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
910
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
@@ -78,7 +79,10 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
7879
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
7980
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
8081
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
81-
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
8282
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
83+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
84+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
8385
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
8486
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
87+
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
88+
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=

ui/table/values.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
"time"
1010

11-
"gopkg.in/yaml.v2"
11+
"sigs.k8s.io/yaml"
1212
)
1313

1414
func NewValueString(s string) ValueString { return ValueString{S: s} }
@@ -129,6 +129,19 @@ func (t ValueInterface) String() string {
129129
return ""
130130
}
131131

132+
// Handles contract in older YAML library defined here:
133+
// https://github.com/go-yaml/yaml/blob/v3/yaml.go#L44-L52
134+
if i, ok := t.I.(interface{ MarshalYAML() (interface{}, error) }); ok {
135+
v, err := i.MarshalYAML()
136+
if err != nil {
137+
return fmt.Sprintf("<serialization error> : %#v", t.I)
138+
}
139+
if v == nil {
140+
return ""
141+
}
142+
t.I = v
143+
}
144+
132145
bytes, err := yaml.Marshal(t.I)
133146
if err != nil {
134147
return fmt.Sprintf("<serialization error> : %#v", t.I)

ui/table/values_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,17 @@ func TestValueInterface(t *testing.T) {
179179
assert.Equal(t, ValueInterface{I: i}.String(), "key:\n nested_key: nested_value")
180180
})
181181

182-
t.Run("returns nested items as a string", func(t *testing.T) {
182+
// Tests contract specified here: https://github.com/go-yaml/yaml/blob/v3/yaml.go#L44-L52
183+
t.Run("respects Marshaller interface", func(t *testing.T) {
183184
i := failsToYAMLMarshal{}
184185
assert.Equal(t, ValueInterface{I: i}.String(), `<serialization error> : table_test.failsToYAMLMarshal{}`)
185186
})
186187

188+
t.Run("returns error on failure", func(t *testing.T) {
189+
i := map[string]interface{}{"foo": make(chan int)}
190+
assert.Contains(t, ValueInterface{I: i}.String(), `<serialization error> :`)
191+
})
192+
187193
t.Run("returns nil items as blank string", func(t *testing.T) {
188194
assert.Equal(t, ValueInterface{I: nil}.String(), "")
189195
})

vendor/github.com/davecgh/go-spew/LICENSE

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/davecgh/go-spew/spew/bypass.go

Lines changed: 90 additions & 97 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/davecgh/go-spew/spew/bypasssafe.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/davecgh/go-spew/spew/common.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/davecgh/go-spew/spew/dump.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/davecgh/go-spew/spew/format.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)