(t *testing.T)
| 78 | } |
| 79 | |
| 80 | func Test_uploadWithDelete_retry(t *testing.T) { |
| 81 | retryInterval = 0 |
| 82 | ctx := context.Background() |
| 83 | |
| 84 | tries := 0 |
| 85 | client := &http.Client{Transport: funcTripper(func(req *http.Request) (*http.Response, error) { |
| 86 | tries++ |
| 87 | if tries == 1 { |
| 88 | return nil, errors.New("made up exception") |
| 89 | } else if tries == 2 { |
| 90 | return &http.Response{ |
| 91 | Request: req, |
| 92 | StatusCode: 500, |
| 93 | Body: io.NopCloser(bytes.NewBufferString(`{}`)), |
| 94 | }, nil |
| 95 | } |
| 96 | return &http.Response{ |
| 97 | Request: req, |
| 98 | StatusCode: 200, |
| 99 | Body: io.NopCloser(bytes.NewBufferString(`{}`)), |
| 100 | }, nil |
| 101 | })} |
| 102 | err := uploadWithDelete(ctx, client, "github.com", safeurl.NewImmutableSafeURL("http://example.com/upload"), AssetForUpload{ |
| 103 | Name: "asset", |
| 104 | Label: "", |
| 105 | Size: 8, |
| 106 | Open: func() (io.ReadCloser, error) { |
| 107 | return io.NopCloser(bytes.NewBufferString(`somebody`)), nil |
| 108 | }, |
| 109 | MIMEType: "application/octet-stream", |
| 110 | }) |
| 111 | if err != nil { |
| 112 | t.Errorf("uploadWithDelete() error: %v", err) |
| 113 | } |
| 114 | if tries != 3 { |
| 115 | t.Errorf("tries = %d, expected %d", tries, 3) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // funcTripper drives uploadWithDelete from a plain function. It is a RoundTripper rather than |
| 120 | // a Do-er because the upload path takes a concrete *http.Client, which is what api.Client needs. |
nothing calls this directly
no test coverage detected