--- Integration-style tests: full request/response cycle per resource endpoint ---
(t *testing.T)
| 599 | // --- Integration-style tests: full request/response cycle per resource endpoint --- |
| 600 | |
| 601 | func TestAPIClient_MonitorEndpoints(t *testing.T) { |
| 602 | mock := testutil.NewMockAPI() |
| 603 | defer mock.Close() |
| 604 | |
| 605 | client := newTestClient(mock.Server.URL) |
| 606 | |
| 607 | tests := []struct { |
| 608 | name string |
| 609 | do func() (*lib.APIResponse, error) |
| 610 | method string |
| 611 | path string |
| 612 | wantBody string |
| 613 | }{ |
| 614 | { |
| 615 | name: "list monitors", |
| 616 | do: func() (*lib.APIResponse, error) { return client.GET("/monitors", nil) }, |
| 617 | method: "GET", |
| 618 | path: "/monitors", |
| 619 | }, |
| 620 | { |
| 621 | name: "get monitor", |
| 622 | do: func() (*lib.APIResponse, error) { return client.GET("/monitors/abc123", nil) }, |
| 623 | method: "GET", |
| 624 | path: "/monitors/abc123", |
| 625 | }, |
| 626 | { |
| 627 | name: "create monitor", |
| 628 | do: func() (*lib.APIResponse, error) { |
| 629 | return client.POST("/monitors", []byte(`{"key":"new","type":"job"}`), nil) |
| 630 | }, |
| 631 | method: "POST", |
| 632 | path: "/monitors", |
| 633 | wantBody: `{"key":"new","type":"job"}`, |
| 634 | }, |
| 635 | { |
| 636 | name: "update monitor (PUT batch)", |
| 637 | do: func() (*lib.APIResponse, error) { |
| 638 | return client.PUT("/monitors", []byte(`[{"key":"abc","name":"Updated"}]`), nil) |
| 639 | }, |
| 640 | method: "PUT", |
| 641 | path: "/monitors", |
| 642 | wantBody: `[{"key":"abc","name":"Updated"}]`, |
| 643 | }, |
| 644 | { |
| 645 | name: "delete monitor", |
| 646 | do: func() (*lib.APIResponse, error) { return client.DELETE("/monitors/abc123", nil, nil) }, |
| 647 | method: "DELETE", |
| 648 | path: "/monitors/abc123", |
| 649 | }, |
| 650 | { |
| 651 | name: "clone monitor", |
| 652 | do: func() (*lib.APIResponse, error) { |
| 653 | return client.POST("/monitors/clone", []byte(`{"key":"abc123"}`), nil) |
| 654 | }, |
| 655 | method: "POST", |
| 656 | path: "/monitors/clone", |
| 657 | wantBody: `{"key":"abc123"}`, |
| 658 | }, |
nothing calls this directly
no test coverage detected