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

Function TestPutFileIfExistsSkipReturnsNonFileConflicts

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

Source from the content-addressed store, hash-verified

1352}
1353
1354func TestPutFileIfExistsSkipReturnsNonFileConflicts(t *testing.T) {
1355 tests := []struct {
1356 name string
1357 conflictTag string
1358 }{
1359 {"folder", files.WriteConflictErrorFolder},
1360 {"file ancestor", files.WriteConflictErrorFileAncestor},
1361 {"other", files.WriteConflictErrorOther},
1362 }
1363
1364 for _, tt := range tests {
1365 t.Run(tt.name, func(t *testing.T) {
1366 tmpFile := filepath.Join(t.TempDir(), "test.txt")
1367 if err := os.WriteFile(tmpFile, []byte("test"), 0644); err != nil {
1368 t.Fatal(err)
1369 }
1370
1371 mock := &mockFilesClient{
1372 getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) {
1373 return nil, getMetadataNotFoundError()
1374 },
1375 uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) {
1376 return nil, uploadPathConflictError(tt.conflictTag)
1377 },
1378 }
1379 stubFilesClient(t, mock)
1380
1381 stderr := captureStderr(t, func() {
1382 err := putFile(tmpFile, "/bad-conflict.txt", putOptions{
1383 chunkSize: 1 << 24,
1384 workers: 4,
1385 ifExists: putIfExistsSkip,
1386 })
1387 if err == nil {
1388 t.Fatal("expected non-file conflict error")
1389 }
1390 })
1391 if strings.Contains(stderr, "Skipping ") {
1392 t.Fatalf("stderr = %q, should not skip non-file conflicts", stderr)
1393 }
1394 })
1395 }
1396}
1397
1398func TestIsUploadDestinationFileConflict(t *testing.T) {
1399 tests := []struct {

Callers

nothing calls this directly

Calls 5

getMetadataNotFoundErrorFunction · 0.85
uploadPathConflictErrorFunction · 0.85
stubFilesClientFunction · 0.85
captureStderrFunction · 0.85
putFileFunction · 0.85

Tested by

no test coverage detected