Skip to content

Commit 570ea25

Browse files
committed
Update load config + test
1 parent 8aefd55 commit 570ea25

7 files changed

+14
-7
lines changed

helper.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ const MODES = {
77
}
88
const SUPPORTED_MODES = [MODES.UNI, MODES.BI];
99

10-
function loadConfig(filename, callback) {
10+
function loadConfig(filenameOrAbsolutePath, callback) {
1111
let config = {};
12+
let configPath = '';
13+
if (fs.existsSync(filenameOrAbsolutePath)) {
14+
configPath = filenameOrAbsolutePath;
15+
} else {
16+
configPath = path.join(__dirname, filenameOrAbsolutePath);
17+
}
1218
try {
13-
config = JSON.parse(fs.readFileSync(path.join(__dirname, filename)).toString())
19+
config = JSON.parse(fs.readFileSync(configPath).toString())
1420
} catch(err) {
1521
return callback(new Error("config.json is required | " + err.toString()));
1622
}

logs/.gitkeep

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/storage.test.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const helper = require('../helper');
77

88
/**
99
* TODO:
10-
* - test option `maxDeletion`
10+
* - [ ] test deleting source files with `syncFiles`
11+
* - [ ] test `maxDeletion` options
1112
*/
1213

1314
const files = {
@@ -40,7 +41,7 @@ describe("storage", function() {
4041
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ListAllMyBucketsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>89123456:user-feiowjfOEIJW</ID><DisplayName>12345678:user-feiowjfOEIJW</DisplayName></Owner><Buckets><Bucket><Name>invoices</Name><CreationDate>2023-02-27T11:46:24.000Z</CreationDate></Bucket></Buckets></ListAllMyBucketsResult>";
4142
});
4243

43-
helper.loadConfig('config.test-swift-s3.json', function(err, config) {
44+
helper.loadConfig(path.join(__dirname, 'config.test-swift-s3.json'), function(err, config) {
4445
assert.strictEqual(err, null);
4546
_config = config;
4647
storage.connection(_config, 'source', function(err) {
@@ -229,7 +230,7 @@ describe("storage", function() {
229230
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ListAllMyBucketsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>89123456:user-feiowjfOEIJW</ID><DisplayName>12345678:user-feiowjfOEIJW</DisplayName></Owner><Buckets><Bucket><Name>invoices</Name><CreationDate>2023-02-27T11:46:24.000Z</CreationDate></Bucket></Buckets></ListAllMyBucketsResult>";
230231
});
231232

232-
helper.loadConfig('config.test-s3-s3.json', function(err, config) {
233+
helper.loadConfig(path.join(__dirname, 'config.test-s3-s3.json'), function(err, config) {
233234
assert.strictEqual(err, null);
234235
_config = config;
235236
storage.connection(_config, 'source', function(err) {
@@ -301,7 +302,7 @@ describe("storage", function() {
301302
.post('/auth/tokens')
302303
.reply(200, connectionResultSuccessV3SBG, { "X-Subject-Token": tokenAuthSwift });
303304

304-
helper.loadConfig('config.test-swift-swift.json', function(err, config) {
305+
helper.loadConfig(path.join(__dirname, 'config.test-swift-swift.json'), function(err, config) {
305306
assert.strictEqual(err, null);
306307

307308
const _config = config;
@@ -377,7 +378,7 @@ describe("storage", function() {
377378
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ListAllMyBucketsResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>89123456:user-feiowjfOEIJW</ID><DisplayName>12345678:user-feiowjfOEIJW</DisplayName></Owner><Buckets><Bucket><Name>invoices</Name><CreationDate>2023-02-27T11:46:24.000Z</CreationDate></Bucket></Buckets></ListAllMyBucketsResult>";
378379
});
379380

380-
helper.loadConfig('config.test-s3-swift.json', function(err, config) {
381+
helper.loadConfig(path.join(__dirname, 'config.test-s3-swift.json'), function(err, config) {
381382
assert.strictEqual(err, null);
382383
_config = config;
383384
storage.connection(_config, 'source', function(err) {

0 commit comments

Comments
 (0)