Skip to content

core (grpc): correctly convert arrays & bools #1329

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

Merged
merged 1 commit into from
May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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