(t *testing.T)
| 789 | } |
| 790 | |
| 791 | func TestAPIClient_NotificationEndpoints(t *testing.T) { |
| 792 | mock := testutil.NewMockAPI() |
| 793 | defer mock.Close() |
| 794 | client := newTestClient(mock.Server.URL) |
| 795 | |
| 796 | tests := []struct { |
| 797 | name string |
| 798 | do func() (*lib.APIResponse, error) |
| 799 | method string |
| 800 | path string |
| 801 | }{ |
| 802 | {"list", func() (*lib.APIResponse, error) { return client.GET("/notifications", nil) }, "GET", "/notifications"}, |
| 803 | {"get", func() (*lib.APIResponse, error) { return client.GET("/notifications/default", nil) }, "GET", "/notifications/default"}, |
| 804 | {"create", func() (*lib.APIResponse, error) { |
| 805 | return client.POST("/notifications", []byte(`{"name":"DevOps"}`), nil) |
| 806 | }, "POST", "/notifications"}, |
| 807 | {"update", func() (*lib.APIResponse, error) { |
| 808 | return client.PUT("/notifications/devops", []byte(`{"name":"Updated"}`), nil) |
| 809 | }, "PUT", "/notifications/devops"}, |
| 810 | {"delete", func() (*lib.APIResponse, error) { return client.DELETE("/notifications/old", nil, nil) }, "DELETE", "/notifications/old"}, |
| 811 | } |
| 812 | |
| 813 | for _, tt := range tests { |
| 814 | t.Run(tt.name, func(t *testing.T) { |
| 815 | mock.Reset() |
| 816 | _, err := tt.do() |
| 817 | if err != nil { |
| 818 | t.Fatalf("unexpected error: %v", err) |
| 819 | } |
| 820 | req := mock.LastRequest() |
| 821 | if req.Method != tt.method { |
| 822 | t.Errorf("expected %s, got %s", tt.method, req.Method) |
| 823 | } |
| 824 | if req.Path != tt.path { |
| 825 | t.Errorf("expected %s, got %s", tt.path, req.Path) |
| 826 | } |
| 827 | }) |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | func TestAPIClient_IssueEndpoints(t *testing.T) { |
| 832 | mock := testutil.NewMockAPI() |
nothing calls this directly
no test coverage detected