Permalink
Browse files

Adding settingWithFunc

  • Loading branch information...
1 parent 33b754e commit dc29f22fa58b0293f9d05c44b8bf2cb300082786 Andre Rodrigues committed Oct 11, 2012
@@ -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;
};
@@ -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.
*
@@ -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,
@@ -13,6 +13,7 @@
* limitations under the License.
*/
+var should = require('should');
var assert = require('assert');
var testutil = require('../../util/util');
@@ -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();
+ });
});
View
@@ -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.