(t *testing.T)
| 1275 | } |
| 1276 | |
| 1277 | func TestPutFileIfExistsOverwriteUsesOverwriteMode(t *testing.T) { |
| 1278 | tmpFile := filepath.Join(t.TempDir(), "test.txt") |
| 1279 | if err := os.WriteFile(tmpFile, []byte("test"), 0644); err != nil { |
| 1280 | t.Fatal(err) |
| 1281 | } |
| 1282 | |
| 1283 | metadataCalls := 0 |
| 1284 | var mode string |
| 1285 | var strictConflict bool |
| 1286 | mock := &mockFilesClient{ |
| 1287 | getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) { |
| 1288 | metadataCalls++ |
| 1289 | return &files.FileMetadata{}, nil |
| 1290 | }, |
| 1291 | uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) { |
| 1292 | mode = arg.Mode.Tag |
| 1293 | strictConflict = arg.StrictConflict |
| 1294 | return &files.FileMetadata{}, nil |
| 1295 | }, |
| 1296 | } |
| 1297 | stubFilesClient(t, mock) |
| 1298 | |
| 1299 | err := putFile(tmpFile, "/existing.txt", putOptions{ |
| 1300 | chunkSize: 1 << 24, |
| 1301 | workers: 4, |
| 1302 | ifExists: putIfExistsOverwrite, |
| 1303 | }) |
| 1304 | if err != nil { |
| 1305 | t.Fatalf("putFile error: %v", err) |
| 1306 | } |
| 1307 | if metadataCalls != 0 { |
| 1308 | t.Errorf("metadata calls = %d, want 0 for overwrite", metadataCalls) |
| 1309 | } |
| 1310 | if mode != files.WriteModeOverwrite { |
| 1311 | t.Errorf("write mode = %q, want %q", mode, files.WriteModeOverwrite) |
| 1312 | } |
| 1313 | if strictConflict { |
| 1314 | t.Error("strict conflict = true, want false for overwrite") |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | func TestPutFileIfExistsSkipTreatsUploadFileConflictAsSkip(t *testing.T) { |
| 1319 | tmpFile := filepath.Join(t.TempDir(), "test.txt") |
nothing calls this directly
no test coverage detected