github.com/aavshr/aws-sdk-go@v1.41.3/aws/convert_types_test.go (about) 1 package aws 2 3 import ( 4 "reflect" 5 "testing" 6 "time" 7 ) 8 9 var testCasesStringSlice = [][]string{ 10 {"a", "b", "c", "d", "e"}, 11 {"a", "b", "", "", "e"}, 12 } 13 14 func TestStringSlice(t *testing.T) { 15 for idx, in := range testCasesStringSlice { 16 if in == nil { 17 continue 18 } 19 out := StringSlice(in) 20 if e, a := len(out), len(in); e != a { 21 t.Errorf("Unexpected len at idx %d", idx) 22 } 23 for i := range out { 24 if e, a := in[i], *(out[i]); e != a { 25 t.Errorf("Unexpected value at idx %d", idx) 26 } 27 } 28 29 out2 := StringValueSlice(out) 30 if e, a := len(out2), len(in); e != a { 31 t.Errorf("Unexpected len at idx %d", idx) 32 } 33 if e, a := in, out2; !reflect.DeepEqual(e, a) { 34 t.Errorf("Unexpected value at idx %d", idx) 35 } 36 } 37 } 38 39 var testCasesStringValueSlice = [][]*string{ 40 {String("a"), String("b"), nil, String("c")}, 41 } 42 43 func TestStringValueSlice(t *testing.T) { 44 for idx, in := range testCasesStringValueSlice { 45 if in == nil { 46 continue 47 } 48 out := StringValueSlice(in) 49 if e, a := len(out), len(in); e != a { 50 t.Errorf("Unexpected len at idx %d", idx) 51 } 52 for i := range out { 53 if in[i] == nil { 54 if out[i] != "" { 55 t.Errorf("Unexpected value at idx %d", idx) 56 } 57 } else { 58 if e, a := *(in[i]), out[i]; e != a { 59 t.Errorf("Unexpected value at idx %d", idx) 60 } 61 } 62 } 63 64 out2 := StringSlice(out) 65 if e, a := len(out2), len(in); e != a { 66 t.Errorf("Unexpected len at idx %d", idx) 67 } 68 for i := range out2 { 69 if in[i] == nil { 70 if *(out2[i]) != "" { 71 t.Errorf("Unexpected value at idx %d", idx) 72 } 73 } else { 74 if e, a := *in[i], *out2[i]; e != a { 75 t.Errorf("Unexpected value at idx %d", idx) 76 } 77 } 78 } 79 } 80 } 81 82 var testCasesStringMap = []map[string]string{ 83 {"a": "1", "b": "2", "c": "3"}, 84 } 85 86 func TestStringMap(t *testing.T) { 87 for idx, in := range testCasesStringMap { 88 if in == nil { 89 continue 90 } 91 out := StringMap(in) 92 if e, a := len(out), len(in); e != a { 93 t.Errorf("Unexpected len at idx %d", idx) 94 } 95 for i := range out { 96 if e, a := in[i], *(out[i]); e != a { 97 t.Errorf("Unexpected value at idx %d", idx) 98 } 99 } 100 101 out2 := StringValueMap(out) 102 if e, a := len(out2), len(in); e != a { 103 t.Errorf("Unexpected len at idx %d", idx) 104 } 105 if e, a := in, out2; !reflect.DeepEqual(e, a) { 106 t.Errorf("Unexpected value at idx %d", idx) 107 } 108 } 109 } 110 111 var testCasesBoolSlice = [][]bool{ 112 {true, true, false, false}, 113 } 114 115 func TestBoolSlice(t *testing.T) { 116 for idx, in := range testCasesBoolSlice { 117 if in == nil { 118 continue 119 } 120 out := BoolSlice(in) 121 if e, a := len(out), len(in); e != a { 122 t.Errorf("Unexpected len at idx %d", idx) 123 } 124 for i := range out { 125 if e, a := in[i], *(out[i]); e != a { 126 t.Errorf("Unexpected value at idx %d", idx) 127 } 128 } 129 130 out2 := BoolValueSlice(out) 131 if e, a := len(out2), len(in); e != a { 132 t.Errorf("Unexpected len at idx %d", idx) 133 } 134 if e, a := in, out2; !reflect.DeepEqual(e, a) { 135 t.Errorf("Unexpected value at idx %d", idx) 136 } 137 } 138 } 139 140 var testCasesBoolValueSlice = [][]*bool{} 141 142 func TestBoolValueSlice(t *testing.T) { 143 for idx, in := range testCasesBoolValueSlice { 144 if in == nil { 145 continue 146 } 147 out := BoolValueSlice(in) 148 if e, a := len(out), len(in); e != a { 149 t.Errorf("Unexpected len at idx %d", idx) 150 } 151 for i := range out { 152 if in[i] == nil { 153 if out[i] { 154 t.Errorf("Unexpected value at idx %d", idx) 155 } 156 } else { 157 if e, a := *(in[i]), out[i]; e != a { 158 t.Errorf("Unexpected value at idx %d", idx) 159 } 160 } 161 } 162 163 out2 := BoolSlice(out) 164 if e, a := len(out2), len(in); e != a { 165 t.Errorf("Unexpected len at idx %d", idx) 166 } 167 for i := range out2 { 168 if in[i] == nil { 169 if *(out2[i]) { 170 t.Errorf("Unexpected value at idx %d", idx) 171 } 172 } else { 173 if e, a := in[i], out2[i]; e != a { 174 t.Errorf("Unexpected value at idx %d", idx) 175 } 176 } 177 } 178 } 179 } 180 181 var testCasesBoolMap = []map[string]bool{ 182 {"a": true, "b": false, "c": true}, 183 } 184 185 func TestBoolMap(t *testing.T) { 186 for idx, in := range testCasesBoolMap { 187 if in == nil { 188 continue 189 } 190 out := BoolMap(in) 191 if e, a := len(out), len(in); e != a { 192 t.Errorf("Unexpected len at idx %d", idx) 193 } 194 for i := range out { 195 if e, a := in[i], *(out[i]); e != a { 196 t.Errorf("Unexpected value at idx %d", idx) 197 } 198 } 199 200 out2 := BoolValueMap(out) 201 if e, a := len(out2), len(in); e != a { 202 t.Errorf("Unexpected len at idx %d", idx) 203 } 204 if e, a := in, out2; !reflect.DeepEqual(e, a) { 205 t.Errorf("Unexpected value at idx %d", idx) 206 } 207 } 208 } 209 210 var testCasesUintSlice = [][]uint{ 211 {1, 2, 3, 4}, 212 } 213 214 func TestUintSlice(t *testing.T) { 215 for idx, in := range testCasesUintSlice { 216 if in == nil { 217 continue 218 } 219 out := UintSlice(in) 220 if e, a := len(out), len(in); e != a { 221 t.Errorf("Unexpected len at idx %d", idx) 222 } 223 for i := range out { 224 if e, a := in[i], *(out[i]); e != a { 225 t.Errorf("Unexpected value at idx %d", idx) 226 } 227 } 228 229 out2 := UintValueSlice(out) 230 if e, a := len(out2), len(in); e != a { 231 t.Errorf("Unexpected len at idx %d", idx) 232 } 233 if e, a := in, out2; !reflect.DeepEqual(e, a) { 234 t.Errorf("Unexpected value at idx %d", idx) 235 } 236 } 237 } 238 239 var testCasesUintValueSlice = [][]*uint{} 240 241 func TestUintValueSlice(t *testing.T) { 242 for idx, in := range testCasesUintValueSlice { 243 if in == nil { 244 continue 245 } 246 out := UintValueSlice(in) 247 if e, a := len(out), len(in); e != a { 248 t.Errorf("Unexpected len at idx %d", idx) 249 } 250 for i := range out { 251 if in[i] == nil { 252 if out[i] != 0 { 253 t.Errorf("Unexpected value at idx %d", idx) 254 } 255 } else { 256 if e, a := *(in[i]), out[i]; e != a { 257 t.Errorf("Unexpected value at idx %d", idx) 258 } 259 } 260 } 261 262 out2 := UintSlice(out) 263 if e, a := len(out2), len(in); e != a { 264 t.Errorf("Unexpected len at idx %d", idx) 265 } 266 for i := range out2 { 267 if in[i] == nil { 268 if *(out2[i]) != 0 { 269 t.Errorf("Unexpected value at idx %d", idx) 270 } 271 } else { 272 if e, a := in[i], out2[i]; e != a { 273 t.Errorf("Unexpected value at idx %d", idx) 274 } 275 } 276 } 277 } 278 } 279 280 var testCasesUintMap = []map[string]uint{ 281 {"a": 3, "b": 2, "c": 1}, 282 } 283 284 func TestUintMap(t *testing.T) { 285 for idx, in := range testCasesUintMap { 286 if in == nil { 287 continue 288 } 289 out := UintMap(in) 290 if e, a := len(out), len(in); e != a { 291 t.Errorf("Unexpected len at idx %d", idx) 292 } 293 for i := range out { 294 if e, a := in[i], *(out[i]); e != a { 295 t.Errorf("Unexpected value at idx %d", idx) 296 } 297 } 298 299 out2 := UintValueMap(out) 300 if e, a := len(out2), len(in); e != a { 301 t.Errorf("Unexpected len at idx %d", idx) 302 } 303 if e, a := in, out2; !reflect.DeepEqual(e, a) { 304 t.Errorf("Unexpected value at idx %d", idx) 305 } 306 } 307 } 308 309 var testCasesIntSlice = [][]int{ 310 {1, 2, 3, 4}, 311 } 312 313 func TestIntSlice(t *testing.T) { 314 for idx, in := range testCasesIntSlice { 315 if in == nil { 316 continue 317 } 318 out := IntSlice(in) 319 if e, a := len(out), len(in); e != a { 320 t.Errorf("Unexpected len at idx %d", idx) 321 } 322 for i := range out { 323 if e, a := in[i], *(out[i]); e != a { 324 t.Errorf("Unexpected value at idx %d", idx) 325 } 326 } 327 328 out2 := IntValueSlice(out) 329 if e, a := len(out2), len(in); e != a { 330 t.Errorf("Unexpected len at idx %d", idx) 331 } 332 if e, a := in, out2; !reflect.DeepEqual(e, a) { 333 t.Errorf("Unexpected value at idx %d", idx) 334 } 335 } 336 } 337 338 var testCasesIntValueSlice = [][]*int{} 339 340 func TestIntValueSlice(t *testing.T) { 341 for idx, in := range testCasesIntValueSlice { 342 if in == nil { 343 continue 344 } 345 out := IntValueSlice(in) 346 if e, a := len(out), len(in); e != a { 347 t.Errorf("Unexpected len at idx %d", idx) 348 } 349 for i := range out { 350 if in[i] == nil { 351 if out[i] != 0 { 352 t.Errorf("Unexpected value at idx %d", idx) 353 } 354 } else { 355 if e, a := *(in[i]), out[i]; e != a { 356 t.Errorf("Unexpected value at idx %d", idx) 357 } 358 } 359 } 360 361 out2 := IntSlice(out) 362 if e, a := len(out2), len(in); e != a { 363 t.Errorf("Unexpected len at idx %d", idx) 364 } 365 for i := range out2 { 366 if in[i] == nil { 367 if *(out2[i]) != 0 { 368 t.Errorf("Unexpected value at idx %d", idx) 369 } 370 } else { 371 if e, a := in[i], out2[i]; e != a { 372 t.Errorf("Unexpected value at idx %d", idx) 373 } 374 } 375 } 376 } 377 } 378 379 var testCasesIntMap = []map[string]int{ 380 {"a": 3, "b": 2, "c": 1}, 381 } 382 383 func TestIntMap(t *testing.T) { 384 for idx, in := range testCasesIntMap { 385 if in == nil { 386 continue 387 } 388 out := IntMap(in) 389 if e, a := len(out), len(in); e != a { 390 t.Errorf("Unexpected len at idx %d", idx) 391 } 392 for i := range out { 393 if e, a := in[i], *(out[i]); e != a { 394 t.Errorf("Unexpected value at idx %d", idx) 395 } 396 } 397 398 out2 := IntValueMap(out) 399 if e, a := len(out2), len(in); e != a { 400 t.Errorf("Unexpected len at idx %d", idx) 401 } 402 if e, a := in, out2; !reflect.DeepEqual(e, a) { 403 t.Errorf("Unexpected value at idx %d", idx) 404 } 405 } 406 } 407 408 var testCasesInt8Slice = [][]int8{ 409 {1, 2, 3, 4}, 410 } 411 412 func TestInt8Slice(t *testing.T) { 413 for idx, in := range testCasesInt8Slice { 414 if in == nil { 415 continue 416 } 417 out := Int8Slice(in) 418 if e, a := len(out), len(in); e != a { 419 t.Errorf("Unexpected len at idx %d", idx) 420 } 421 for i := range out { 422 if e, a := in[i], *(out[i]); e != a { 423 t.Errorf("Unexpected value at idx %d", idx) 424 } 425 } 426 427 out2 := Int8ValueSlice(out) 428 if e, a := len(out2), len(in); e != a { 429 t.Errorf("Unexpected len at idx %d", idx) 430 } 431 if e, a := in, out2; !reflect.DeepEqual(e, a) { 432 t.Errorf("Unexpected value at idx %d", idx) 433 } 434 } 435 } 436 437 var testCasesInt8ValueSlice = [][]*int8{} 438 439 func TestInt8ValueSlice(t *testing.T) { 440 for idx, in := range testCasesInt8ValueSlice { 441 if in == nil { 442 continue 443 } 444 out := Int8ValueSlice(in) 445 if e, a := len(out), len(in); e != a { 446 t.Errorf("Unexpected len at idx %d", idx) 447 } 448 for i := range out { 449 if in[i] == nil { 450 if out[i] != 0 { 451 t.Errorf("Unexpected value at idx %d", idx) 452 } 453 } else { 454 if e, a := *(in[i]), out[i]; e != a { 455 t.Errorf("Unexpected value at idx %d", idx) 456 } 457 } 458 } 459 460 out2 := Int8Slice(out) 461 if e, a := len(out2), len(in); e != a { 462 t.Errorf("Unexpected len at idx %d", idx) 463 } 464 for i := range out2 { 465 if in[i] == nil { 466 if *(out2[i]) != 0 { 467 t.Errorf("Unexpected value at idx %d", idx) 468 } 469 } else { 470 if e, a := in[i], out2[i]; e != a { 471 t.Errorf("Unexpected value at idx %d", idx) 472 } 473 } 474 } 475 } 476 } 477 478 var testCasesInt8Map = []map[string]int8{ 479 {"a": 3, "b": 2, "c": 1}, 480 } 481 482 func TestInt8Map(t *testing.T) { 483 for idx, in := range testCasesInt8Map { 484 if in == nil { 485 continue 486 } 487 out := Int8Map(in) 488 if e, a := len(out), len(in); e != a { 489 t.Errorf("Unexpected len at idx %d", idx) 490 } 491 for i := range out { 492 if e, a := in[i], *(out[i]); e != a { 493 t.Errorf("Unexpected value at idx %d", idx) 494 } 495 } 496 497 out2 := Int8ValueMap(out) 498 if e, a := len(out2), len(in); e != a { 499 t.Errorf("Unexpected len at idx %d", idx) 500 } 501 if e, a := in, out2; !reflect.DeepEqual(e, a) { 502 t.Errorf("Unexpected value at idx %d", idx) 503 } 504 } 505 } 506 507 var testCasesInt16Slice = [][]int16{ 508 {1, 2, 3, 4}, 509 } 510 511 func TestInt16Slice(t *testing.T) { 512 for idx, in := range testCasesInt16Slice { 513 if in == nil { 514 continue 515 } 516 out := Int16Slice(in) 517 if e, a := len(out), len(in); e != a { 518 t.Errorf("Unexpected len at idx %d", idx) 519 } 520 for i := range out { 521 if e, a := in[i], *(out[i]); e != a { 522 t.Errorf("Unexpected value at idx %d", idx) 523 } 524 } 525 526 out2 := Int16ValueSlice(out) 527 if e, a := len(out2), len(in); e != a { 528 t.Errorf("Unexpected len at idx %d", idx) 529 } 530 if e, a := in, out2; !reflect.DeepEqual(e, a) { 531 t.Errorf("Unexpected value at idx %d", idx) 532 } 533 } 534 } 535 536 var testCasesInt16ValueSlice = [][]*int16{} 537 538 func TestInt16ValueSlice(t *testing.T) { 539 for idx, in := range testCasesInt16ValueSlice { 540 if in == nil { 541 continue 542 } 543 out := Int16ValueSlice(in) 544 if e, a := len(out), len(in); e != a { 545 t.Errorf("Unexpected len at idx %d", idx) 546 } 547 for i := range out { 548 if in[i] == nil { 549 if out[i] != 0 { 550 t.Errorf("Unexpected value at idx %d", idx) 551 } 552 } else { 553 if e, a := *(in[i]), out[i]; e != a { 554 t.Errorf("Unexpected value at idx %d", idx) 555 } 556 } 557 } 558 559 out2 := Int16Slice(out) 560 if e, a := len(out2), len(in); e != a { 561 t.Errorf("Unexpected len at idx %d", idx) 562 } 563 for i := range out2 { 564 if in[i] == nil { 565 if *(out2[i]) != 0 { 566 t.Errorf("Unexpected value at idx %d", idx) 567 } 568 } else { 569 if e, a := in[i], out2[i]; e != a { 570 t.Errorf("Unexpected value at idx %d", idx) 571 } 572 } 573 } 574 } 575 } 576 577 var testCasesInt16Map = []map[string]int16{ 578 {"a": 3, "b": 2, "c": 1}, 579 } 580 581 func TestInt16Map(t *testing.T) { 582 for idx, in := range testCasesInt16Map { 583 if in == nil { 584 continue 585 } 586 out := Int16Map(in) 587 if e, a := len(out), len(in); e != a { 588 t.Errorf("Unexpected len at idx %d", idx) 589 } 590 for i := range out { 591 if e, a := in[i], *(out[i]); e != a { 592 t.Errorf("Unexpected value at idx %d", idx) 593 } 594 } 595 596 out2 := Int16ValueMap(out) 597 if e, a := len(out2), len(in); e != a { 598 t.Errorf("Unexpected len at idx %d", idx) 599 } 600 if e, a := in, out2; !reflect.DeepEqual(e, a) { 601 t.Errorf("Unexpected value at idx %d", idx) 602 } 603 } 604 } 605 606 var testCasesInt32Slice = [][]int32{ 607 {1, 2, 3, 4}, 608 } 609 610 func TestInt32Slice(t *testing.T) { 611 for idx, in := range testCasesInt32Slice { 612 if in == nil { 613 continue 614 } 615 out := Int32Slice(in) 616 if e, a := len(out), len(in); e != a { 617 t.Errorf("Unexpected len at idx %d", idx) 618 } 619 for i := range out { 620 if e, a := in[i], *(out[i]); e != a { 621 t.Errorf("Unexpected value at idx %d", idx) 622 } 623 } 624 625 out2 := Int32ValueSlice(out) 626 if e, a := len(out2), len(in); e != a { 627 t.Errorf("Unexpected len at idx %d", idx) 628 } 629 if e, a := in, out2; !reflect.DeepEqual(e, a) { 630 t.Errorf("Unexpected value at idx %d", idx) 631 } 632 } 633 } 634 635 var testCasesInt32ValueSlice = [][]*int32{} 636 637 func TestInt32ValueSlice(t *testing.T) { 638 for idx, in := range testCasesInt32ValueSlice { 639 if in == nil { 640 continue 641 } 642 out := Int32ValueSlice(in) 643 if e, a := len(out), len(in); e != a { 644 t.Errorf("Unexpected len at idx %d", idx) 645 } 646 for i := range out { 647 if in[i] == nil { 648 if out[i] != 0 { 649 t.Errorf("Unexpected value at idx %d", idx) 650 } 651 } else { 652 if e, a := *(in[i]), out[i]; e != a { 653 t.Errorf("Unexpected value at idx %d", idx) 654 } 655 } 656 } 657 658 out2 := Int32Slice(out) 659 if e, a := len(out2), len(in); e != a { 660 t.Errorf("Unexpected len at idx %d", idx) 661 } 662 for i := range out2 { 663 if in[i] == nil { 664 if *(out2[i]) != 0 { 665 t.Errorf("Unexpected value at idx %d", idx) 666 } 667 } else { 668 if e, a := in[i], out2[i]; e != a { 669 t.Errorf("Unexpected value at idx %d", idx) 670 } 671 } 672 } 673 } 674 } 675 676 var testCasesInt32Map = []map[string]int32{ 677 {"a": 3, "b": 2, "c": 1}, 678 } 679 680 func TestInt32Map(t *testing.T) { 681 for idx, in := range testCasesInt32Map { 682 if in == nil { 683 continue 684 } 685 out := Int32Map(in) 686 if e, a := len(out), len(in); e != a { 687 t.Errorf("Unexpected len at idx %d", idx) 688 } 689 for i := range out { 690 if e, a := in[i], *(out[i]); e != a { 691 t.Errorf("Unexpected value at idx %d", idx) 692 } 693 } 694 695 out2 := Int32ValueMap(out) 696 if e, a := len(out2), len(in); e != a { 697 t.Errorf("Unexpected len at idx %d", idx) 698 } 699 if e, a := in, out2; !reflect.DeepEqual(e, a) { 700 t.Errorf("Unexpected value at idx %d", idx) 701 } 702 } 703 } 704 705 var testCasesInt64Slice = [][]int64{ 706 {1, 2, 3, 4}, 707 } 708 709 func TestInt64Slice(t *testing.T) { 710 for idx, in := range testCasesInt64Slice { 711 if in == nil { 712 continue 713 } 714 out := Int64Slice(in) 715 if e, a := len(out), len(in); e != a { 716 t.Errorf("Unexpected len at idx %d", idx) 717 } 718 for i := range out { 719 if e, a := in[i], *(out[i]); e != a { 720 t.Errorf("Unexpected value at idx %d", idx) 721 } 722 } 723 724 out2 := Int64ValueSlice(out) 725 if e, a := len(out2), len(in); e != a { 726 t.Errorf("Unexpected len at idx %d", idx) 727 } 728 if e, a := in, out2; !reflect.DeepEqual(e, a) { 729 t.Errorf("Unexpected value at idx %d", idx) 730 } 731 } 732 } 733 734 var testCasesInt64ValueSlice = [][]*int64{} 735 736 func TestInt64ValueSlice(t *testing.T) { 737 for idx, in := range testCasesInt64ValueSlice { 738 if in == nil { 739 continue 740 } 741 out := Int64ValueSlice(in) 742 if e, a := len(out), len(in); e != a { 743 t.Errorf("Unexpected len at idx %d", idx) 744 } 745 for i := range out { 746 if in[i] == nil { 747 if out[i] != 0 { 748 t.Errorf("Unexpected value at idx %d", idx) 749 } 750 } else { 751 if e, a := *(in[i]), out[i]; e != a { 752 t.Errorf("Unexpected value at idx %d", idx) 753 } 754 } 755 } 756 757 out2 := Int64Slice(out) 758 if e, a := len(out2), len(in); e != a { 759 t.Errorf("Unexpected len at idx %d", idx) 760 } 761 for i := range out2 { 762 if in[i] == nil { 763 if *(out2[i]) != 0 { 764 t.Errorf("Unexpected value at idx %d", idx) 765 } 766 } else { 767 if e, a := in[i], out2[i]; e != a { 768 t.Errorf("Unexpected value at idx %d", idx) 769 } 770 } 771 } 772 } 773 } 774 775 var testCasesInt64Map = []map[string]int64{ 776 {"a": 3, "b": 2, "c": 1}, 777 } 778 779 func TestInt64Map(t *testing.T) { 780 for idx, in := range testCasesInt64Map { 781 if in == nil { 782 continue 783 } 784 out := Int64Map(in) 785 if e, a := len(out), len(in); e != a { 786 t.Errorf("Unexpected len at idx %d", idx) 787 } 788 for i := range out { 789 if e, a := in[i], *(out[i]); e != a { 790 t.Errorf("Unexpected value at idx %d", idx) 791 } 792 } 793 794 out2 := Int64ValueMap(out) 795 if e, a := len(out2), len(in); e != a { 796 t.Errorf("Unexpected len at idx %d", idx) 797 } 798 if e, a := in, out2; !reflect.DeepEqual(e, a) { 799 t.Errorf("Unexpected value at idx %d", idx) 800 } 801 } 802 } 803 804 var testCasesUint8Slice = [][]uint8{ 805 {1, 2, 3, 4}, 806 } 807 808 func TestUint8Slice(t *testing.T) { 809 for idx, in := range testCasesUint8Slice { 810 if in == nil { 811 continue 812 } 813 out := Uint8Slice(in) 814 if e, a := len(out), len(in); e != a { 815 t.Errorf("Unexpected len at idx %d", idx) 816 } 817 for i := range out { 818 if e, a := in[i], *(out[i]); e != a { 819 t.Errorf("Unexpected value at idx %d", idx) 820 } 821 } 822 823 out2 := Uint8ValueSlice(out) 824 if e, a := len(out2), len(in); e != a { 825 t.Errorf("Unexpected len at idx %d", idx) 826 } 827 if e, a := in, out2; !reflect.DeepEqual(e, a) { 828 t.Errorf("Unexpected value at idx %d", idx) 829 } 830 } 831 } 832 833 var testCasesUint8ValueSlice = [][]*uint8{} 834 835 func TestUint8ValueSlice(t *testing.T) { 836 for idx, in := range testCasesUint8ValueSlice { 837 if in == nil { 838 continue 839 } 840 out := Uint8ValueSlice(in) 841 if e, a := len(out), len(in); e != a { 842 t.Errorf("Unexpected len at idx %d", idx) 843 } 844 for i := range out { 845 if in[i] == nil { 846 if out[i] != 0 { 847 t.Errorf("Unexpected value at idx %d", idx) 848 } 849 } else { 850 if e, a := *(in[i]), out[i]; e != a { 851 t.Errorf("Unexpected value at idx %d", idx) 852 } 853 } 854 } 855 856 out2 := Uint8Slice(out) 857 if e, a := len(out2), len(in); e != a { 858 t.Errorf("Unexpected len at idx %d", idx) 859 } 860 for i := range out2 { 861 if in[i] == nil { 862 if *(out2[i]) != 0 { 863 t.Errorf("Unexpected value at idx %d", idx) 864 } 865 } else { 866 if e, a := in[i], out2[i]; e != a { 867 t.Errorf("Unexpected value at idx %d", idx) 868 } 869 } 870 } 871 } 872 } 873 874 var testCasesUint8Map = []map[string]uint8{ 875 {"a": 3, "b": 2, "c": 1}, 876 } 877 878 func TestUint8Map(t *testing.T) { 879 for idx, in := range testCasesUint8Map { 880 if in == nil { 881 continue 882 } 883 out := Uint8Map(in) 884 if e, a := len(out), len(in); e != a { 885 t.Errorf("Unexpected len at idx %d", idx) 886 } 887 for i := range out { 888 if e, a := in[i], *(out[i]); e != a { 889 t.Errorf("Unexpected value at idx %d", idx) 890 } 891 } 892 893 out2 := Uint8ValueMap(out) 894 if e, a := len(out2), len(in); e != a { 895 t.Errorf("Unexpected len at idx %d", idx) 896 } 897 if e, a := in, out2; !reflect.DeepEqual(e, a) { 898 t.Errorf("Unexpected value at idx %d", idx) 899 } 900 } 901 } 902 903 var testCasesUint16Slice = [][]uint16{ 904 {1, 2, 3, 4}, 905 } 906 907 func TestUint16Slice(t *testing.T) { 908 for idx, in := range testCasesUint16Slice { 909 if in == nil { 910 continue 911 } 912 out := Uint16Slice(in) 913 if e, a := len(out), len(in); e != a { 914 t.Errorf("Unexpected len at idx %d", idx) 915 } 916 for i := range out { 917 if e, a := in[i], *(out[i]); e != a { 918 t.Errorf("Unexpected value at idx %d", idx) 919 } 920 } 921 922 out2 := Uint16ValueSlice(out) 923 if e, a := len(out2), len(in); e != a { 924 t.Errorf("Unexpected len at idx %d", idx) 925 } 926 if e, a := in, out2; !reflect.DeepEqual(e, a) { 927 t.Errorf("Unexpected value at idx %d", idx) 928 } 929 } 930 } 931 932 var testCasesUint16ValueSlice = [][]*uint16{} 933 934 func TestUint16ValueSlice(t *testing.T) { 935 for idx, in := range testCasesUint16ValueSlice { 936 if in == nil { 937 continue 938 } 939 out := Uint16ValueSlice(in) 940 if e, a := len(out), len(in); e != a { 941 t.Errorf("Unexpected len at idx %d", idx) 942 } 943 for i := range out { 944 if in[i] == nil { 945 if out[i] != 0 { 946 t.Errorf("Unexpected value at idx %d", idx) 947 } 948 } else { 949 if e, a := *(in[i]), out[i]; e != a { 950 t.Errorf("Unexpected value at idx %d", idx) 951 } 952 } 953 } 954 955 out2 := Uint16Slice(out) 956 if e, a := len(out2), len(in); e != a { 957 t.Errorf("Unexpected len at idx %d", idx) 958 } 959 for i := range out2 { 960 if in[i] == nil { 961 if *(out2[i]) != 0 { 962 t.Errorf("Unexpected value at idx %d", idx) 963 } 964 } else { 965 if e, a := in[i], out2[i]; e != a { 966 t.Errorf("Unexpected value at idx %d", idx) 967 } 968 } 969 } 970 } 971 } 972 973 var testCasesUint16Map = []map[string]uint16{ 974 {"a": 3, "b": 2, "c": 1}, 975 } 976 977 func TestUint16Map(t *testing.T) { 978 for idx, in := range testCasesUint16Map { 979 if in == nil { 980 continue 981 } 982 out := Uint16Map(in) 983 if e, a := len(out), len(in); e != a { 984 t.Errorf("Unexpected len at idx %d", idx) 985 } 986 for i := range out { 987 if e, a := in[i], *(out[i]); e != a { 988 t.Errorf("Unexpected value at idx %d", idx) 989 } 990 } 991 992 out2 := Uint16ValueMap(out) 993 if e, a := len(out2), len(in); e != a { 994 t.Errorf("Unexpected len at idx %d", idx) 995 } 996 if e, a := in, out2; !reflect.DeepEqual(e, a) { 997 t.Errorf("Unexpected value at idx %d", idx) 998 } 999 } 1000 } 1001 1002 var testCasesUint32Slice = [][]uint32{ 1003 {1, 2, 3, 4}, 1004 } 1005 1006 func TestUint32Slice(t *testing.T) { 1007 for idx, in := range testCasesUint32Slice { 1008 if in == nil { 1009 continue 1010 } 1011 out := Uint32Slice(in) 1012 if e, a := len(out), len(in); e != a { 1013 t.Errorf("Unexpected len at idx %d", idx) 1014 } 1015 for i := range out { 1016 if e, a := in[i], *(out[i]); e != a { 1017 t.Errorf("Unexpected value at idx %d", idx) 1018 } 1019 } 1020 1021 out2 := Uint32ValueSlice(out) 1022 if e, a := len(out2), len(in); e != a { 1023 t.Errorf("Unexpected len at idx %d", idx) 1024 } 1025 if e, a := in, out2; !reflect.DeepEqual(e, a) { 1026 t.Errorf("Unexpected value at idx %d", idx) 1027 } 1028 } 1029 } 1030 1031 var testCasesUint32ValueSlice = [][]*uint32{} 1032 1033 func TestUint32ValueSlice(t *testing.T) { 1034 for idx, in := range testCasesUint32ValueSlice { 1035 if in == nil { 1036 continue 1037 } 1038 out := Uint32ValueSlice(in) 1039 if e, a := len(out), len(in); e != a { 1040 t.Errorf("Unexpected len at idx %d", idx) 1041 } 1042 for i := range out { 1043 if in[i] == nil { 1044 if out[i] != 0 { 1045 t.Errorf("Unexpected value at idx %d", idx) 1046 } 1047 } else { 1048 if e, a := *(in[i]), out[i]; e != a { 1049 t.Errorf("Unexpected value at idx %d", idx) 1050 } 1051 } 1052 } 1053 1054 out2 := Uint32Slice(out) 1055 if e, a := len(out2), len(in); e != a { 1056 t.Errorf("Unexpected len at idx %d", idx) 1057 } 1058 for i := range out2 { 1059 if in[i] == nil { 1060 if *(out2[i]) != 0 { 1061 t.Errorf("Unexpected value at idx %d", idx) 1062 } 1063 } else { 1064 if e, a := in[i], out2[i]; e != a { 1065 t.Errorf("Unexpected value at idx %d", idx) 1066 } 1067 } 1068 } 1069 } 1070 } 1071 1072 var testCasesUint32Map = []map[string]uint32{ 1073 {"a": 3, "b": 2, "c": 1}, 1074 } 1075 1076 func TestUint32Map(t *testing.T) { 1077 for idx, in := range testCasesUint32Map { 1078 if in == nil { 1079 continue 1080 } 1081 out := Uint32Map(in) 1082 if e, a := len(out), len(in); e != a { 1083 t.Errorf("Unexpected len at idx %d", idx) 1084 } 1085 for i := range out { 1086 if e, a := in[i], *(out[i]); e != a { 1087 t.Errorf("Unexpected value at idx %d", idx) 1088 } 1089 } 1090 1091 out2 := Uint32ValueMap(out) 1092 if e, a := len(out2), len(in); e != a { 1093 t.Errorf("Unexpected len at idx %d", idx) 1094 } 1095 if e, a := in, out2; !reflect.DeepEqual(e, a) { 1096 t.Errorf("Unexpected value at idx %d", idx) 1097 } 1098 } 1099 } 1100 1101 var testCasesUint64Slice = [][]uint64{ 1102 {1, 2, 3, 4}, 1103 } 1104 1105 func TestUint64Slice(t *testing.T) { 1106 for idx, in := range testCasesUint64Slice { 1107 if in == nil { 1108 continue 1109 } 1110 out := Uint64Slice(in) 1111 if e, a := len(out), len(in); e != a { 1112 t.Errorf("Unexpected len at idx %d", idx) 1113 } 1114 for i := range out { 1115 if e, a := in[i], *(out[i]); e != a { 1116 t.Errorf("Unexpected value at idx %d", idx) 1117 } 1118 } 1119 1120 out2 := Uint64ValueSlice(out) 1121 if e, a := len(out2), len(in); e != a { 1122 t.Errorf("Unexpected len at idx %d", idx) 1123 } 1124 if e, a := in, out2; !reflect.DeepEqual(e, a) { 1125 t.Errorf("Unexpected value at idx %d", idx) 1126 } 1127 } 1128 } 1129 1130 var testCasesUint64ValueSlice = [][]*uint64{} 1131 1132 func TestUint64ValueSlice(t *testing.T) { 1133 for idx, in := range testCasesUint64ValueSlice { 1134 if in == nil { 1135 continue 1136 } 1137 out := Uint64ValueSlice(in) 1138 if e, a := len(out), len(in); e != a { 1139 t.Errorf("Unexpected len at idx %d", idx) 1140 } 1141 for i := range out { 1142 if in[i] == nil { 1143 if out[i] != 0 { 1144 t.Errorf("Unexpected value at idx %d", idx) 1145 } 1146 } else { 1147 if e, a := *(in[i]), out[i]; e != a { 1148 t.Errorf("Unexpected value at idx %d", idx) 1149 } 1150 } 1151 } 1152 1153 out2 := Uint64Slice(out) 1154 if e, a := len(out2), len(in); e != a { 1155 t.Errorf("Unexpected len at idx %d", idx) 1156 } 1157 for i := range out2 { 1158 if in[i] == nil { 1159 if *(out2[i]) != 0 { 1160 t.Errorf("Unexpected value at idx %d", idx) 1161 } 1162 } else { 1163 if e, a := in[i], out2[i]; e != a { 1164 t.Errorf("Unexpected value at idx %d", idx) 1165 } 1166 } 1167 } 1168 } 1169 } 1170 1171 var testCasesUint64Map = []map[string]uint64{ 1172 {"a": 3, "b": 2, "c": 1}, 1173 } 1174 1175 func TestUint64Map(t *testing.T) { 1176 for idx, in := range testCasesUint64Map { 1177 if in == nil { 1178 continue 1179 } 1180 out := Uint64Map(in) 1181 if e, a := len(out), len(in); e != a { 1182 t.Errorf("Unexpected len at idx %d", idx) 1183 } 1184 for i := range out { 1185 if e, a := in[i], *(out[i]); e != a { 1186 t.Errorf("Unexpected value at idx %d", idx) 1187 } 1188 } 1189 1190 out2 := Uint64ValueMap(out) 1191 if e, a := len(out2), len(in); e != a { 1192 t.Errorf("Unexpected len at idx %d", idx) 1193 } 1194 if e, a := in, out2; !reflect.DeepEqual(e, a) { 1195 t.Errorf("Unexpected value at idx %d", idx) 1196 } 1197 } 1198 } 1199 1200 var testCasesFloat32Slice = [][]float32{ 1201 {1, 2, 3, 4}, 1202 } 1203 1204 func TestFloat32Slice(t *testing.T) { 1205 for idx, in := range testCasesFloat32Slice { 1206 if in == nil { 1207 continue 1208 } 1209 out := Float32Slice(in) 1210 if e, a := len(out), len(in); e != a { 1211 t.Errorf("Unexpected len at idx %d", idx) 1212 } 1213 for i := range out { 1214 if e, a := in[i], *(out[i]); e != a { 1215 t.Errorf("Unexpected value at idx %d", idx) 1216 } 1217 } 1218 1219 out2 := Float32ValueSlice(out) 1220 if e, a := len(out2), len(in); e != a { 1221 t.Errorf("Unexpected len at idx %d", idx) 1222 } 1223 if e, a := in, out2; !reflect.DeepEqual(e, a) { 1224 t.Errorf("Unexpected value at idx %d", idx) 1225 } 1226 } 1227 } 1228 1229 var testCasesFloat32ValueSlice = [][]*float32{} 1230 1231 func TestFloat32ValueSlice(t *testing.T) { 1232 for idx, in := range testCasesFloat32ValueSlice { 1233 if in == nil { 1234 continue 1235 } 1236 out := Float32ValueSlice(in) 1237 if e, a := len(out), len(in); e != a { 1238 t.Errorf("Unexpected len at idx %d", idx) 1239 } 1240 for i := range out { 1241 if in[i] == nil { 1242 if out[i] != 0 { 1243 t.Errorf("Unexpected value at idx %d", idx) 1244 } 1245 } else { 1246 if e, a := *(in[i]), out[i]; e != a { 1247 t.Errorf("Unexpected value at idx %d", idx) 1248 } 1249 } 1250 } 1251 1252 out2 := Float32Slice(out) 1253 if e, a := len(out2), len(in); e != a { 1254 t.Errorf("Unexpected len at idx %d", idx) 1255 } 1256 for i := range out2 { 1257 if in[i] == nil { 1258 if *(out2[i]) != 0 { 1259 t.Errorf("Unexpected value at idx %d", idx) 1260 } 1261 } else { 1262 if e, a := in[i], out2[i]; e != a { 1263 t.Errorf("Unexpected value at idx %d", idx) 1264 } 1265 } 1266 } 1267 } 1268 } 1269 1270 var testCasesFloat32Map = []map[string]float32{ 1271 {"a": 3, "b": 2, "c": 1}, 1272 } 1273 1274 func TestFloat32Map(t *testing.T) { 1275 for idx, in := range testCasesFloat32Map { 1276 if in == nil { 1277 continue 1278 } 1279 out := Float32Map(in) 1280 if e, a := len(out), len(in); e != a { 1281 t.Errorf("Unexpected len at idx %d", idx) 1282 } 1283 for i := range out { 1284 if e, a := in[i], *(out[i]); e != a { 1285 t.Errorf("Unexpected value at idx %d", idx) 1286 } 1287 } 1288 1289 out2 := Float32ValueMap(out) 1290 if e, a := len(out2), len(in); e != a { 1291 t.Errorf("Unexpected len at idx %d", idx) 1292 } 1293 if e, a := in, out2; !reflect.DeepEqual(e, a) { 1294 t.Errorf("Unexpected value at idx %d", idx) 1295 } 1296 } 1297 } 1298 1299 var testCasesFloat64Slice = [][]float64{ 1300 {1, 2, 3, 4}, 1301 } 1302 1303 func TestFloat64Slice(t *testing.T) { 1304 for idx, in := range testCasesFloat64Slice { 1305 if in == nil { 1306 continue 1307 } 1308 out := Float64Slice(in) 1309 if e, a := len(out), len(in); e != a { 1310 t.Errorf("Unexpected len at idx %d", idx) 1311 } 1312 for i := range out { 1313 if e, a := in[i], *(out[i]); e != a { 1314 t.Errorf("Unexpected value at idx %d", idx) 1315 } 1316 } 1317 1318 out2 := Float64ValueSlice(out) 1319 if e, a := len(out2), len(in); e != a { 1320 t.Errorf("Unexpected len at idx %d", idx) 1321 } 1322 if e, a := in, out2; !reflect.DeepEqual(e, a) { 1323 t.Errorf("Unexpected value at idx %d", idx) 1324 } 1325 } 1326 } 1327 1328 var testCasesFloat64ValueSlice = [][]*float64{} 1329 1330 func TestFloat64ValueSlice(t *testing.T) { 1331 for idx, in := range testCasesFloat64ValueSlice { 1332 if in == nil { 1333 continue 1334 } 1335 out := Float64ValueSlice(in) 1336 if e, a := len(out), len(in); e != a { 1337 t.Errorf("Unexpected len at idx %d", idx) 1338 } 1339 for i := range out { 1340 if in[i] == nil { 1341 if out[i] != 0 { 1342 t.Errorf("Unexpected value at idx %d", idx) 1343 } 1344 } else { 1345 if e, a := *(in[i]), out[i]; e != a { 1346 t.Errorf("Unexpected value at idx %d", idx) 1347 } 1348 } 1349 } 1350 1351 out2 := Float64Slice(out) 1352 if e, a := len(out2), len(in); e != a { 1353 t.Errorf("Unexpected len at idx %d", idx) 1354 } 1355 for i := range out2 { 1356 if in[i] == nil { 1357 if *(out2[i]) != 0 { 1358 t.Errorf("Unexpected value at idx %d", idx) 1359 } 1360 } else { 1361 if e, a := in[i], out2[i]; e != a { 1362 t.Errorf("Unexpected value at idx %d", idx) 1363 } 1364 } 1365 } 1366 } 1367 } 1368 1369 var testCasesFloat64Map = []map[string]float64{ 1370 {"a": 3, "b": 2, "c": 1}, 1371 } 1372 1373 func TestFloat64Map(t *testing.T) { 1374 for idx, in := range testCasesFloat64Map { 1375 if in == nil { 1376 continue 1377 } 1378 out := Float64Map(in) 1379 if e, a := len(out), len(in); e != a { 1380 t.Errorf("Unexpected len at idx %d", idx) 1381 } 1382 for i := range out { 1383 if e, a := in[i], *(out[i]); e != a { 1384 t.Errorf("Unexpected value at idx %d", idx) 1385 } 1386 } 1387 1388 out2 := Float64ValueMap(out) 1389 if e, a := len(out2), len(in); e != a { 1390 t.Errorf("Unexpected len at idx %d", idx) 1391 } 1392 if e, a := in, out2; !reflect.DeepEqual(e, a) { 1393 t.Errorf("Unexpected value at idx %d", idx) 1394 } 1395 } 1396 } 1397 1398 var testCasesTimeSlice = [][]time.Time{ 1399 {time.Now(), time.Now().AddDate(100, 0, 0)}, 1400 } 1401 1402 func TestTimeSlice(t *testing.T) { 1403 for idx, in := range testCasesTimeSlice { 1404 if in == nil { 1405 continue 1406 } 1407 out := TimeSlice(in) 1408 if e, a := len(out), len(in); e != a { 1409 t.Errorf("Unexpected len at idx %d", idx) 1410 } 1411 for i := range out { 1412 if e, a := in[i], *(out[i]); e != a { 1413 t.Errorf("Unexpected value at idx %d", idx) 1414 } 1415 } 1416 1417 out2 := TimeValueSlice(out) 1418 if e, a := len(out2), len(in); e != a { 1419 t.Errorf("Unexpected len at idx %d", idx) 1420 } 1421 if e, a := in, out2; !reflect.DeepEqual(e, a) { 1422 t.Errorf("Unexpected value at idx %d", idx) 1423 } 1424 } 1425 } 1426 1427 var testCasesTimeValueSlice = [][]*time.Time{} 1428 1429 func TestTimeValueSlice(t *testing.T) { 1430 for idx, in := range testCasesTimeValueSlice { 1431 if in == nil { 1432 continue 1433 } 1434 out := TimeValueSlice(in) 1435 if e, a := len(out), len(in); e != a { 1436 t.Errorf("Unexpected len at idx %d", idx) 1437 } 1438 for i := range out { 1439 if in[i] == nil { 1440 if !out[i].IsZero() { 1441 t.Errorf("Unexpected value at idx %d", idx) 1442 } 1443 } else { 1444 if e, a := *(in[i]), out[i]; e != a { 1445 t.Errorf("Unexpected value at idx %d", idx) 1446 } 1447 } 1448 } 1449 1450 out2 := TimeSlice(out) 1451 if e, a := len(out2), len(in); e != a { 1452 t.Errorf("Unexpected len at idx %d", idx) 1453 } 1454 for i := range out2 { 1455 if in[i] == nil { 1456 if !(out2[i]).IsZero() { 1457 t.Errorf("Unexpected value at idx %d", idx) 1458 } 1459 } else { 1460 if e, a := in[i], out2[i]; e != a { 1461 t.Errorf("Unexpected value at idx %d", idx) 1462 } 1463 } 1464 } 1465 } 1466 } 1467 1468 var testCasesTimeMap = []map[string]time.Time{ 1469 {"a": time.Now().AddDate(-100, 0, 0), "b": time.Now()}, 1470 } 1471 1472 func TestTimeMap(t *testing.T) { 1473 for idx, in := range testCasesTimeMap { 1474 if in == nil { 1475 continue 1476 } 1477 out := TimeMap(in) 1478 if e, a := len(out), len(in); e != a { 1479 t.Errorf("Unexpected len at idx %d", idx) 1480 } 1481 for i := range out { 1482 if e, a := in[i], *(out[i]); e != a { 1483 t.Errorf("Unexpected value at idx %d", idx) 1484 } 1485 } 1486 1487 out2 := TimeValueMap(out) 1488 if e, a := len(out2), len(in); e != a { 1489 t.Errorf("Unexpected len at idx %d", idx) 1490 } 1491 if e, a := in, out2; !reflect.DeepEqual(e, a) { 1492 t.Errorf("Unexpected value at idx %d", idx) 1493 } 1494 } 1495 } 1496 1497 type TimeValueTestCase struct { 1498 in int64 1499 outSecs time.Time 1500 outMillis time.Time 1501 } 1502 1503 var testCasesTimeValue = []TimeValueTestCase{ 1504 { 1505 in: int64(1501558289000), 1506 outSecs: time.Unix(1501558289, 0), 1507 outMillis: time.Unix(1501558289, 0), 1508 }, 1509 { 1510 in: int64(1501558289001), 1511 outSecs: time.Unix(1501558289, 0), 1512 outMillis: time.Unix(1501558289, 1*1000000), 1513 }, 1514 } 1515 1516 func TestSecondsTimeValue(t *testing.T) { 1517 for idx, testCase := range testCasesTimeValue { 1518 out := SecondsTimeValue(&testCase.in) 1519 if e, a := testCase.outSecs, out; e != a { 1520 t.Errorf("Unexpected value for time value at %d", idx) 1521 } 1522 } 1523 } 1524 1525 func TestMillisecondsTimeValue(t *testing.T) { 1526 for idx, testCase := range testCasesTimeValue { 1527 out := MillisecondsTimeValue(&testCase.in) 1528 if e, a := testCase.outMillis, out; e != a { 1529 t.Errorf("Unexpected value for time value at %d", idx) 1530 } 1531 } 1532 }