(t *testing.T)
| 829 | } |
| 830 | |
| 831 | func TestAPIClient_IssueEndpoints(t *testing.T) { |
| 832 | mock := testutil.NewMockAPI() |
| 833 | defer mock.Close() |
| 834 | client := newTestClient(mock.Server.URL) |
| 835 | |
| 836 | tests := []struct { |
| 837 | name string |
| 838 | do func() (*lib.APIResponse, error) |
| 839 | method string |
| 840 | path string |
| 841 | wantBody string |
| 842 | }{ |
| 843 | {"list", func() (*lib.APIResponse, error) { return client.GET("/issues", nil) }, "GET", "/issues", ""}, |
| 844 | {"get", func() (*lib.APIResponse, error) { return client.GET("/issues/issue-001", nil) }, "GET", "/issues/issue-001", ""}, |
| 845 | {"create", func() (*lib.APIResponse, error) { |
| 846 | return client.POST("/issues", []byte(`{"name":"DB issue","severity":"outage"}`), nil) |
| 847 | }, "POST", "/issues", `{"name":"DB issue","severity":"outage"}`}, |
| 848 | {"update", func() (*lib.APIResponse, error) { |
| 849 | return client.PUT("/issues/issue-001", []byte(`{"state":"investigating"}`), nil) |
| 850 | }, "PUT", "/issues/issue-001", `{"state":"investigating"}`}, |
| 851 | {"resolve", func() (*lib.APIResponse, error) { |
| 852 | return client.PUT("/issues/issue-001", []byte(`{"state":"resolved"}`), nil) |
| 853 | }, "PUT", "/issues/issue-001", `{"state":"resolved"}`}, |
| 854 | {"delete", func() (*lib.APIResponse, error) { return client.DELETE("/issues/issue-001", nil, nil) }, "DELETE", "/issues/issue-001", ""}, |
| 855 | } |
| 856 | |
| 857 | for _, tt := range tests { |
| 858 | t.Run(tt.name, func(t *testing.T) { |
| 859 | mock.Reset() |
| 860 | _, err := tt.do() |
| 861 | if err != nil { |
| 862 | t.Fatalf("unexpected error: %v", err) |
| 863 | } |
| 864 | req := mock.LastRequest() |
| 865 | if req.Method != tt.method { |
| 866 | t.Errorf("expected %s, got %s", tt.method, req.Method) |
| 867 | } |
| 868 | if req.Path != tt.path { |
| 869 | t.Errorf("expected %s, got %s", tt.path, req.Path) |
| 870 | } |
| 871 | if tt.wantBody != "" && req.Body != tt.wantBody { |
| 872 | t.Errorf("expected body %q, got %q", tt.wantBody, req.Body) |
| 873 | } |
| 874 | }) |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | func TestAPIClient_MaintenanceEndpoints(t *testing.T) { |
| 879 | mock := testutil.NewMockAPI() |
nothing calls this directly
no test coverage detected