@@ -12,6 +12,7 @@ var _ = Describe("NewOpsFromDefinitions", func() {
1212 path = "/abc"
1313 invalidPath = "abc"
1414 val interface {} = 123
15+ complexVal interface {} = map [interface {}]interface {}{123 : 123 }
1516 )
1617
1718 It ("supports 'replace' and 'remove' operations" , func () {
@@ -32,52 +33,90 @@ var _ = Describe("NewOpsFromDefinitions", func() {
3233 It ("returns error if operation type is unknown" , func () {
3334 _ , err := NewOpsFromDefinitions ([]OpDefinition {{Type : "test" }})
3435 Expect (err ).To (HaveOccurred ())
35- Expect (err .Error ()).To (Equal ("Unknown operation [0] with type 'test'" ))
36+ Expect (err .Error ()).To (Equal (`Unknown operation [0] with type 'test' within
37+ {
38+ "Type": "test"
39+ }` ))
3640 })
3741
3842 It ("returns error if operation type is find since it's not useful in list of operations" , func () {
3943 _ , err := NewOpsFromDefinitions ([]OpDefinition {{Type : "find" }})
4044 Expect (err ).To (HaveOccurred ())
41- Expect (err .Error ()).To (Equal ("Unknown operation [0] with type 'find'" ))
45+ Expect (err .Error ()).To (ContainSubstring ("Unknown operation [0] with type 'find'" ))
46+ })
47+
48+ It ("allows values to be complex in error messages" , func () {
49+ _ , err := NewOpsFromDefinitions ([]OpDefinition {{Type : "test" , Path : & invalidPath , Value : & complexVal }})
50+ Expect (err ).To (HaveOccurred ())
51+ Expect (err .Error ()).To (Equal (`Unknown operation [0] with type 'test' within
52+ {
53+ "Type": "test",
54+ "Path": "abc",
55+ "Value": "<redacted>"
56+ }` ))
4257 })
4358
4459 Describe ("replace" , func () {
4560 It ("requires path" , func () {
4661 _ , err := NewOpsFromDefinitions ([]OpDefinition {{Type : "replace" }})
4762 Expect (err ).To (HaveOccurred ())
48- Expect (err .Error ()).To (Equal ("Replace operation [0]: Missing path" ))
63+ Expect (err .Error ()).To (Equal (`Replace operation [0]: Missing path within
64+ {
65+ "Type": "replace"
66+ }` ))
4967 })
5068
5169 It ("requires value" , func () {
5270 _ , err := NewOpsFromDefinitions ([]OpDefinition {{Type : "replace" , Path : & path }})
5371 Expect (err ).To (HaveOccurred ())
54- Expect (err .Error ()).To (Equal ("Replace operation [0]: Missing value" ))
72+ Expect (err .Error ()).To (Equal (`Replace operation [0]: Missing value within
73+ {
74+ "Type": "replace",
75+ "Path": "/abc"
76+ }` ))
5577 })
5678
5779 It ("requires valid path" , func () {
5880 _ , err := NewOpsFromDefinitions ([]OpDefinition {{Type : "replace" , Path : & invalidPath , Value : & val }})
5981 Expect (err ).To (HaveOccurred ())
60- Expect (err .Error ()).To (ContainSubstring ("Replace operation [0]: Invalid path: Expected to start with '/'" ))
82+ Expect (err .Error ()).To (Equal (`Replace operation [0]: Invalid path: Expected to start with '/' within
83+ {
84+ "Type": "replace",
85+ "Path": "abc",
86+ "Value": "<redacted>"
87+ }` ))
6188 })
6289 })
6390
6491 Describe ("remove" , func () {
6592 It ("requires path" , func () {
6693 _ , err := NewOpsFromDefinitions ([]OpDefinition {{Type : "remove" }})
6794 Expect (err ).To (HaveOccurred ())
68- Expect (err .Error ()).To (Equal ("Remove operation [0]: Missing path" ))
95+ Expect (err .Error ()).To (Equal (`Remove operation [0]: Missing path within
96+ {
97+ "Type": "remove"
98+ }` ))
6999 })
70100
71101 It ("does not allow value" , func () {
72102 _ , err := NewOpsFromDefinitions ([]OpDefinition {{Type : "remove" , Path : & path , Value : & val }})
73103 Expect (err ).To (HaveOccurred ())
74- Expect (err .Error ()).To (Equal ("Remove operation [0]: Cannot specify value" ))
104+ Expect (err .Error ()).To (Equal (`Remove operation [0]: Cannot specify value within
105+ {
106+ "Type": "remove",
107+ "Path": "/abc",
108+ "Value": "<redacted>"
109+ }` ))
75110 })
76111
77112 It ("requires valid path" , func () {
78113 _ , err := NewOpsFromDefinitions ([]OpDefinition {{Type : "remove" , Path : & invalidPath }})
79114 Expect (err ).To (HaveOccurred ())
80- Expect (err .Error ()).To (ContainSubstring ("Remove operation [0]: Invalid path: Expected to start with '/'" ))
115+ Expect (err .Error ()).To (Equal (`Remove operation [0]: Invalid path: Expected to start with '/' within
116+ {
117+ "Type": "remove",
118+ "Path": "abc"
119+ }` ))
81120 })
82121 })
83122})
0 commit comments