Skip to content

Commit

Permalink
NC | config dir restructure tests
Browse files Browse the repository at this point in the history
Signed-off-by: Romy <[email protected]>
  • Loading branch information
romayalon committed Jan 7, 2025
1 parent 37154c6 commit 513d2bd
Show file tree
Hide file tree
Showing 5 changed files with 672 additions and 24 deletions.
59 changes: 45 additions & 14 deletions src/test/system_tests/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,15 @@ function get_new_buckets_path_by_test_env(new_buckets_full_path, new_buckets_dir
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
* @param {Object} config_data
* @param {String} [invalid_str]
* @param {{symlink_name?: Boolean, symlink_access_key?: Boolean}} [options]
* @returns {Promise<Void>}
*/
async function write_manual_config_file(type, config_fs, config_data, invalid_str = '') {
async function write_manual_config_file(type, config_fs, config_data, invalid_str = '', { symlink_name, symlink_access_key} = {symlink_name: true, symlink_access_key: true}) {
const config_path = type === CONFIG_TYPES.BUCKET ?
config_fs.get_bucket_path_by_name(config_data.name) :
config_fs.get_identity_path_by_id(config_data._id);
if (type === CONFIG_TYPES.ACCOUNT) {
const dir_path = config_fs.get_identity_dir_path_by_id(config_data._id);
await nb_native().fs.mkdir(config_fs.fs_context, dir_path, native_fs_utils.get_umasked_mode(config.BASE_MODE_DIR));
await create_identity_dir_if_missing(config_fs, config_data);
}
await nb_native().fs.writeFile(
config_fs.fs_context,
Expand All @@ -500,22 +500,42 @@ async function write_manual_config_file(type, config_fs, config_data, invalid_st
mode: native_fs_utils.get_umasked_mode(config.BASE_MODE_FILE)
}
);
const id_relative_path = config_fs.get_account_relative_path_by_id(config_data._id);

if (type === CONFIG_TYPES.ACCOUNT) {
const id_relative_path = config_fs.get_account_relative_path_by_id(config_data._id);
if (type === CONFIG_TYPES.ACCOUNT && symlink_name) {
const name_symlink_path = config_fs.get_account_or_user_path_by_name(config_data.name);
await nb_native().fs.symlink(config_fs.fs_context, id_relative_path, name_symlink_path);
}

if (type === CONFIG_TYPES.ACCOUNT && symlink_access_key && config_data.access_keys) {
const access_key_symlink_path = config_fs.get_account_or_user_path_by_access_key(config_data.access_keys[0].access_key);
await nb_native().fs.symlink(config_fs.fs_context, id_relative_path, access_key_symlink_path);
}
}

/**
* create_identity_dir_if_missing created the identity directory if missing
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
* @param {Object} config_data
* @returns {Promise<Void>}
*/
async function create_identity_dir_if_missing(config_fs, config_data) {
const dir_path = config_fs.get_identity_dir_path_by_id(config_data._id);
try {
await nb_native().fs.mkdir(config_fs.fs_context, dir_path, native_fs_utils.get_umasked_mode(config.BASE_MODE_DIR));
} catch (err) {
if (err.code !== 'ENOENT') throw err;
}
}

/**
* write_manual_old_account_config_file writes account config file directly to the old file system account path without using config FS
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
* @param {Object} config_data
* @param {{symlink_access_key?: Boolean}} [options]
* @returns {Promise<Void>}
*/
async function write_manual_old_account_config_file(config_fs, config_data) {
async function write_manual_old_account_config_file(config_fs, config_data, { symlink_access_key } = { symlink_access_key: false }) {
const config_path = config_fs._get_old_account_path_by_name(config_data.name);
await nb_native().fs.writeFile(
config_fs.fs_context,
Expand All @@ -525,6 +545,12 @@ async function write_manual_old_account_config_file(config_fs, config_data) {
mode: native_fs_utils.get_umasked_mode(config.BASE_MODE_FILE)
}
);

const account_name_relative_path = config_fs.get_old_account_relative_path_by_name(config_data.name);
if (symlink_access_key) {
const access_key_symlink_path = config_fs.get_account_or_user_path_by_access_key(config_data.access_keys[0].access_key);
await nb_native().fs.symlink(config_fs.fs_context, account_name_relative_path, access_key_symlink_path);
}
}

/**
Expand Down Expand Up @@ -556,9 +582,9 @@ async function delete_manual_config_file(type, config_fs, config_data) {

/**
* @param {any} test_name
* @param {Object} [config_fs]
* @param {import('../../sdk/config_fs').ConfigFS} [config_fs]
*/
async function fail_test_if_default_config_dir_exists(test_name, config_fs = {}) {
async function fail_test_if_default_config_dir_exists(test_name, config_fs) {
const fs_context = config_fs?.fs_context || native_fs_utils.get_process_fs_context();
const config_dir_exists = await native_fs_utils.is_path_exists(fs_context, config.NSFS_NC_DEFAULT_CONF_DIR);
const msg = `${test_name} found an existing default config directory ${config.NSFS_NC_DEFAULT_CONF_DIR},` +
Expand All @@ -583,6 +609,8 @@ async function create_config_dir(config_dir) {

/**
* clean_config_dir cleans the config directory
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
* @param {String} [custom_config_dir_path]
* @returns {Promise<Void>}
*/
async function clean_config_dir(config_fs, custom_config_dir_path) {
Expand All @@ -593,15 +621,17 @@ async function clean_config_dir(config_fs, custom_config_dir_path) {
const system_json = '/system.json';
for (const dir of [buckets_dir_name, identities_dir_name, access_keys_dir_name, accounts_by_name, config.NSFS_TEMP_CONF_DIR_NAME]) {
const default_path = path.join(config.NSFS_NC_DEFAULT_CONF_DIR, dir);
await fs_utils.folder_delete(default_path);
const custom_path = path.join(custom_config_dir_path, dir);
await fs_utils.folder_delete(custom_path);

await fs_utils.folder_delete_skip_enoent(default_path);
if (custom_config_dir_path) {
const custom_path = path.join(custom_config_dir_path, dir);
await fs_utils.folder_delete_skip_enoent(custom_path);
}
}

await delete_redirect_file(config_fs);
await fs_utils.file_delete(system_json);
await fs_utils.folder_delete(config.NSFS_NC_DEFAULT_CONF_DIR);
await fs_utils.folder_delete(custom_config_dir_path);
await fs_utils.folder_delete_skip_enoent(config.NSFS_NC_DEFAULT_CONF_DIR);
await fs_utils.folder_delete_skip_enoent(custom_config_dir_path);
}


Expand Down Expand Up @@ -629,6 +659,7 @@ exports.get_new_buckets_path_by_test_env = get_new_buckets_path_by_test_env;
exports.write_manual_config_file = write_manual_config_file;
exports.write_manual_old_account_config_file = write_manual_old_account_config_file;
exports.delete_manual_config_file = delete_manual_config_file;
exports.create_identity_dir_if_missing = create_identity_dir_if_missing;
exports.create_redirect_file = create_redirect_file;
exports.delete_redirect_file = delete_redirect_file;
exports.fail_test_if_default_config_dir_exists = fail_test_if_default_config_dir_exists;
Expand Down
Loading

0 comments on commit 513d2bd

Please sign in to comment.