github.com/hawser/git-hawser@v2.5.2+incompatible/errors/types_test.go (about)

     1  package errors_test
     2  
     3  import (
     4  	"net/url"
     5  	"testing"
     6  
     7  	"github.com/git-lfs/git-lfs/errors"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  type TemporaryError struct {
    12  }
    13  
    14  func (e TemporaryError) Error() string {
    15  	return ""
    16  }
    17  
    18  func (e TemporaryError) Temporary() bool {
    19  	return true
    20  }
    21  
    22  type TimeoutError struct {
    23  }
    24  
    25  func (e TimeoutError) Error() string {
    26  	return ""
    27  }
    28  
    29  func (e TimeoutError) Timeout() bool {
    30  	return true
    31  }
    32  
    33  func TestCanRetryOnTemporaryError(t *testing.T) {
    34  	err := &url.Error{Err: TemporaryError{}}
    35  	assert.True(t, errors.IsRetriableError(err))
    36  }
    37  
    38  func TestCanRetryOnTimeoutError(t *testing.T) {
    39  	err := &url.Error{Err: TimeoutError{}}
    40  	assert.True(t, errors.IsRetriableError(err))
    41  }
    42  
    43  func TestCannotRetryOnGenericUrlError(t *testing.T) {
    44  	err := &url.Error{Err: errors.New("")}
    45  	assert.False(t, errors.IsRetriableError(err))
    46  }