Skip to content

Commit

Permalink
Add tests for buffer fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanseys committed Nov 16, 2014
1 parent 2d76a12 commit c218eb8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/datastore/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,17 @@ module.exports.isKeyComplete = function(key) {
*
* @example
* propertyToValue({
* booleanValue: false
* boolean_value: false
* });
* // false
*
* propertyToValue({
* stringValue: 'Hi'
* string_value: 'Hi'
* });
* // 'Hi'
*
* propertyToValue({
* blobValue: 'aGVsbG8='
* blob_value: new Buffer('68656c6c6f')
* });
* // <Buffer 68 65 6c 6c 6f>
*/
Expand Down Expand Up @@ -384,6 +384,8 @@ function propertyToValue(property) {
}
}

module.exports.propertyToValue = propertyToValue;

/**
* Convert any native value to a property object.
*
Expand Down
22 changes: 22 additions & 0 deletions regression/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ describe('datastore', function() {
});
});

it('should save/get/delete a buffer', function(done) {
var data = {
buf: new Buffer('010100000000000000000059400000000000006940', 'hex')
};
ds.save({
key: ds.key('Post'),
data: data
}, function (err, key) {
assert.ifError(err);
var assignedId = key.path[1];
assert(assignedId);
ds.get(key, function (err, entity) {
assert.ifError(err);
assert.deepEqual(entity.data, data);
ds.delete(ds.key(['Post', assignedId]), function(err) {
assert.ifError(err);
done();
});
});
});
});

it('should save/get/delete with a generated key id', function(done) {
ds.save({
key: ds.key('Post'),
Expand Down
12 changes: 12 additions & 0 deletions test/datastore/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
var assert = require('assert');
var entity = require('../../lib/datastore/entity.js');
var datastore = require('../../lib/datastore');
var ByteBuffer = require('bytebuffer');

var blogPostMetadata = {
title: { kind: String, indexed: true },
Expand Down Expand Up @@ -334,6 +335,17 @@ describe('queryToQueryProto', function() {
});
});

describe('propertyToValue', function() {
it('should translate a buffer', function() {
var buffer = new Buffer('010159406940');
var property = {
blob_value: ByteBuffer.wrap(buffer)
};
var returnedbuffer = entity.propertyToValue(property);
assert.deepEqual(buffer, returnedbuffer);
});
});

describe('valueToProperty', function() {
it('should translate a boolean', function() {
var val = entity.valueToProperty(true);
Expand Down

0 comments on commit c218eb8

Please sign in to comment.