Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions pkg/gofr/service/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ func (*mockHTTP) DeleteWithHeaders(_ context.Context, _ string, _ []byte, _ map[
return &http.Response{StatusCode: http.StatusNoContent, Body: http.NoBody}, nil
}

func TestRetryProvider_Get(t *testing.T) {
// Helper to create a retry HTTP instance.
func newRetryHTTP() HTTP {
mockHTTP := &mockHTTP{}
retryConfig := &RetryConfig{MaxRetries: 3}
retryHTTP := retryConfig.AddOption(mockHTTP)

return retryConfig.AddOption(mockHTTP)
}

func TestRetryProvider_Get(t *testing.T) {
retryHTTP := newRetryHTTP()

// Make the GET request
resp, err := retryHTTP.Get(t.Context(), "/test", nil)
Expand All @@ -86,9 +92,7 @@ func TestRetryProvider_Get(t *testing.T) {
}

func TestRetryProvider_GetWithHeaders(t *testing.T) {
mockHTTP := &mockHTTP{}
retryConfig := &RetryConfig{MaxRetries: 3}
retryHTTP := retryConfig.AddOption(mockHTTP)
retryHTTP := newRetryHTTP()

// Make the GET request with headers
resp, err := retryHTTP.GetWithHeaders(t.Context(), "/test", nil,
Expand All @@ -101,9 +105,7 @@ func TestRetryProvider_GetWithHeaders(t *testing.T) {
}

func TestRetryProvider_Post(t *testing.T) {
mockHTTP := &mockHTTP{}
retryConfig := &RetryConfig{MaxRetries: 3}
retryHTTP := retryConfig.AddOption(mockHTTP)
retryHTTP := newRetryHTTP()

// Make the POST request
resp, err := retryHTTP.Post(t.Context(), "/test", nil, []byte("body"))
Expand All @@ -115,9 +117,7 @@ func TestRetryProvider_Post(t *testing.T) {
}

func TestRetryProvider_PostWithHeaders(t *testing.T) {
mockHTTP := &mockHTTP{}
retryConfig := &RetryConfig{MaxRetries: 3}
retryHTTP := retryConfig.AddOption(mockHTTP)
retryHTTP := newRetryHTTP()

// Make the POST request with headers
resp, err := retryHTTP.PostWithHeaders(t.Context(), "/test", nil, []byte("body"),
Expand All @@ -130,9 +130,7 @@ func TestRetryProvider_PostWithHeaders(t *testing.T) {
}

func TestRetryProvider_Put(t *testing.T) {
mockHTTP := &mockHTTP{}
retryConfig := &RetryConfig{MaxRetries: 3}
retryHTTP := retryConfig.AddOption(mockHTTP)
retryHTTP := newRetryHTTP()

// Make the PUT request
resp, err := retryHTTP.Put(t.Context(), "/test", nil, []byte("body"))
Expand All @@ -144,9 +142,7 @@ func TestRetryProvider_Put(t *testing.T) {
}

func TestRetryProvider_PutWithHeaders(t *testing.T) {
mockHTTP := &mockHTTP{}
retryConfig := &RetryConfig{MaxRetries: 3}
retryHTTP := retryConfig.AddOption(mockHTTP)
retryHTTP := newRetryHTTP()

// Make the PUT request with headers
resp, err := retryHTTP.PutWithHeaders(t.Context(), "/test", nil, []byte("body"),
Expand Down Expand Up @@ -182,9 +178,7 @@ func TestRetryProvider_Patch_WithError(t *testing.T) {
}

func TestRetryProvider_PatchWithHeaders(t *testing.T) {
mockHTTP := &mockHTTP{}
retryConfig := &RetryConfig{MaxRetries: 3}
retryHTTP := retryConfig.AddOption(mockHTTP)
retryHTTP := newRetryHTTP()

// Make the PATCH request with headers
resp, err := retryHTTP.PatchWithHeaders(t.Context(), "/test", nil, []byte("body"),
Expand All @@ -197,9 +191,7 @@ func TestRetryProvider_PatchWithHeaders(t *testing.T) {
}

func TestRetryProvider_Delete(t *testing.T) {
mockHTTP := &mockHTTP{}
retryConfig := &RetryConfig{MaxRetries: 3}
retryHTTP := retryConfig.AddOption(mockHTTP)
retryHTTP := newRetryHTTP()

// Make the DELETE request
resp, err := retryHTTP.Delete(t.Context(), "/test", nil)
Expand All @@ -210,9 +202,7 @@ func TestRetryProvider_Delete(t *testing.T) {
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
}
func TestRetryProvider_DeleteWithHeaders(t *testing.T) {
mockHTTP := &mockHTTP{}
retryConfig := &RetryConfig{MaxRetries: 3}
retryHTTP := retryConfig.AddOption(mockHTTP)
retryHTTP := newRetryHTTP()

// Make the DELETE request with headers
resp, err := retryHTTP.DeleteWithHeaders(t.Context(), "/test", []byte("body"),
Expand Down
Loading