File tree Expand file tree Collapse file tree 3 files changed +50
-1
lines changed
Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Original file line number Diff line number Diff line change 22
33Roughly based on JSON patch: https://tools.ietf.org/html/rfc6902 .
44
5- [ Usage examples] ( docs/examples.md )
5+ - [ Usage examples] ( docs/examples.md )
6+ - [ Go YAML gotchas] ( docs/go-yaml.md )
Original file line number Diff line number Diff line change 1+ ## Go YAML
2+
3+ Tests: [ patch/yaml_compat_test.go] ( patch/yaml_compat_test.go )
4+
5+ - Use ` !!str "" ` instead of ` "" `
Original file line number Diff line number Diff line change 1+ package patch_test
2+
3+ import (
4+ . "github.com/onsi/ginkgo"
5+ . "github.com/onsi/gomega"
6+ "gopkg.in/yaml.v2"
7+
8+ . "github.com/cppforlife/go-patch/patch"
9+ )
10+
11+ var _ = Describe ("YAML compatibility" , func () {
12+ Describe ("empty string" , func () {
13+ It ("[WORKAROUND] works serializing empty strings" , func () {
14+ str := `
15+ - type: replace
16+ path: /instance_groups/name=cloud_controller/instances
17+ value: !!str ""
18+ `
19+
20+ var opDefs []OpDefinition
21+
22+ err := yaml .Unmarshal ([]byte (str ), & opDefs )
23+ Expect (err ).ToNot (HaveOccurred ())
24+
25+ val := opDefs [0 ].Value
26+ Expect ((* val ).(string )).To (Equal ("" ))
27+ })
28+
29+ It ("[PORBLEM] does not works serializing empty strings" , func () {
30+ str := `
31+ - type: replace
32+ path: /instance_groups/name=cloud_controller/instances
33+ value: ""
34+ `
35+
36+ var opDefs []OpDefinition
37+
38+ err := yaml .Unmarshal ([]byte (str ), & opDefs )
39+ Expect (err ).To (HaveOccurred ())
40+ Expect (err .Error ()).To (ContainSubstring ("cannot unmarshal !!str" ))
41+ })
42+ })
43+ })
You can’t perform that action at this time.
0 commit comments