|
1 | 1 | /* Copyright (C) 2020 NooBaa */
|
2 | 2 | /*eslint max-lines-per-function: ["error", 900]*/
|
3 |
| -/*eslint max-lines: ["error", 2100]*/ |
| 3 | +/*eslint max-lines: ["error", 2200]*/ |
4 | 4 | 'use strict';
|
5 | 5 |
|
6 | 6 | const _ = require('lodash');
|
@@ -426,6 +426,7 @@ mocha.describe('namespace_fs', function() {
|
426 | 426 |
|
427 | 427 | const dir_1 = '/a/b/c/';
|
428 | 428 | const dir_2 = '/a/b/';
|
| 429 | + const dir_3 = '/x/y/z/'; |
429 | 430 | const upload_key_1 = dir_1 + 'upload_key_1';
|
430 | 431 | const upload_key_2 = dir_1 + 'upload_key_2';
|
431 | 432 | const upload_key_3 = dir_2 + 'upload_key_3';
|
@@ -460,35 +461,82 @@ mocha.describe('namespace_fs', function() {
|
460 | 461 | const source = buffer_utils.buffer_to_read_stream(data);
|
461 | 462 | await upload_object(ns_tmp, upload_bkt, upload_key_3, dummy_object_sdk, source);
|
462 | 463 | await delete_object(ns_tmp, upload_bkt, upload_key_1, dummy_object_sdk);
|
463 |
| - |
464 | 464 | let entries;
|
465 | 465 | try {
|
466 | 466 | entries = await nb_native().fs.readdir(DEFAULT_FS_CONFIG, ns_tmp_bucket_path + dir_2);
|
467 | 467 | } catch (e) {
|
468 | 468 | assert.ifError(e);
|
469 | 469 | }
|
470 |
| - console.log('stop when not empty - entries', entries); |
471 | 470 | assert.strictEqual(entries.length, 1);
|
472 | 471 |
|
473 | 472 | });
|
474 | 473 |
|
| 474 | + mocha.it('delete partial dir object without last slash version enabled - /x/y/z', async function() { |
| 475 | + const source = buffer_utils.buffer_to_read_stream(data); |
| 476 | + ns_tmp.set_bucket_versioning('ENABLED', dummy_object_sdk); |
| 477 | + await upload_object(ns_tmp, upload_bkt, dir_3, dummy_object_sdk, source); |
| 478 | + await fs_utils.file_must_exist(path.join(ns_tmp_bucket_path, '/x/y/z/', config.NSFS_FOLDER_OBJECT_NAME)); |
| 479 | + const partial_dir_3 = dir_3.slice(0, -1); // the path without the last slash |
| 480 | + await delete_object(ns_tmp, upload_bkt, partial_dir_3, dummy_object_sdk); |
| 481 | + await fs_utils.file_must_exist(path.join(ns_tmp_bucket_path, '/x/y/z/', config.NSFS_FOLDER_OBJECT_NAME)); |
| 482 | + await delete_object(ns_tmp, upload_bkt, dir_3, dummy_object_sdk); |
| 483 | + }); |
| 484 | + |
| 485 | + mocha.it('delete dir object, version enabled - /x/y/z/', async function() { |
| 486 | + const source = buffer_utils.buffer_to_read_stream(data); |
| 487 | + ns_tmp.set_bucket_versioning('ENABLED', dummy_object_sdk); |
| 488 | + await upload_object(ns_tmp, upload_bkt, dir_3, dummy_object_sdk, source); |
| 489 | + await fs_utils.file_must_exist(path.join(ns_tmp_bucket_path, '/x/y/z/', config.NSFS_FOLDER_OBJECT_NAME)); |
| 490 | + const resp = await delete_object(ns_tmp, upload_bkt, dir_3, dummy_object_sdk); |
| 491 | + await fs_utils.file_must_not_exist(path.join(ns_tmp_bucket_path, '/x/y/z/', config.NSFS_FOLDER_OBJECT_NAME)); |
| 492 | + await fs_utils.file_must_not_exist(path.join(ns_tmp_bucket_path, '/x/y/z/')); |
| 493 | + // object versioning is not enabled for dir, because of this no delete_marker. |
| 494 | + assert.deepEqual(resp, {}); |
| 495 | + const res = await ns_tmp.list_object_versions({ |
| 496 | + bucket: upload_bkt, |
| 497 | + prefix: '/x/y/' |
| 498 | + }, dummy_object_sdk); |
| 499 | + assert.equal(res.objects.length, 0); |
| 500 | + }); |
| 501 | + |
| 502 | + mocha.it('delete dir object, version enabled - /x/y/z/ - multiple files', async function() { |
| 503 | + const source = buffer_utils.buffer_to_read_stream(data); |
| 504 | + const source1 = buffer_utils.buffer_to_read_stream(data); |
| 505 | + ns_tmp.set_bucket_versioning('ENABLED', dummy_object_sdk); |
| 506 | + const dir_3_object = path.join(dir_3, 'obj1'); |
| 507 | + await upload_object(ns_tmp, upload_bkt, dir_3, dummy_object_sdk, source); |
| 508 | + await upload_object(ns_tmp, upload_bkt, dir_3_object, dummy_object_sdk, source1); |
| 509 | + await fs_utils.file_must_exist(path.join(ns_tmp_bucket_path, dir_3, config.NSFS_FOLDER_OBJECT_NAME)); |
| 510 | + await fs_utils.file_must_exist(path.join(ns_tmp_bucket_path, dir_3_object)); |
| 511 | + const resp = await delete_object(ns_tmp, upload_bkt, dir_3, dummy_object_sdk); |
| 512 | + await fs_utils.file_must_not_exist(path.join(ns_tmp_bucket_path, dir_3, config.NSFS_FOLDER_OBJECT_NAME)); |
| 513 | + await fs_utils.file_must_exist(path.join(ns_tmp_bucket_path, dir_3)); |
| 514 | + await fs_utils.file_must_exist(path.join(ns_tmp_bucket_path, dir_3_object)); |
| 515 | + // object versioning is not enabled for dir, because of this no delete_marker. |
| 516 | + assert.deepEqual(resp, {}); |
| 517 | + const res = await ns_tmp.list_object_versions({ |
| 518 | + bucket: upload_bkt, |
| 519 | + prefix: '/x/y/' |
| 520 | + }, dummy_object_sdk); |
| 521 | + assert.equal(res.objects.length, 1); |
| 522 | + }); |
| 523 | + |
475 | 524 | mocha.after(async function() {
|
476 | 525 | let entries_before;
|
477 | 526 | let entries_after;
|
478 | 527 | try {
|
479 | 528 | entries_before = await nb_native().fs.readdir(DEFAULT_FS_CONFIG, ns_tmp_bucket_path);
|
480 |
| - |
481 | 529 | const delete_res = await ns_tmp.delete_object({
|
482 | 530 | bucket: upload_bkt,
|
483 | 531 | key: upload_key_3,
|
484 | 532 | }, dummy_object_sdk);
|
485 | 533 | console.log('delete_object response', inspect(delete_res));
|
486 |
| - |
487 | 534 | entries_after = await nb_native().fs.readdir(DEFAULT_FS_CONFIG, ns_tmp_bucket_path);
|
488 | 535 | } catch (e) {
|
489 | 536 | assert.ifError(e);
|
490 | 537 | }
|
491 |
| - assert.strictEqual(entries_after.length, entries_before.length - 1); |
| 538 | + ns_tmp.set_bucket_versioning('DISABLED', dummy_object_sdk); |
| 539 | + assert.strictEqual(entries_after.length, entries_before.length); |
492 | 540 | });
|
493 | 541 | });
|
494 | 542 |
|
|
0 commit comments