Skip to content

Commit

Permalink
test: add test for x-goog-api-client (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Aug 19, 2019
1 parent a7b9083 commit 36b6598
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/google-cloud-resourcemanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"predocs-test": "npm run docs"
},
"dependencies": {
"@google-cloud/paginator": "^2.0.0",
"@google-cloud/common": "^2.0.0",
"@google-cloud/paginator": "^2.0.0",
"@google-cloud/promisify": "^1.0.0"
},
"devDependencies": {
Expand All @@ -65,7 +65,7 @@
"nyc": "^14.0.0",
"power-assert": "^1.4.4",
"prettier": "^1.7.4",
"proxyquire": "^2.0.0",
"proxyquire": "^2.1.3",
"source-map-support": "^0.5.6",
"typescript": "~3.5.0",
"uuid": "^3.0.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/google-cloud-resourcemanager/src/project.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Copyright 2015 Google Inc. All Rights Reserved.
* Copyright 2015 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
68 changes: 68 additions & 0 deletions packages/google-cloud-resourcemanager/test/headers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as assert from 'assert';
import * as proxyquire from 'proxyquire';

const error = Error('not implemented');

interface Request {
headers: {
[key: string]: string;
};
}

describe('headers', () => {
const requests: Request[] = [];
const {Resource} = proxyquire('../../', {
'google-auth-library': {
GoogleAuth: class {
async getProjectId() {
return 'foo-project';
}
async getClient() {
return class {
async request() {
return {};
}
};
}
getCredentials() {
return {};
}
async authorizeRequest(req: Request) {
requests.push(req);
throw error;
}
},
'@global': true,
},
});

it('populates x-goog-api-client header', async () => {
const resource = new Resource();
try {
const [projects] = await resource.getProjects();
} catch (err) {
if (err !== error) throw err;
}
assert.ok(
/^gl-node\/[0-9]+\.[0-9]+\.[-.\w]+ gccl\/[0-9]+\.[0-9]+\.[-.\w]+$/.test(
requests[0].headers['x-goog-api-client']
)
);
});
});

0 comments on commit 36b6598

Please sign in to comment.