-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export utils and commands to share (with sentinel client, or others) #428
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// hgetall converts its replies to an Object. If the reply is empty, null is returned. | ||
function reply_to_object(reply) { | ||
var obj = {}, j, jl, key, val; | ||
|
||
if (reply.length === 0) { | ||
return null; | ||
} | ||
|
||
for (j = 0, jl = reply.length; j < jl; j += 2) { | ||
key = reply[j].toString(); | ||
val = reply[j + 1]; | ||
obj[key] = val; | ||
} | ||
|
||
return obj; | ||
} | ||
|
||
module.exports = { | ||
reply_to_object: reply_to_object | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// test runner utils, separated from mranney's test.js. | ||
|
||
var assert = require('assert'); | ||
|
||
exports.buffers_to_strings = function buffers_to_strings(arr) { | ||
return arr.map(function (val) { | ||
return val.toString(); | ||
}); | ||
}; | ||
|
||
exports.require_number = function require_number(expected, label, callback) { | ||
return function (err, results) { | ||
assert.strictEqual(null, err, label + " expected " + expected + ", got error: " + err); | ||
assert.strictEqual(expected, results, label + " " + expected + " !== " + results); | ||
assert.strictEqual(typeof results, "number", label); | ||
if (typeof callback === 'function') callback(); | ||
return true; | ||
}; | ||
}; | ||
|
||
exports.require_number_any = function require_number_any(label, callback) { | ||
return function (err, results) { | ||
assert.strictEqual(null, err, label + " expected any number, got error: " + err); | ||
assert.strictEqual(typeof results, "number", label + " " + results + " is not a number"); | ||
if (typeof callback === 'function') callback(); | ||
return true; | ||
}; | ||
}; | ||
|
||
exports.require_number_pos = function require_number_pos(label, callback) { | ||
return function (err, results) { | ||
assert.strictEqual(null, err, label + " expected positive number, got error: " + err); | ||
assert.strictEqual(true, (results > 0), label + " " + results + " is not a positive number"); | ||
if (typeof callback === 'function') callback(); | ||
return true; | ||
}; | ||
}; | ||
|
||
exports.require_string = function require_string(str, label, callback) { | ||
return function (err, results) { | ||
assert.strictEqual(null, err, label + " expected string '" + str + "', got error: " + err); | ||
assert.strictEqual(str, results, label + " " + str + " does not match " + results); | ||
if (typeof callback === 'function') callback(); | ||
return true; | ||
}; | ||
}; | ||
|
||
exports.require_null = function require_null(label, callback) { | ||
return function (err, results) { | ||
assert.strictEqual(null, err, label + " expected null, got error: " + err); | ||
assert.strictEqual(null, results, label + ": " + results + " is not null"); | ||
if (typeof callback === 'function') callback(); | ||
return true; | ||
}; | ||
}; | ||
|
||
exports.require_error = function require_error(label, callback) { | ||
return function (err, results) { | ||
assert.notEqual(err, null, label + " err is null, but an error is expected here."); | ||
if (typeof callback === 'function') callback(); | ||
return true; | ||
}; | ||
}; | ||
|
||
exports.is_empty_array = function is_empty_array(obj) { | ||
return Array.isArray(obj) && obj.length === 0; | ||
}; | ||
|
||
exports.server_version_at_least = function server_version_at_least(connection, desired_version) { | ||
// Return true if the server version >= desired_version | ||
var version = connection.server_info.versions; | ||
for (var i = 0; i < 3; i++) { | ||
if (version[i] > desired_version[i]) return true; | ||
if (version[i] < desired_version[i]) return false; | ||
} | ||
return true; | ||
}; | ||
|
||
|
||
function MockLogger(){ | ||
var self = this; | ||
this.msgs = []; | ||
this.toConsole = false; | ||
} | ||
MockLogger.prototype.log = function() { | ||
var args = Array.prototype.slice.call(arguments); | ||
this.msgs.push(args); | ||
if (this.toConsole) console.log.apply(this, args); | ||
}; | ||
exports.MockLogger = MockLogger; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes an error, needs to be:
var testUtils = require('./test_utils'),