Skip to content

Commit

Permalink
add more tests for metric types
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Schauenberg committed Aug 9, 2013
1 parent fc63eec commit 53fd384
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ function is_valid_packet(fields) {
return false;
}
// filter out invalid metrics values
else if (!fields[0].match(/^([\-\+\d\.]+$)/)) {
else if (fields[1] == 'g') {
if (!fields[0].match(/^([\-\+\d\.]+$)/)) {
return false;
} else {
return true;
}
}
else if (!fields[0].match(/^([\d\.]+$)/)) {
return false;
}
// filter out malformed sample rates
Expand Down
24 changes: 24 additions & 0 deletions test/helpers_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ module.exports = {
test.done();
},

counter_deltas_positive_are_not_valid: function (test) {
var res = helpers.is_valid_packet(['+10', 'c']);
test.equals(res, false);
test.done();
},

counter_deltas_negative_are_not_valid: function (test) {
var res = helpers.is_valid_packet(['-10', 'c']);
test.equals(res, false);
test.done();
},

gauges_delta_positive_are_valid: function (test) {
var res = helpers.is_valid_packet(['+10', 'g']);
test.equals(res, true);
test.done();
},

gauges_delta_negative_are_valid: function (test) {
var res = helpers.is_valid_packet(['-10', 'g']);
test.equals(res, true);
test.done();
},

correct_packet: function (test) {
var res = helpers.is_valid_packet(['345345', 'ms', '@1.0']);
test.equals(res, true);
Expand Down

0 comments on commit 53fd384

Please sign in to comment.