Rearrange comments for yaml/V3 bug fix

This commit is contained in:
Phani Teja Marupaka
2020-03-30 01:00:49 -07:00
parent 50cc1968e4
commit 17503ae9d8
5 changed files with 92 additions and 7 deletions

View File

@@ -45,6 +45,7 @@ type ByteWriter struct {
var _ Writer = ByteWriter{}
func (w ByteWriter) Write(nodes []*yaml.RNode) error {
yaml.DoSerializationHacksOnNodes(nodes)
if w.Sort {
if err := kioutil.SortNodes(nodes); err != nil {
return errors.Wrap(err)
@@ -117,5 +118,7 @@ func (w ByteWriter) Write(nodes []*yaml.RNode) error {
for i := range nodes {
items.Content = append(items.Content, nodes[i].YNode())
}
return errors.Wrap(encoder.Encode(doc))
err := errors.Wrap(encoder.Encode(doc))
yaml.UndoSerializationHacksOnNodes(nodes)
return err
}

View File

@@ -75,8 +75,10 @@ func TestByteWriter_Write_withoutAnnotations(t *testing.T) {
node3, err := yaml.Parse(`e: f
g:
h:
- i # has a list
- j
# has a list
- i : [i1, i2] # line comment
# has a list 2
- j : j1
`)
if !assert.NoError(t, err) {
return
@@ -93,8 +95,10 @@ g:
e: f
g:
h:
- i # has a list
- j
# has a list
- i: [i1, i2] # line comment
# has a list 2
- j: j1
---
a: b #first
`, buff.String())

View File

@@ -411,8 +411,8 @@ spec:
app: nginx
spec:
containers:
- # this is another container
name: a-nginx
# this is another container
- name: a-nginx
image: nginx:1.7.9
ports:
- containerPort: 80