This commit is contained in:
Andre Rodrigues 2012-10-11 17:48:28 +01:00
Родитель 03136272d1
Коммит a71c9cf261
4 изменённых файлов: 60 добавлений и 2 удалений

Просмотреть файл

@ -124,7 +124,30 @@ StorageServiceSettings.developmentStorageAccount = function () {
} }
return _devStoreAccount; return _devStoreAccount;
} };
/**
* Gets the default service endpoint using the specified protocol and account
* name.
*
* @param {array} settings The service settings.
* @param {string} dns The service DNS.
*
* @return {string}
*/
StorageServiceSettings._getDefaultServiceEndpoint = function (settings, dns) {
var scheme = util.tryGetValueInsensitive(
ConnectionStringKeys.DEFAULT_ENDPOINTS_PROTOCOL_NAME,
settings
);
var accountName = util.tryGetValueInsensitive(
ConnectionStringKeys.ACCOUNT_NAME_NAME,
settings
);
return url.format({ protocol: scheme, host: accountName + '.' + dns });
};
/** /**
* Creates StorageServiceSettings object given endpoints uri. * Creates StorageServiceSettings object given endpoints uri.

Просмотреть файл

@ -232,6 +232,30 @@ exports.inArrayInsensitive = function (needle, haystack) {
return _.contains(_.map(haystack, function (h) { return h.toLowerCase() }), needle.toLowerCase()); return _.contains(_.map(haystack, function (h) { return h.toLowerCase() }), needle.toLowerCase());
}; };
/**
* Returns the specified value of the key passed from object and in case that
* this key doesn't exist, the default value is returned. The key matching is
* done in a case insensitive manner.
*
* @param {string} key The array key.
* @param {object} haystack The object to be used.
* @param {mix} default The value to return if $key is not found in $array.
*
* @static
*
* @return mix
*/
exports.tryGetValueInsensitive = function (key, haystack, defaultValue)
{
for (var i in haystack) {
if (i.toString().toLowerCase() === key.toString().toLowerCase()) {
return haystack[i];
}
}
return defaultValue;
};
exports.pathExistsSync = fs.existsSync exports.pathExistsSync = fs.existsSync
? fs.existsSync ? fs.existsSync
: path.existsSync; : path.existsSync;

Просмотреть файл

@ -1,3 +1,4 @@
services/core/servicesettings-tests.js services/core/servicesettings-tests.js
services/core/storageservicesettings-tests.js services/core/storageservicesettings-tests.js
util/validate-tests.js util/validate-tests.js
util/util-tests.js

Просмотреть файл

@ -175,4 +175,14 @@ suite('util-tests', function() {
done(); done();
}); });
test('Get value case insensitive', function (done) {
// int positives
assert.equal(util.tryGetValueInsensitive('B', { 'a': 'a1', 'b': 'b1', 'c': 'c1' }), 'b1');
assert.equal(util.tryGetValueInsensitive('b', { 'a': 'a1', 'b': 'b1', 'c': 'c1' }), 'b1');
assert.equal(util.tryGetValueInsensitive('D', { 'a': 'a1', 'b': 'b1', 'c': 'c1' }), undefined);
assert.equal(util.tryGetValueInsensitive('D', { 'a': 'a1', 'b': 'b1', 'c': 'c1' }, 'something'), 'something');
done();
});
}); });