MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestUploadSingleShot_RetryOnServerErrorResetsReader

Function TestUploadSingleShot_RetryOnServerErrorResetsReader

cmd/put_test.go:169–207  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

167}
168
169func TestUploadSingleShot_RetryOnServerErrorResetsReader(t *testing.T) {
170 stubRetrySleep(t)
171 data := []byte("small file contents")
172 reader := bytes.NewReader(data)
173 uploadArg := &files.UploadArg{CommitInfo: *files.NewCommitInfo("/test.txt")}
174
175 calls := 0
176 var bodies []string
177 mock := &mockFilesClient{
178 uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) {
179 calls++
180 body, err := io.ReadAll(content)
181 if err != nil {
182 return nil, err
183 }
184 bodies = append(bodies, string(body))
185 if calls < 3 {
186 return nil, dbxauth.ServerError{APIError: dropbox.APIError{ErrorSummary: "500"}}
187 }
188 return &files.FileMetadata{}, nil
189 },
190 }
191
192 _, err := uploadSingleShot(mock, reader, uploadArg, int64(len(data)), nil)
193 if err != nil {
194 t.Errorf("expected nil error after retry, got %v", err)
195 }
196 if calls != 3 {
197 t.Errorf("expected 3 calls, got %d", calls)
198 }
199 if len(bodies) != 3 {
200 t.Fatalf("expected 3 uploaded bodies, got %d", len(bodies))
201 }
202 for i, body := range bodies {
203 if body != string(data) {
204 t.Errorf("body %d = %q, want %q", i, body, string(data))
205 }
206 }
207}
208
209func TestUploadSingleShot_RetriesTooManyWriteOperations(t *testing.T) {
210 stubRetrySleep(t)

Callers

nothing calls this directly

Calls 2

stubRetrySleepFunction · 0.85
uploadSingleShotFunction · 0.85

Tested by

no test coverage detected