github.com/prysmaticlabs/prysm@v1.4.4/shared/testutil/assertions/assertions_test.go (about) 1 package assertions_test 2 3 import ( 4 "errors" 5 "fmt" 6 "strings" 7 "testing" 8 9 eth "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 10 "github.com/prysmaticlabs/prysm/shared/testutil/assert" 11 "github.com/prysmaticlabs/prysm/shared/testutil/assertions" 12 "github.com/prysmaticlabs/prysm/shared/testutil/require" 13 "github.com/sirupsen/logrus" 14 "github.com/sirupsen/logrus/hooks/test" 15 ) 16 17 func Test_Equal(t *testing.T) { 18 type args struct { 19 tb *assertions.TBMock 20 expected interface{} 21 actual interface{} 22 msgs []interface{} 23 } 24 tests := []struct { 25 name string 26 args args 27 expectedErr string 28 }{ 29 { 30 name: "equal values", 31 args: args{ 32 tb: &assertions.TBMock{}, 33 expected: 42, 34 actual: 42, 35 }, 36 }, 37 { 38 name: "equal values different types", 39 args: args{ 40 tb: &assertions.TBMock{}, 41 expected: uint64(42), 42 actual: 42, 43 }, 44 expectedErr: "Values are not equal, want: 42 (uint64), got: 42 (int)", 45 }, 46 { 47 name: "non-equal values", 48 args: args{ 49 tb: &assertions.TBMock{}, 50 expected: 42, 51 actual: 41, 52 }, 53 expectedErr: "Values are not equal, want: 42 (int), got: 41 (int)", 54 }, 55 { 56 name: "custom error message", 57 args: args{ 58 tb: &assertions.TBMock{}, 59 expected: 42, 60 actual: 41, 61 msgs: []interface{}{"Custom values are not equal"}, 62 }, 63 expectedErr: "Custom values are not equal, want: 42 (int), got: 41 (int)", 64 }, 65 { 66 name: "custom error message with params", 67 args: args{ 68 tb: &assertions.TBMock{}, 69 expected: 42, 70 actual: 41, 71 msgs: []interface{}{"Custom values are not equal (for slot %d)", 12}, 72 }, 73 expectedErr: "Custom values are not equal (for slot 12), want: 42 (int), got: 41 (int)", 74 }, 75 } 76 for _, tt := range tests { 77 verify := func() { 78 if tt.expectedErr == "" && tt.args.tb.ErrorfMsg != "" { 79 t.Errorf("Unexpected error: %v", tt.args.tb.ErrorfMsg) 80 } else if !strings.Contains(tt.args.tb.ErrorfMsg, tt.expectedErr) { 81 t.Errorf("got: %q, want: %q", tt.args.tb.ErrorfMsg, tt.expectedErr) 82 } 83 } 84 t.Run(fmt.Sprintf("Assert/%s", tt.name), func(t *testing.T) { 85 assert.Equal(tt.args.tb, tt.args.expected, tt.args.actual, tt.args.msgs...) 86 verify() 87 }) 88 t.Run(fmt.Sprintf("Require/%s", tt.name), func(t *testing.T) { 89 require.Equal(tt.args.tb, tt.args.expected, tt.args.actual, tt.args.msgs...) 90 verify() 91 }) 92 } 93 } 94 95 func Test_NotEqual(t *testing.T) { 96 type args struct { 97 tb *assertions.TBMock 98 expected interface{} 99 actual interface{} 100 msgs []interface{} 101 } 102 tests := []struct { 103 name string 104 args args 105 expectedErr string 106 }{ 107 { 108 name: "equal values", 109 args: args{ 110 tb: &assertions.TBMock{}, 111 expected: 42, 112 actual: 42, 113 }, 114 expectedErr: "Values are equal, both values are equal: 42 (int)", 115 }, 116 { 117 name: "equal values different types", 118 args: args{ 119 tb: &assertions.TBMock{}, 120 expected: uint64(42), 121 actual: 42, 122 }, 123 }, 124 { 125 name: "non-equal values", 126 args: args{ 127 tb: &assertions.TBMock{}, 128 expected: 42, 129 actual: 41, 130 }, 131 }, 132 { 133 name: "custom error message", 134 args: args{ 135 tb: &assertions.TBMock{}, 136 expected: 42, 137 actual: 42, 138 msgs: []interface{}{"Custom values are equal"}, 139 }, 140 expectedErr: "Custom values are equal, both values are equal", 141 }, 142 } 143 for _, tt := range tests { 144 verify := func() { 145 if tt.expectedErr == "" && tt.args.tb.ErrorfMsg != "" { 146 t.Errorf("Unexpected error: %v", tt.args.tb.ErrorfMsg) 147 } else if !strings.Contains(tt.args.tb.ErrorfMsg, tt.expectedErr) { 148 t.Errorf("got: %q, want: %q", tt.args.tb.ErrorfMsg, tt.expectedErr) 149 } 150 } 151 t.Run(fmt.Sprintf("Assert/%s", tt.name), func(t *testing.T) { 152 assert.NotEqual(tt.args.tb, tt.args.expected, tt.args.actual, tt.args.msgs...) 153 verify() 154 }) 155 t.Run(fmt.Sprintf("Require/%s", tt.name), func(t *testing.T) { 156 require.NotEqual(tt.args.tb, tt.args.expected, tt.args.actual, tt.args.msgs...) 157 verify() 158 }) 159 } 160 } 161 162 func TestAssert_DeepEqual(t *testing.T) { 163 type args struct { 164 tb *assertions.TBMock 165 expected interface{} 166 actual interface{} 167 msgs []interface{} 168 } 169 tests := []struct { 170 name string 171 args args 172 expectedErr string 173 }{ 174 { 175 name: "equal values", 176 args: args{ 177 tb: &assertions.TBMock{}, 178 expected: struct{ i int }{42}, 179 actual: struct{ i int }{42}, 180 }, 181 }, 182 { 183 name: "non-equal values", 184 args: args{ 185 tb: &assertions.TBMock{}, 186 expected: struct{ i int }{42}, 187 actual: struct{ i int }{41}, 188 }, 189 expectedErr: "Values are not equal, want: struct { i int }{i:42}, got: struct { i int }{i:41}", 190 }, 191 { 192 name: "custom error message", 193 args: args{ 194 tb: &assertions.TBMock{}, 195 expected: struct{ i int }{42}, 196 actual: struct{ i int }{41}, 197 msgs: []interface{}{"Custom values are not equal"}, 198 }, 199 expectedErr: "Custom values are not equal, want: struct { i int }{i:42}, got: struct { i int }{i:41}", 200 }, 201 { 202 name: "custom error message with params", 203 args: args{ 204 tb: &assertions.TBMock{}, 205 expected: struct{ i int }{42}, 206 actual: struct{ i int }{41}, 207 msgs: []interface{}{"Custom values are not equal (for slot %d)", 12}, 208 }, 209 expectedErr: "Custom values are not equal (for slot 12), want: struct { i int }{i:42}, got: struct { i int }{i:41}", 210 }, 211 } 212 for _, tt := range tests { 213 verify := func() { 214 if tt.expectedErr == "" && tt.args.tb.ErrorfMsg != "" { 215 t.Errorf("Unexpected error: %v", tt.args.tb.ErrorfMsg) 216 } else if !strings.Contains(tt.args.tb.ErrorfMsg, tt.expectedErr) { 217 t.Errorf("got: %q, want: %q", tt.args.tb.ErrorfMsg, tt.expectedErr) 218 } 219 } 220 t.Run(fmt.Sprintf("Assert/%s", tt.name), func(t *testing.T) { 221 assert.DeepEqual(tt.args.tb, tt.args.expected, tt.args.actual, tt.args.msgs...) 222 verify() 223 }) 224 t.Run(fmt.Sprintf("Require/%s", tt.name), func(t *testing.T) { 225 require.DeepEqual(tt.args.tb, tt.args.expected, tt.args.actual, tt.args.msgs...) 226 verify() 227 }) 228 } 229 } 230 231 func TestAssert_DeepNotEqual(t *testing.T) { 232 type args struct { 233 tb *assertions.TBMock 234 expected interface{} 235 actual interface{} 236 msgs []interface{} 237 } 238 tests := []struct { 239 name string 240 args args 241 expectedErr string 242 }{ 243 { 244 name: "equal values", 245 args: args{ 246 tb: &assertions.TBMock{}, 247 expected: struct{ i int }{42}, 248 actual: struct{ i int }{42}, 249 }, 250 expectedErr: "Values are equal, want: struct { i int }{i:42}, got: struct { i int }{i:42}", 251 }, 252 { 253 name: "non-equal values", 254 args: args{ 255 tb: &assertions.TBMock{}, 256 expected: struct{ i int }{42}, 257 actual: struct{ i int }{41}, 258 }, 259 }, 260 { 261 name: "custom error message", 262 args: args{ 263 tb: &assertions.TBMock{}, 264 expected: struct{ i int }{42}, 265 actual: struct{ i int }{42}, 266 msgs: []interface{}{"Custom values are equal"}, 267 }, 268 expectedErr: "Custom values are equal, want: struct { i int }{i:42}, got: struct { i int }{i:42}", 269 }, 270 { 271 name: "custom error message with params", 272 args: args{ 273 tb: &assertions.TBMock{}, 274 expected: struct{ i int }{42}, 275 actual: struct{ i int }{42}, 276 msgs: []interface{}{"Custom values are equal (for slot %d)", 12}, 277 }, 278 expectedErr: "Custom values are equal (for slot 12), want: struct { i int }{i:42}, got: struct { i int }{i:42}", 279 }, 280 } 281 for _, tt := range tests { 282 verify := func() { 283 if tt.expectedErr == "" && tt.args.tb.ErrorfMsg != "" { 284 t.Errorf("Unexpected error: %v", tt.args.tb.ErrorfMsg) 285 } else if !strings.Contains(tt.args.tb.ErrorfMsg, tt.expectedErr) { 286 t.Errorf("got: %q, want: %q", tt.args.tb.ErrorfMsg, tt.expectedErr) 287 } 288 } 289 t.Run(fmt.Sprintf("Assert/%s", tt.name), func(t *testing.T) { 290 assert.DeepNotEqual(tt.args.tb, tt.args.expected, tt.args.actual, tt.args.msgs...) 291 verify() 292 }) 293 t.Run(fmt.Sprintf("Require/%s", tt.name), func(t *testing.T) { 294 require.DeepNotEqual(tt.args.tb, tt.args.expected, tt.args.actual, tt.args.msgs...) 295 verify() 296 }) 297 } 298 } 299 300 func TestAssert_DeepSSZEqual(t *testing.T) { 301 type args struct { 302 tb *assertions.TBMock 303 expected interface{} 304 actual interface{} 305 } 306 tests := []struct { 307 name string 308 args args 309 expectedResult bool 310 }{ 311 { 312 name: "equal values", 313 args: args{ 314 tb: &assertions.TBMock{}, 315 expected: struct{ I uint64 }{42}, 316 actual: struct{ I uint64 }{42}, 317 }, 318 expectedResult: true, 319 }, 320 { 321 name: "equal structs", 322 args: args{ 323 tb: &assertions.TBMock{}, 324 expected: ð.Checkpoint{ 325 Epoch: 5, 326 Root: []byte("hi there"), 327 }, 328 actual: ð.Checkpoint{ 329 Epoch: 5, 330 Root: []byte("hi there"), 331 }, 332 }, 333 expectedResult: true, 334 }, 335 { 336 name: "non-equal values", 337 args: args{ 338 tb: &assertions.TBMock{}, 339 expected: struct{ I uint64 }{42}, 340 actual: struct{ I uint64 }{41}, 341 }, 342 expectedResult: false, 343 }, 344 } 345 for _, tt := range tests { 346 verify := func() { 347 if tt.expectedResult && tt.args.tb.ErrorfMsg != "" { 348 t.Errorf("Unexpected error: %s %v", tt.name, tt.args.tb.ErrorfMsg) 349 } 350 } 351 t.Run(fmt.Sprintf("Assert/%s", tt.name), func(t *testing.T) { 352 assert.DeepSSZEqual(tt.args.tb, tt.args.expected, tt.args.actual) 353 verify() 354 }) 355 t.Run(fmt.Sprintf("Require/%s", tt.name), func(t *testing.T) { 356 require.DeepSSZEqual(tt.args.tb, tt.args.expected, tt.args.actual) 357 verify() 358 }) 359 } 360 } 361 362 func TestAssert_DeepNotSSZEqual(t *testing.T) { 363 type args struct { 364 tb *assertions.TBMock 365 expected interface{} 366 actual interface{} 367 } 368 tests := []struct { 369 name string 370 args args 371 expectedResult bool 372 }{ 373 { 374 name: "equal values", 375 args: args{ 376 tb: &assertions.TBMock{}, 377 expected: struct{ I uint64 }{42}, 378 actual: struct{ I uint64 }{42}, 379 }, 380 expectedResult: true, 381 }, 382 { 383 name: "non-equal values", 384 args: args{ 385 tb: &assertions.TBMock{}, 386 expected: struct{ I uint64 }{42}, 387 actual: struct{ I uint64 }{41}, 388 }, 389 expectedResult: false, 390 }, 391 { 392 name: "not equal structs", 393 args: args{ 394 tb: &assertions.TBMock{}, 395 expected: ð.Checkpoint{ 396 Epoch: 5, 397 Root: []byte("hello there"), 398 }, 399 actual: ð.Checkpoint{ 400 Epoch: 3, 401 Root: []byte("hi there"), 402 }, 403 }, 404 expectedResult: true, 405 }, 406 } 407 for _, tt := range tests { 408 verify := func() { 409 if !tt.expectedResult && tt.args.tb.ErrorfMsg != "" { 410 t.Errorf("Unexpected error: %s %v", tt.name, tt.args.tb.ErrorfMsg) 411 } 412 } 413 t.Run(fmt.Sprintf("Assert/%s", tt.name), func(t *testing.T) { 414 assert.DeepNotSSZEqual(tt.args.tb, tt.args.expected, tt.args.actual) 415 verify() 416 }) 417 t.Run(fmt.Sprintf("Require/%s", tt.name), func(t *testing.T) { 418 require.DeepNotSSZEqual(tt.args.tb, tt.args.expected, tt.args.actual) 419 verify() 420 }) 421 } 422 } 423 424 func TestAssert_NoError(t *testing.T) { 425 type args struct { 426 tb *assertions.TBMock 427 err error 428 msgs []interface{} 429 } 430 tests := []struct { 431 name string 432 args args 433 expectedErr string 434 }{ 435 { 436 name: "nil error", 437 args: args{ 438 tb: &assertions.TBMock{}, 439 }, 440 }, 441 { 442 name: "non-nil error", 443 args: args{ 444 tb: &assertions.TBMock{}, 445 err: errors.New("failed"), 446 }, 447 expectedErr: "Unexpected error: failed", 448 }, 449 { 450 name: "custom non-nil error", 451 args: args{ 452 tb: &assertions.TBMock{}, 453 err: errors.New("failed"), 454 msgs: []interface{}{"Custom error message"}, 455 }, 456 expectedErr: "Custom error message: failed", 457 }, 458 { 459 name: "custom non-nil error with params", 460 args: args{ 461 tb: &assertions.TBMock{}, 462 err: errors.New("failed"), 463 msgs: []interface{}{"Custom error message (for slot %d)", 12}, 464 }, 465 expectedErr: "Custom error message (for slot 12): failed", 466 }, 467 } 468 for _, tt := range tests { 469 verify := func() { 470 if tt.expectedErr == "" && tt.args.tb.ErrorfMsg != "" { 471 t.Errorf("Unexpected error: %v", tt.args.tb.ErrorfMsg) 472 } else if !strings.Contains(tt.args.tb.ErrorfMsg, tt.expectedErr) { 473 t.Errorf("got: %q, want: %q", tt.args.tb.ErrorfMsg, tt.expectedErr) 474 } 475 } 476 t.Run(fmt.Sprintf("Assert/%s", tt.name), func(t *testing.T) { 477 assert.NoError(tt.args.tb, tt.args.err, tt.args.msgs...) 478 verify() 479 }) 480 t.Run(fmt.Sprintf("Require/%s", tt.name), func(t *testing.T) { 481 require.NoError(tt.args.tb, tt.args.err, tt.args.msgs...) 482 verify() 483 }) 484 } 485 } 486 487 func TestAssert_ErrorContains(t *testing.T) { 488 type args struct { 489 tb *assertions.TBMock 490 want string 491 err error 492 msgs []interface{} 493 } 494 tests := []struct { 495 name string 496 args args 497 expectedErr string 498 }{ 499 { 500 name: "nil error", 501 args: args{ 502 tb: &assertions.TBMock{}, 503 want: "some error", 504 }, 505 expectedErr: "Expected error not returned, got: <nil>, want: some error", 506 }, 507 { 508 name: "unexpected error", 509 args: args{ 510 tb: &assertions.TBMock{}, 511 want: "another error", 512 err: errors.New("failed"), 513 }, 514 expectedErr: "Expected error not returned, got: failed, want: another error", 515 }, 516 { 517 name: "expected error", 518 args: args{ 519 tb: &assertions.TBMock{}, 520 want: "failed", 521 err: errors.New("failed"), 522 }, 523 expectedErr: "", 524 }, 525 { 526 name: "custom unexpected error", 527 args: args{ 528 tb: &assertions.TBMock{}, 529 want: "another error", 530 err: errors.New("failed"), 531 msgs: []interface{}{"Something wrong"}, 532 }, 533 expectedErr: "Something wrong, got: failed, want: another error", 534 }, 535 { 536 name: "expected error", 537 args: args{ 538 tb: &assertions.TBMock{}, 539 want: "failed", 540 err: errors.New("failed"), 541 msgs: []interface{}{"Something wrong"}, 542 }, 543 expectedErr: "", 544 }, 545 { 546 name: "custom unexpected error with params", 547 args: args{ 548 tb: &assertions.TBMock{}, 549 want: "another error", 550 err: errors.New("failed"), 551 msgs: []interface{}{"Something wrong (for slot %d)", 12}, 552 }, 553 expectedErr: "Something wrong (for slot 12), got: failed, want: another error", 554 }, 555 { 556 name: "expected error with params", 557 args: args{ 558 tb: &assertions.TBMock{}, 559 want: "failed", 560 err: errors.New("failed"), 561 msgs: []interface{}{"Something wrong (for slot %d)", 12}, 562 }, 563 expectedErr: "", 564 }, 565 } 566 for _, tt := range tests { 567 verify := func() { 568 if tt.expectedErr == "" && tt.args.tb.ErrorfMsg != "" { 569 t.Errorf("Unexpected error: %v", tt.args.tb.ErrorfMsg) 570 } else if !strings.Contains(tt.args.tb.ErrorfMsg, tt.expectedErr) { 571 t.Errorf("got: %q, want: %q", tt.args.tb.ErrorfMsg, tt.expectedErr) 572 } 573 } 574 t.Run(fmt.Sprintf("Assert/%s", tt.name), func(t *testing.T) { 575 assert.ErrorContains(tt.args.tb, tt.args.want, tt.args.err, tt.args.msgs...) 576 verify() 577 }) 578 t.Run(fmt.Sprintf("Require/%s", tt.name), func(t *testing.T) { 579 require.ErrorContains(tt.args.tb, tt.args.want, tt.args.err, tt.args.msgs...) 580 verify() 581 }) 582 } 583 } 584 585 func Test_NotNil(t *testing.T) { 586 type args struct { 587 tb *assertions.TBMock 588 obj interface{} 589 msgs []interface{} 590 } 591 var nilBlock *eth.SignedBeaconBlock = nil 592 tests := []struct { 593 name string 594 args args 595 expectedErr string 596 }{ 597 { 598 name: "nil", 599 args: args{ 600 tb: &assertions.TBMock{}, 601 }, 602 expectedErr: "Unexpected nil value", 603 }, 604 { 605 name: "nil custom message", 606 args: args{ 607 tb: &assertions.TBMock{}, 608 msgs: []interface{}{"This should not be nil"}, 609 }, 610 expectedErr: "This should not be nil", 611 }, 612 { 613 name: "nil custom message with params", 614 args: args{ 615 tb: &assertions.TBMock{}, 616 msgs: []interface{}{"This should not be nil (for slot %d)", 12}, 617 }, 618 expectedErr: "This should not be nil (for slot 12)", 619 }, 620 { 621 name: "not nil", 622 args: args{ 623 tb: &assertions.TBMock{}, 624 obj: "some value", 625 }, 626 expectedErr: "", 627 }, 628 { 629 name: "nil value of dynamic type", 630 args: args{ 631 tb: &assertions.TBMock{}, 632 obj: nilBlock, 633 }, 634 expectedErr: "Unexpected nil value", 635 }, 636 { 637 name: "make sure that assertion works for basic type", 638 args: args{ 639 tb: &assertions.TBMock{}, 640 obj: 15, 641 }, 642 }, 643 } 644 for _, tt := range tests { 645 verify := func() { 646 if tt.expectedErr == "" && tt.args.tb.ErrorfMsg != "" { 647 t.Errorf("Unexpected error: %v", tt.args.tb.ErrorfMsg) 648 } else if !strings.Contains(tt.args.tb.ErrorfMsg, tt.expectedErr) { 649 t.Errorf("got: %q, want: %q", tt.args.tb.ErrorfMsg, tt.expectedErr) 650 } 651 } 652 t.Run(fmt.Sprintf("Assert/%s", tt.name), func(t *testing.T) { 653 assert.NotNil(tt.args.tb, tt.args.obj, tt.args.msgs...) 654 verify() 655 }) 656 t.Run(fmt.Sprintf("Require/%s", tt.name), func(t *testing.T) { 657 require.NotNil(tt.args.tb, tt.args.obj, tt.args.msgs...) 658 verify() 659 }) 660 } 661 } 662 663 func Test_LogsContainDoNotContain(t *testing.T) { 664 type args struct { 665 tb *assertions.TBMock 666 want string 667 flag bool 668 msgs []interface{} 669 } 670 tests := []struct { 671 name string 672 args args 673 updateLogs func(log *logrus.Logger) 674 expectedErr string 675 }{ 676 { 677 name: "should contain not found", 678 args: args{ 679 tb: &assertions.TBMock{}, 680 want: "here goes some expected log string", 681 flag: true, 682 }, 683 expectedErr: "Expected log not found: here goes some expected log string", 684 }, 685 { 686 name: "should contain found", 687 args: args{ 688 tb: &assertions.TBMock{}, 689 want: "here goes some expected log string", 690 flag: true, 691 }, 692 updateLogs: func(log *logrus.Logger) { 693 log.Info("here goes some expected log string") 694 }, 695 expectedErr: "", 696 }, 697 { 698 name: "should contain not found custom message", 699 args: args{ 700 tb: &assertions.TBMock{}, 701 msgs: []interface{}{"Waited for logs"}, 702 want: "here goes some expected log string", 703 flag: true, 704 }, 705 expectedErr: "Waited for logs: here goes some expected log string", 706 }, 707 { 708 name: "should contain not found custom message with params", 709 args: args{ 710 tb: &assertions.TBMock{}, 711 msgs: []interface{}{"Waited for %d logs", 10}, 712 want: "here goes some expected log string", 713 flag: true, 714 }, 715 expectedErr: "Waited for 10 logs: here goes some expected log string", 716 }, 717 { 718 name: "should not contain and not found", 719 args: args{ 720 tb: &assertions.TBMock{}, 721 want: "here goes some unexpected log string", 722 }, 723 expectedErr: "", 724 }, 725 { 726 name: "should not contain but found", 727 args: args{ 728 tb: &assertions.TBMock{}, 729 want: "here goes some unexpected log string", 730 }, 731 updateLogs: func(log *logrus.Logger) { 732 log.Info("here goes some unexpected log string") 733 }, 734 expectedErr: "Unexpected log found: here goes some unexpected log string", 735 }, 736 { 737 name: "should not contain but found custom message", 738 args: args{ 739 tb: &assertions.TBMock{}, 740 msgs: []interface{}{"Dit not expect logs"}, 741 want: "here goes some unexpected log string", 742 }, 743 updateLogs: func(log *logrus.Logger) { 744 log.Info("here goes some unexpected log string") 745 }, 746 expectedErr: "Dit not expect logs: here goes some unexpected log string", 747 }, 748 { 749 name: "should not contain but found custom message with params", 750 args: args{ 751 tb: &assertions.TBMock{}, 752 msgs: []interface{}{"Dit not expect %d logs", 10}, 753 want: "here goes some unexpected log string", 754 }, 755 updateLogs: func(log *logrus.Logger) { 756 log.Info("here goes some unexpected log string") 757 }, 758 expectedErr: "Dit not expect 10 logs: here goes some unexpected log string", 759 }, 760 } 761 for _, tt := range tests { 762 verify := func() { 763 if tt.expectedErr == "" && tt.args.tb.ErrorfMsg != "" { 764 t.Errorf("Unexpected error: %v", tt.args.tb.ErrorfMsg) 765 } else if !strings.Contains(tt.args.tb.ErrorfMsg, tt.expectedErr) { 766 t.Errorf("got: %q, want: %q", tt.args.tb.ErrorfMsg, tt.expectedErr) 767 } 768 } 769 t.Run(fmt.Sprintf("Assert/%s", tt.name), func(t *testing.T) { 770 log, hook := test.NewNullLogger() 771 if tt.updateLogs != nil { 772 tt.updateLogs(log) 773 } 774 if tt.args.flag { 775 assert.LogsContain(tt.args.tb, hook, tt.args.want, tt.args.msgs...) 776 } else { 777 assert.LogsDoNotContain(tt.args.tb, hook, tt.args.want, tt.args.msgs...) 778 } 779 verify() 780 }) 781 t.Run(fmt.Sprintf("Require/%s", tt.name), func(t *testing.T) { 782 log, hook := test.NewNullLogger() 783 if tt.updateLogs != nil { 784 tt.updateLogs(log) 785 } 786 if tt.args.flag { 787 require.LogsContain(tt.args.tb, hook, tt.args.want, tt.args.msgs...) 788 } else { 789 require.LogsDoNotContain(tt.args.tb, hook, tt.args.want, tt.args.msgs...) 790 } 791 verify() 792 }) 793 } 794 }