(t *testing.T)
| 466 | } |
| 467 | |
| 468 | func TestExpect_Inheritance(t *testing.T) { |
| 469 | t.Run("reporter", func(t *testing.T) { |
| 470 | rootReporter := newMockReporter(t) |
| 471 | req2Reporter := newMockReporter(t) |
| 472 | |
| 473 | e := WithConfig(Config{ |
| 474 | BaseURL: "http://example.com", |
| 475 | Client: &mockClient{}, |
| 476 | Reporter: rootReporter, |
| 477 | }) |
| 478 | |
| 479 | req1 := e.GET("/") |
| 480 | req2 := e.GET("/") |
| 481 | |
| 482 | req2.WithReporter(req2Reporter) |
| 483 | |
| 484 | // So far OK |
| 485 | req1.chain.assert(t, success) |
| 486 | req2.chain.assert(t, success) |
| 487 | |
| 488 | resp1 := req1.Expect() |
| 489 | resp2 := req2.Expect() |
| 490 | |
| 491 | // So far OK |
| 492 | resp1.chain.assert(t, success) |
| 493 | resp2.chain.assert(t, success) |
| 494 | |
| 495 | // Failure on resp1 should be reported to rootReporter, |
| 496 | // which was inherited from config |
| 497 | resp1.JSON().Object().Value("foo").chain.assert(t, failure) |
| 498 | assert.Equal(t, 1, rootReporter.reportCalled) |
| 499 | assert.Equal(t, 0, req2Reporter.reportCalled) |
| 500 | |
| 501 | // Failure on resp2 should be reported to req2Reporter, |
| 502 | // which was inherited from req2 |
| 503 | resp2.JSON().Object().Value("foo").chain.assert(t, failure) |
| 504 | assert.Equal(t, 1, rootReporter.reportCalled) |
| 505 | assert.Equal(t, 1, req2Reporter.reportCalled) |
| 506 | }) |
| 507 | |
| 508 | t.Run("assertion handler", func(t *testing.T) { |
| 509 | rootHandler := &mockAssertionHandler{} |
| 510 | req2Handler := &mockAssertionHandler{} |
| 511 | |
| 512 | e := WithConfig(Config{ |
| 513 | BaseURL: "http://example.com", |
| 514 | Client: &mockClient{}, |
| 515 | AssertionHandler: rootHandler, |
| 516 | }) |
| 517 | |
| 518 | req1 := e.GET("/") |
| 519 | req2 := e.GET("/") |
| 520 | |
| 521 | req2.WithAssertionHandler(req2Handler) |
| 522 | |
| 523 | // So far OK |
| 524 | req1.chain.assert(t, success) |
| 525 | req2.chain.assert(t, success) |
nothing calls this directly
no test coverage detected
searching dependent graphs…