github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/runtime/serializer/yaml/yaml_test.go (about) 1 /* 2 Copyright 2019 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package yaml 18 19 import ( 20 "strings" 21 "testing" 22 23 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/util/yaml" 24 sigsyaml "sigs.k8s.io/yaml" 25 ) 26 27 type testcase struct { 28 name string 29 data []byte 30 error string 31 32 benchmark bool 33 } 34 35 func testcases() []testcase { 36 return []testcase{ 37 { 38 name: "arrays of string aliases", 39 error: "excessive aliasing", 40 data: []byte(` 41 apiVersion: v1 42 data: 43 a: &a ["webwebwebwebwebweb","webwebwebwebwebweb","webwebwebwebwebweb","webwebwebwebwebweb","webwebwebwebwebweb","webwebwebwebwebweb","webwebwebwebwebweb","webwebwebwebwebweb","webwebwebwebwebweb"] 44 b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a] 45 c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b] 46 d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c] 47 e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d] 48 f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e] 49 g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f] 50 h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g] 51 i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h] 52 kind: ConfigMap 53 metadata: 54 name: yaml-bomb 55 namespace: default 56 `), 57 }, 58 { 59 name: "arrays of empty string aliases", 60 error: "excessive aliasing", 61 data: []byte(` 62 apiVersion: v1 63 data: 64 a: &a ["","","","","","","","",""] 65 b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a] 66 c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b] 67 d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c] 68 e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d] 69 f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e] 70 g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f] 71 h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g] 72 i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h] 73 kind: ConfigMap 74 metadata: 75 name: yaml-bomb 76 namespace: default 77 `), 78 benchmark: true, 79 }, 80 { 81 name: "arrays of null aliases", 82 error: "excessive aliasing", 83 data: []byte(` 84 apiVersion: v1 85 data: 86 a: &a [null,null,null,null,null,null,null,null,null] 87 b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a] 88 c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b] 89 d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c] 90 e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d] 91 f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e] 92 g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f] 93 h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g] 94 i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h] 95 kind: ConfigMap 96 metadata: 97 name: yaml-bomb 98 namespace: default 99 `), 100 benchmark: true, 101 }, 102 { 103 name: "arrays of zero int aliases", 104 error: "excessive aliasing", 105 data: []byte(` 106 apiVersion: v1 107 data: 108 a: &a [0,0,0,0,0,0,0,0,0] 109 b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a] 110 c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b] 111 d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c] 112 e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d] 113 f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e] 114 g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f] 115 h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g] 116 i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h] 117 kind: ConfigMap 118 metadata: 119 name: yaml-bomb 120 namespace: default 121 `), 122 benchmark: true, 123 }, 124 { 125 name: "arrays of zero float aliases", 126 error: "excessive aliasing", 127 data: []byte(` 128 apiVersion: v1 129 data: 130 a: &a [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0] 131 b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a] 132 c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b] 133 d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c] 134 e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d] 135 f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e] 136 g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f] 137 h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g] 138 i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h] 139 kind: ConfigMap 140 metadata: 141 name: yaml-bomb 142 namespace: default 143 `), 144 benchmark: true, 145 }, 146 { 147 name: "arrays of big float aliases", 148 error: "excessive aliasing", 149 data: []byte(` 150 apiVersion: v1 151 data: 152 a: &a [1234567890.12345678,1234567890.12345678,1234567890.12345678,1234567890.12345678,1234567890.12345678,1234567890.12345678,1234567890.12345678,1234567890.12345678,1234567890.12345678] 153 b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a] 154 c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b] 155 d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c] 156 e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d] 157 f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e] 158 g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f] 159 h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g] 160 i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h] 161 kind: ConfigMap 162 metadata: 163 name: yaml-bomb 164 namespace: default 165 `), 166 benchmark: true, 167 }, 168 { 169 name: "arrays of bool aliases", 170 error: "excessive aliasing", 171 data: []byte(` 172 apiVersion: v1 173 data: 174 a: &a [true,true,true,true,true,true,true,true,true] 175 b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a] 176 c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b] 177 d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c] 178 e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d] 179 f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e,*e] 180 g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f,*f] 181 h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g,*g] 182 i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h,*h] 183 kind: ConfigMap 184 metadata: 185 name: yaml-bomb 186 namespace: default 187 `), 188 benchmark: true, 189 }, 190 { 191 name: "map key aliases", 192 error: "excessive aliasing", 193 data: []byte(` 194 apiVersion: v1 195 data: 196 a: &a {"verylongkey1":"","verylongkey2":"","verylongkey3":"","verylongkey4":"","verylongkey5":"","verylongkey6":"","verylongkey7":"","verylongkey8":"","verylongkey9":""} 197 b: &b {"verylongkey1":*a,"verylongkey2":*a,"verylongkey3":*a,"verylongkey4":*a,"verylongkey5":*a,"verylongkey6":*a,"verylongkey7":*a,"verylongkey8":*a,"verylongkey9":*a} 198 c: &c {"verylongkey1":*b,"verylongkey2":*b,"verylongkey3":*b,"verylongkey4":*b,"verylongkey5":*b,"verylongkey6":*b,"verylongkey7":*b,"verylongkey8":*b,"verylongkey9":*b} 199 d: &d {"verylongkey1":*c,"verylongkey2":*c,"verylongkey3":*c,"verylongkey4":*c,"verylongkey5":*c,"verylongkey6":*c,"verylongkey7":*c,"verylongkey8":*c,"verylongkey9":*c} 200 e: &e {"verylongkey1":*d,"verylongkey2":*d,"verylongkey3":*d,"verylongkey4":*d,"verylongkey5":*d,"verylongkey6":*d,"verylongkey7":*d,"verylongkey8":*d,"verylongkey9":*d} 201 f: &f {"verylongkey1":*e,"verylongkey2":*e,"verylongkey3":*e,"verylongkey4":*e,"verylongkey5":*e,"verylongkey6":*e,"verylongkey7":*e,"verylongkey8":*e,"verylongkey9":*e} 202 g: &g {"verylongkey1":*f,"verylongkey2":*f,"verylongkey3":*f,"verylongkey4":*f,"verylongkey5":*f,"verylongkey6":*f,"verylongkey7":*f,"verylongkey8":*f,"verylongkey9":*f} 203 h: &h {"verylongkey1":*g,"verylongkey2":*g,"verylongkey3":*g,"verylongkey4":*g,"verylongkey5":*g,"verylongkey6":*g,"verylongkey7":*g,"verylongkey8":*g,"verylongkey9":*g} 204 i: &i {"verylongkey1":*h,"verylongkey2":*h,"verylongkey3":*h,"verylongkey4":*h,"verylongkey5":*h,"verylongkey6":*h,"verylongkey7":*h,"verylongkey8":*h,"verylongkey9":*h} 205 kind: ConfigMap 206 metadata: 207 name: yaml-bomb 208 namespace: default 209 `), 210 benchmark: true, 211 }, 212 { 213 name: "map value aliases", 214 error: "excessive aliasing", 215 data: []byte(` 216 apiVersion: v1 217 data: 218 a: &a {"1":"verylongmapvalue","2":"verylongmapvalue","3":"verylongmapvalue","4":"verylongmapvalue","5":"verylongmapvalue","6":"verylongmapvalue","7":"verylongmapvalue","8":"verylongmapvalue","9":"verylongmapvalue"} 219 b: &b {"1":*a,"2":*a,"3":*a,"4":*a,"5":*a,"6":*a,"7":*a,"8":*a,"9":*a} 220 c: &c {"1":*b,"2":*b,"3":*b,"4":*b,"5":*b,"6":*b,"7":*b,"8":*b,"9":*b} 221 d: &d {"1":*c,"2":*c,"3":*c,"4":*c,"5":*c,"6":*c,"7":*c,"8":*c,"9":*c} 222 e: &e {"1":*d,"2":*d,"3":*d,"4":*d,"5":*d,"6":*d,"7":*d,"8":*d,"9":*d} 223 f: &f {"1":*e,"2":*e,"3":*e,"4":*e,"5":*e,"6":*e,"7":*e,"8":*e,"9":*e} 224 g: &g {"1":*f,"2":*f,"3":*f,"4":*f,"5":*f,"6":*f,"7":*f,"8":*f,"9":*f} 225 h: &h {"1":*g,"2":*g,"3":*g,"4":*g,"5":*g,"6":*g,"7":*g,"8":*g,"9":*g} 226 i: &i {"1":*h,"2":*h,"3":*h,"4":*h,"5":*h,"6":*h,"7":*h,"8":*h,"9":*h} 227 kind: ConfigMap 228 metadata: 229 name: yaml-bomb 230 namespace: default 231 `), 232 benchmark: true, 233 }, 234 { 235 name: "nested map aliases", 236 error: "excessive aliasing", 237 data: []byte(` 238 apiVersion: v1 239 data: 240 a: &a {"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{"":{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} 241 b: &b {"1":*a,"2":*a,"3":*a,"4":*a,"5":*a,"6":*a,"7":*a,"8":*a,"9":*a} 242 c: &c {"1":*b,"2":*b,"3":*b,"4":*b,"5":*b,"6":*b,"7":*b,"8":*b,"9":*b} 243 d: &d {"1":*c,"2":*c,"3":*c,"4":*c,"5":*c,"6":*c,"7":*c,"8":*c,"9":*c} 244 e: &e {"1":*d,"2":*d,"3":*d,"4":*d,"5":*d,"6":*d,"7":*d,"8":*d,"9":*d} 245 f: &f {"1":*e,"2":*e,"3":*e,"4":*e,"5":*e,"6":*e,"7":*e,"8":*e,"9":*e} 246 g: &g {"1":*f,"2":*f,"3":*f,"4":*f,"5":*f,"6":*f,"7":*f,"8":*f,"9":*f} 247 h: &h {"1":*g,"2":*g,"3":*g,"4":*g,"5":*g,"6":*g,"7":*g,"8":*g,"9":*g} 248 i: &i {"1":*h,"2":*h,"3":*h,"4":*h,"5":*h,"6":*h,"7":*h,"8":*h,"9":*h} 249 kind: ConfigMap 250 metadata: 251 name: yaml-bomb 252 namespace: default 253 `), 254 benchmark: true, 255 }, 256 { 257 name: "nested slice aliases", 258 error: "excessive aliasing", 259 data: []byte(` 260 apiVersion: v1 261 data: 262 a: &a [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[""]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] 263 b: &b [[[[[[[[[[*a]]]]]]]]],[[[[[[[[[*a]]]]]]]]],[[[[[[[[[*a]]]]]]]]],[[[[[[[[[*a]]]]]]]]],[[[[[[[[[*a]]]]]]]]]] 264 c: &c [[[[[[[[[[*b]]]]]]]]],[[[[[[[[[*b]]]]]]]]],[[[[[[[[[*b]]]]]]]]],[[[[[[[[[*b]]]]]]]]],[[[[[[[[[*b]]]]]]]]]] 265 d: &d [[[[[[[[[[*c]]]]]]]]],[[[[[[[[[*c]]]]]]]]],[[[[[[[[[*c]]]]]]]]],[[[[[[[[[*c]]]]]]]]],[[[[[[[[[*c]]]]]]]]]] 266 e: &e [[[[[[[[[[*d]]]]]]]]],[[[[[[[[[*d]]]]]]]]],[[[[[[[[[*d]]]]]]]]],[[[[[[[[[*d]]]]]]]]],[[[[[[[[[*d]]]]]]]]]] 267 f: &f [[[[[[[[[[*e]]]]]]]]],[[[[[[[[[*e]]]]]]]]],[[[[[[[[[*e]]]]]]]]],[[[[[[[[[*e]]]]]]]]],[[[[[[[[[*e]]]]]]]]]] 268 g: &g [[[[[[[[[[*f]]]]]]]]],[[[[[[[[[*f]]]]]]]]],[[[[[[[[[*f]]]]]]]]],[[[[[[[[[*f]]]]]]]]],[[[[[[[[[*f]]]]]]]]]] 269 h: &h [[[[[[[[[[*g]]]]]]]]],[[[[[[[[[*g]]]]]]]]],[[[[[[[[[*g]]]]]]]]],[[[[[[[[[*g]]]]]]]]],[[[[[[[[[*g]]]]]]]]]] 270 i: &i [[[[[[[[[[*h]]]]]]]]],[[[[[[[[[*h]]]]]]]]],[[[[[[[[[*h]]]]]]]]],[[[[[[[[[*h]]]]]]]]],[[[[[[[[[*h]]]]]]]]]] 271 kind: ConfigMap 272 metadata: 273 name: yaml-bomb 274 namespace: default 275 `), 276 benchmark: true, 277 }, 278 { 279 name: "3MB map without alias", 280 data: []byte(`a: &a [{a}` + strings.Repeat(`,{a}`, 3*1024*1024/4) + `]`), 281 benchmark: true, 282 }, 283 { 284 name: "3MB map with alias", 285 error: "excessive aliasing", 286 data: []byte(` 287 a: &a [{a}` + strings.Repeat(`,{a}`, 3*1024*1024/4) + `] 288 b: &b [*a]`), 289 benchmark: true, 290 }, 291 { 292 name: "deeply nested slices", 293 error: "max depth", 294 data: []byte(strings.Repeat(`[`, 3*1024*1024)), 295 }, 296 { 297 name: "deeply nested maps", 298 error: "max depth", 299 data: []byte("x: " + strings.Repeat(`{`, 3*1024*1024)), 300 }, 301 { 302 name: "deeply nested indents", 303 error: "max depth", 304 data: []byte(strings.Repeat(`- `, 3*1024*1024)), 305 }, 306 { 307 name: "3MB of 1000-indent lines", 308 data: []byte(strings.Repeat(strings.Repeat(`- `, 1000)+"\n", 3*1024/2)), 309 benchmark: true, 310 }, 311 { 312 name: "3MB of empty slices", 313 data: []byte(`[` + strings.Repeat(`[],`, 3*1024*1024/3-2) + `[]]`), 314 benchmark: true, 315 }, 316 { 317 name: "3MB of slices", 318 data: []byte(`[` + strings.Repeat(`[0],`, 3*1024*1024/4-2) + `[0]]`), 319 benchmark: true, 320 }, 321 { 322 name: "3MB of empty maps", 323 data: []byte(`[` + strings.Repeat(`{},`, 3*1024*1024/3-2) + `{}]`), 324 benchmark: true, 325 }, 326 { 327 name: "3MB of maps", 328 data: []byte(`[` + strings.Repeat(`{a},`, 3*1024*1024/4-2) + `{a}]`), 329 benchmark: true, 330 }, 331 { 332 name: "3MB of ints", 333 data: []byte(`[` + strings.Repeat(`0,`, 3*1024*1024/2-2) + `0]`), 334 benchmark: true, 335 }, 336 { 337 name: "3MB of floats", 338 data: []byte(`[` + strings.Repeat(`0.0,`, 3*1024*1024/4-2) + `0.0]`), 339 benchmark: true, 340 }, 341 { 342 name: "3MB of bools", 343 data: []byte(`[` + strings.Repeat(`true,`, 3*1024*1024/5-2) + `true]`), 344 benchmark: true, 345 }, 346 { 347 name: "3MB of empty strings", 348 data: []byte(`[` + strings.Repeat(`"",`, 3*1024*1024/3-2) + `""]`), 349 benchmark: true, 350 }, 351 { 352 name: "3MB of strings", 353 data: []byte(`[` + strings.Repeat(`"abcdefghijklmnopqrstuvwxyz012",`, 3*1024*1024/30-2) + `"abcdefghijklmnopqrstuvwxyz012"]`), 354 benchmark: true, 355 }, 356 { 357 name: "3MB of nulls", 358 data: []byte(`[` + strings.Repeat(`null,`, 3*1024*1024/5-2) + `null]`), 359 benchmark: true, 360 }, 361 } 362 } 363 364 var decoders = map[string]func([]byte) ([]byte, error){ 365 "sigsyaml": sigsyaml.YAMLToJSON, 366 "utilyaml": yaml.ToJSON, 367 } 368 369 func TestYAMLLimits(t *testing.T) { 370 for _, tc := range testcases() { 371 if tc.benchmark { 372 continue 373 } 374 t.Run(tc.name, func(t *testing.T) { 375 for decoderName, decoder := range decoders { 376 t.Run(decoderName, func(t *testing.T) { 377 _, err := decoder(tc.data) 378 if len(tc.error) == 0 { 379 if err != nil { 380 t.Errorf("unexpected error: %v", err) 381 } 382 } else { 383 if err == nil || !strings.Contains(err.Error(), tc.error) { 384 t.Errorf("expected %q error, got %v", tc.error, err) 385 } 386 } 387 }) 388 } 389 }) 390 } 391 } 392 393 func BenchmarkYAMLLimits(b *testing.B) { 394 for _, tc := range testcases() { 395 b.Run(tc.name, func(b *testing.B) { 396 for decoderName, decoder := range decoders { 397 b.Run(decoderName, func(b *testing.B) { 398 for i := 0; i < b.N; i++ { 399 _, err := decoder(tc.data) 400 if len(tc.error) == 0 { 401 if err != nil { 402 b.Errorf("unexpected error: %v", err) 403 } 404 } else { 405 if err == nil || !strings.Contains(err.Error(), tc.error) { 406 b.Errorf("expected %q error, got %v", tc.error, err) 407 } 408 } 409 } 410 }) 411 } 412 }) 413 } 414 }