Skip to content

Commit f2cd5ea

Browse files
Benjamin E. CoeJustinBeckwith
authored andcommitted
fix: add test for x-goog-api-client header (#556)
1 parent 808a24b commit f2cd5ea

File tree

7 files changed

+25
-14
lines changed

7 files changed

+25
-14
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"predocs-test": "npm run docs"
5353
},
5454
"dependencies": {
55-
"@google-cloud/common-grpc": "^1.0.0",
55+
"@google-cloud/common-grpc": "^1.0.5",
5656
"@google-cloud/paginator": "^2.0.0",
5757
"@google-cloud/projectify": "^1.0.0",
5858
"@google-cloud/promisify": "^1.0.0",
@@ -69,6 +69,7 @@
6969
"pumpify": "^2.0.0",
7070
"snakecase-keys": "^3.0.0",
7171
"stream-events": "^1.0.4",
72+
"teeny-request": "^5.2.1",
7273
"through2": "^3.0.0",
7374
"type-fest": "^0.7.0"
7475
},
@@ -100,6 +101,7 @@
100101
"google-proto-files": "^1.0.0",
101102
"grpc": "^1.22.2",
102103
"gts": "^1.0.0",
104+
"http2spy": "^1.1.0",
103105
"intelli-espower-loader": "^1.0.1",
104106
"jsdoc": "^3.6.2",
105107
"jsdoc-fresh": "^1.0.1",

src/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import * as extend from 'extend';
2323
import {GoogleAuth} from 'google-auth-library';
2424
import * as gax from 'google-gax';
2525
import {ClientReadableStream} from 'grpc';
26-
import * as request from 'request';
26+
import {Response} from 'teeny-request';
2727

2828
const pumpify = require('pumpify');
2929
import * as streamEvents from 'stream-events';
@@ -84,11 +84,7 @@ export interface CreateSinkRequest {
8484
}
8585

8686
export interface CreateSinkCallback {
87-
(
88-
err: Error | null,
89-
sink?: Sink | null,
90-
resp?: LogSink | request.Response
91-
): void;
87+
(err: Error | null, sink?: Sink | null, resp?: LogSink | Response): void;
9288
}
9389

9490
export type GetEntriesResponse = [

src/log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {callbackifyAll} from '@google-cloud/promisify';
1919
import arrify = require('arrify');
2020
import * as extend from 'extend';
2121
import {CallOptions} from 'google-gax';
22-
import {Response} from 'request';
22+
import {Response} from 'teeny-request';
2323

2424
import {google} from '../proto/logging';
2525

src/v2/config_service_v2_client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class ConfigServiceV2Client {
8282

8383
// Determine the client header string.
8484
const clientHeader = [
85-
`gl-node/${process.version}`,
85+
`gl-node/${process.versions.node}`,
8686
`grpc/${gaxGrpc.grpcVersion}`,
8787
`gax/${gax.version}`,
8888
`gapic/${VERSION}`,

src/v2/logging_service_v2_client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class LoggingServiceV2Client {
8282

8383
// Determine the client header string.
8484
const clientHeader = [
85-
`gl-node/${process.version}`,
85+
`gl-node/${process.versions.node}`,
8686
`grpc/${gaxGrpc.grpcVersion}`,
8787
`gax/${gax.version}`,
8888
`gapic/${VERSION}`,

src/v2/metrics_service_v2_client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class MetricsServiceV2Client {
8181

8282
// Determine the client header string.
8383
const clientHeader = [
84-
`gl-node/${process.version}`,
84+
`gl-node/${process.versions.node}`,
8585
`grpc/${gaxGrpc.grpcVersion}`,
8686
`gax/${gax.version}`,
8787
`gapic/${VERSION}`,

system-test/logging.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {HOST_ADDRESS} from 'gcp-metadata';
2727
import * as nock from 'nock';
2828
import {Duplex} from 'stream';
2929
import * as uuid from 'uuid';
30-
30+
import * as http2spy from 'http2spy';
3131
import {Logging, Sink} from '../src';
3232

3333
// block all attempts to chat with the metadata server (kokoro runs on GCE)
@@ -219,8 +219,10 @@ describe('Logging', () => {
219219
// tslint:disable-next-line no-any
220220
const logs: any[] = [];
221221

222-
function getTestLog() {
223-
const log = logging.log(`system-test-logs-${uuid.v4()}`);
222+
function getTestLog(loggingInstnce = null) {
223+
const log = (loggingInstnce || logging).log(
224+
`system-test-logs-${uuid.v4()}`
225+
);
224226
logs.push(log);
225227

226228
const logEntries = [
@@ -579,6 +581,17 @@ describe('Logging', () => {
579581
const {log, logEntries} = getTestLog();
580582
log.warning(logEntries, options, done);
581583
});
584+
585+
it('should populate x-goog-api-client header', async () => {
586+
const {Logging} = http2spy.require(require.resolve('../src'));
587+
const {log, logEntries} = getTestLog(new Logging());
588+
await log.write(logEntries[0], options);
589+
assert.ok(
590+
/gl-node\/[0-9]+\.[\w.-]+ grpc\/[0-9]+\.[\w.-]+ gax\/[0-9]+\.[\w.-]+ gapic\/[0-9]+\.[\w.-]+ gccl\/[0-9]+\.[\w.-]+/.test(
591+
http2spy.requests[0]['x-goog-api-client'][0]
592+
)
593+
);
594+
});
582595
});
583596

584597
function generateName() {

0 commit comments

Comments
 (0)