Skip to content

Commit

Permalink
core (grpc): correctly convert arrays & bools (#1329)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed May 18, 2016
1 parent 0fdff64 commit 79b05af
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
6 changes: 4 additions & 2 deletions lib/common/grpc-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ GrpcService.convertValue_ = function(value) {
};
} else if (is.boolean(value)) {
convertedValue = {
booleanValue: value
boolValue: value
};
} else if (Buffer.isBuffer(value)) {
convertedValue = {
Expand All @@ -344,7 +344,9 @@ GrpcService.convertValue_ = function(value) {
};
} else if (is.array(value)) {
convertedValue = {
listValue: value.map(GrpcService.convertValue_)
listValue: {
values: value.map(GrpcService.convertValue_)
}
};
} else {
throw new Error('Value of type ' + typeof value + ' not recognized.');
Expand Down
8 changes: 6 additions & 2 deletions system-test/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,12 @@ describe('Logging', function() {
// object data
log.entry({ delegate: 'my_username' }),

// null data
log.entry({ nonValue: null }),
// various data types
log.entry({
nonValue: null,
boolValue: true,
arrayValue: [ 1, 2, 3 ]
}),

// nested object data
log.entry({
Expand Down
14 changes: 8 additions & 6 deletions test/common/grpc-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ describe('GrpcService', function() {
});

assert.deepEqual(GrpcService.convertValue_(true), {
booleanValue: true
boolValue: true
});

assert.strictEqual(
Expand Down Expand Up @@ -733,11 +733,13 @@ describe('GrpcService', function() {
it('should convert arrays', function() {
var convertedValue = GrpcService.convertValue_([1, 2, 3]);

assert.deepEqual(convertedValue.listValue, [
GrpcService.convertValue_(1),
GrpcService.convertValue_(2),
GrpcService.convertValue_(3)
]);
assert.deepEqual(convertedValue.listValue, {
values: [
GrpcService.convertValue_(1),
GrpcService.convertValue_(2),
GrpcService.convertValue_(3)
]
});
});

it('should throw if a type is not recognized', function() {
Expand Down

0 comments on commit 79b05af

Please sign in to comment.