Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Adding settingWithFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Rodrigues committed Oct 11, 2012
1 parent 33b754e commit dc29f22
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 32 deletions.
51 changes: 51 additions & 0 deletions lib/services/core/servicesettings.js
Expand Up @@ -50,4 +50,55 @@ exports.parseAndValidateKeys = function (connectionString, validKeys) {
}

return tokenizedSettings;
};


/**
* Creates a setting value condition that validates it is one of the
* passed valid values.
*
* @param {string} name The setting key name.
*
* @return {array}
*/
exports.setting = function (name) {
var validValues = Array.prototype.slice.call(arguments, 1, arguments.length);

var predicate = function (settingValue) {
if (validValues.length === 0) {
// No restrictions, succeed.
return true;
}

// Check to find if the $settingValue is valid or not. The index must
// start from 1 as unset deletes the value but does not update the array
// indecies.
for (var index = 1; index < validValues.length; validValues++) {
if (settingValue === validValues[index]) {
// SettingValue is found in valid values set, succeed.
return true;
}
}

// settingValue is missing in valid values set, fail.
throw new Error('The provided config value ' + settingValue + ' does not belong to the valid values subset:\n' + validValues);
}

return exports.settingWithFunc(name, predicate);
};

/**
* Creates a setting value condition using the passed predicate.
*
* @param {string} name The setting key name.
* @param {function} predicate The setting value predicate.
*
* @return {array}
*/
exports.settingWithFunc = function (name, predicate) {
var requirement = {};
requirement['SettingName'] = name;
requirement['SettingConstraint'] = predicate;

return requirement;
};
2 changes: 2 additions & 0 deletions lib/services/core/storageservicesettings.js
Expand Up @@ -33,6 +33,8 @@ var validKeys = [
ConnectionStringKeys.TABLE_ENDPOINT_NAME
];

var _useDevelopmentStorageSetting = settings(ConnectionStringKeys.USE_DEVELOPMENT_STORAGE_NAME, 'true');

/**
* Creates new storage service settings instance.
*
Expand Down
2 changes: 1 addition & 1 deletion test/services/core/serviceclient-tests.js
Expand Up @@ -19,7 +19,7 @@ var azure = testutil.libRequire('azure');
var ServiceClient = azure.ServiceClient;

suite('serviceclient-tests', function () {
test('NormalizedErrorsAreErrors', function () {
test('NormalizedErrorsAreErrors', function (done) {
var error = {
'message': 'this is an error message',
'ResultCode': 500,
Expand Down
10 changes: 10 additions & 0 deletions test/services/core/servicesettings-tests.js
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/

var should = require('should');
var assert = require('assert');

var testutil = require('../../util/util');
Expand All @@ -39,11 +40,20 @@ suite('servicesettings-tests', function () {
done();
});


test('parseAndValidateKeysInvalid', function (done) {
var connectionString = 'ValidKey1=FakeValue';
var validKeys = [ 'ValidKey1', 'ValidKey2' ];

ServiceSettings.parseAndValidateKeys(connectionString, validKeys);
done();
});

test('Setting', function (done) {
var settingWithFunc = ServiceSettings.setting('mysettingname', 'true', 'false');
settingWithFunc['SettingName'].should.not.be.null;
settingWithFunc['SettingConstraint'].should.not.be.null;

done();
});
});
32 changes: 1 addition & 31 deletions test/testlist.txt
@@ -1,31 +1 @@
cli/commands/generate-psm1-utils-test.js
serviceruntime/roleenvironment-tests.js
serviceruntime/runtimeversionmanager-tests.js
serviceruntime/runtimeversionprotocolclient-tests.js
services/blob/blobservice-tests.js
services/blob/sharedaccesssignature-tests.js
services/blob/sharedkey-tests.js
services/blob/sharedkeylite-tests.js
services/blob/filters-tests.js
services/core/connectionstringparser-tests.js
services/core/serviceclient-tests.js
services/core/exponentialretrypolicyfilter-tests.js
services/core/linearretrypolicyfilter-tests.js
services/queue/queueservice-tests.js
services/table/batchserviceclient-tests.js
services/table/sharedkeytable-tests.js
services/table/sharedkeylitetable-tests.js
services/serviceBus/servicebusservice-tests.js
services/serviceBus/wrapservice-tests.js
services/serviceBus/wraptokenmanager-tests.js
services/table/tablequery-tests.js
services/table/tableservice-batch-tests.js
services/table/tableservice-tablequery-tests.js
services/table/tableservice-tests.js
util/atomhandler-tests.js
util/iso8061date-tests.js
util/util-tests.js
util/certificates/der.decoder-tests.js
util/certificates/der.decoder.pfx.root-tests.js
util/certificates/pkcs.filedecoder-tests.js
azure-tests.js
services/core/servicesettings-tests.js

0 comments on commit dc29f22

Please sign in to comment.