(t *testing.T)
| 76 | } |
| 77 | |
| 78 | func Test_uploadWithDelete_retry(t *testing.T) { |
| 79 | retryInterval = 0 |
| 80 | ctx := context.Background() |
| 81 | |
| 82 | tries := 0 |
| 83 | client := funcClient(func(req *http.Request) (*http.Response, error) { |
| 84 | tries++ |
| 85 | if tries == 1 { |
| 86 | return nil, errors.New("made up exception") |
| 87 | } else if tries == 2 { |
| 88 | return &http.Response{ |
| 89 | Request: req, |
| 90 | StatusCode: 500, |
| 91 | Body: io.NopCloser(bytes.NewBufferString(`{}`)), |
| 92 | }, nil |
| 93 | } |
| 94 | return &http.Response{ |
| 95 | Request: req, |
| 96 | StatusCode: 200, |
| 97 | Body: io.NopCloser(bytes.NewBufferString(`{}`)), |
| 98 | }, nil |
| 99 | }) |
| 100 | err := uploadWithDelete(ctx, client, "http://example.com/upload", AssetForUpload{ |
| 101 | Name: "asset", |
| 102 | Label: "", |
| 103 | Size: 8, |
| 104 | Open: func() (io.ReadCloser, error) { |
| 105 | return io.NopCloser(bytes.NewBufferString(`somebody`)), nil |
| 106 | }, |
| 107 | MIMEType: "application/octet-stream", |
| 108 | }) |
| 109 | if err != nil { |
| 110 | t.Errorf("uploadWithDelete() error: %v", err) |
| 111 | } |
| 112 | if tries != 3 { |
| 113 | t.Errorf("tries = %d, expected %d", tries, 3) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | type funcClient func(*http.Request) (*http.Response, error) |
| 118 |
nothing calls this directly
no test coverage detected