Skip to content
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

chore: system tests for gax #334

Merged
merged 10 commits into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from 9 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
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ jobs:
command: npm run system-test
environment:
GCLOUD_PROJECT: long-door-651
GOOGLE_APPLICATION_CREDENTIALS: .circleci/key.json
GOOGLE_APPLICATION_CREDENTIALS: /home/node/project/.circleci/key.json
NPM_CONFIG_PREFIX: /home/node/.npm-global
- run:
name: Remove unencrypted key.
command: |
Expand Down
Binary file added .circleci/key.json.enc
Binary file not shown.
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@types/node": "^10.3.2",
"@types/proxyquire": "^1.3.28",
"@types/pumpify": "^1.4.1",
"@types/rimraf": "^2.0.2",
"@types/semver": "^5.5.0",
"@types/sinon": "^5.0.1",
"@types/source-map-support": "^0.4.1",
Expand All @@ -45,9 +46,11 @@
"istanbul": "~0.4.5",
"jsdoc": "^3.5.5",
"mocha": "~5.2.0",
"nyc": "^13.1.0",
"pegjs": "~0.10.0",
"proxyquire": "^2.0.1",
"pumpify": "^1.5.1",
"rimraf": "^2.6.2",
"sinon": "^7.0.0",
"source-map-support": "^0.5.6",
"stream-events": "^1.0.4",
Expand All @@ -67,7 +70,7 @@
"prepare": "npm run compile",
"pretest-only": "npm run compile",
"posttest": "npm run lint",
"system-test": "echo no system tests 😱",
"system-test": "nyc mocha --no-timeouts build/system-test/system.js",

This comment was marked as spam.

"samples-test": "echo no sample tests 😱"
},
"repository": "googleapis/gax-nodejs",
Expand All @@ -82,5 +85,13 @@
"homepage": "https://github.com/googleapis/gax-nodejs#readme",
"engines": {
"node": ">=6.0.0"
},
"nyc": {
"include": [

This comment was marked as spam.

This comment was marked as spam.

"build/**"
],
"exclude": [
"build/system-test/**"
]
}
}
138 changes: 137 additions & 1 deletion system-test/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,140 @@
* limitations under the License.
*/

console.warn(`no system tests available 👻`);
import * as cp from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import * as rimraf from 'rimraf';
import * as util from 'util';

const mkdir = util.promisify(fs.mkdir);
const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);
const rmrf = util.promisify(rimraf);

const baseRepoUrl = 'https://github.com/googleapis/';
const gaxPath = process.cwd();
const testDir = path.join(process.cwd(), 'system-test-run');

interface PackageJson {
dependencies: {[name: string]: string;};
}

interface ExecuteResult {
stdout: string;
stderr: string;
}

async function execute(command: string, cwd?: string): Promise<ExecuteResult> {
cwd = cwd || process.cwd();
const maxBuffer = 10 * 1024 * 1024;
console.log(`Execute: ${command} [cwd: ${cwd}]`);
return new Promise<ExecuteResult>((resolve, reject) => {
cp.exec(command, {cwd, maxBuffer}, (err, stdout, stderr) => {

This comment was marked as spam.

This comment was marked as spam.

if (err) {
reject(new Error(`Command ${command} terminated with error ${err}`));
} else {
resolve({stdout, stderr});
}
});
});
}

async function spawn(
command: string, args?: string[], cwd?: string): Promise<void> {
cwd = cwd || process.cwd();
args = args || [];
console.log(`Execute: ${command} ${args.join(' ')} [cwd: ${cwd}]`);
return new Promise<void>((resolve, reject) => {
const child =
cp.spawn(command, args || [], {cwd})
.on('close', (code: number|null, signal: string|null) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`Command ${command} terminated with code ${
code}, signal ${signal}`));
}
});
child.stdout.on('data', (chunk: Buffer) => {
process.stdout.write(chunk);
});
child.stderr.on('data', (chunk: Buffer) => {
process.stderr.write(chunk);
});
});
}

async function latestRelease(cwd: string): Promise<string> {
const gitTagOutput = (await execute('git tag --list', cwd)).stdout;
const tags =
gitTagOutput.split('\n')
.filter(str => str.match(/^v\d+\.\d+\.\d+$/))
.sort((tag1: string, tag2: string): number => {
const match1 = tag1.match(/^v(\d+)\.(\d+)\.(\d+)$/);
const match2 = tag2.match(/^v(\d+)\.(\d+)\.(\d+)$/);
if (!match1 || !match2) {
throw new Error(`Cannot compare git tags ${tag1} and ${tag2}`);
}
// compare major version, then minor versions, then patch versions.
// return positive number, zero, or negative number
for (let idx = 1; idx <= 3; ++idx) {
if (match1[idx] !== match2[idx]) {
return Number(match1[idx]) - Number(match2[idx]);
}
}
return 0;
});
// the last tag in the list is the latest release
return tags[tags.length - 1];
}

async function preparePackage(packageName: string): Promise<void> {
await spawn(
'git', ['clone', `${baseRepoUrl}${packageName}.git`, packageName]);
const tag = await latestRelease(packageName);
await spawn('git', ['checkout', tag], packageName);
await spawn('npm', ['link', '../../'], packageName);
// npm-install-retry prints a lot, so run it silently
await execute('node .circleci/npm-install-retry.js', packageName);
}

async function runSystemTest(packageName: string): Promise<void> {
await spawn('npm', ['run', 'system-test'], packageName);
}

describe('Run system tests for some libraries', () => {
before(async () => {
await rmrf(testDir);
await mkdir(testDir);
process.chdir(testDir);
console.log(`Running tests in ${testDir}.`);
});
// Video intelligence API has long running operations
describe('video-intelligence', () => {
before(async () => {
await preparePackage('nodejs-video-intelligence');
});
it('should pass system tests', async () => {
await runSystemTest('nodejs-video-intelligence');
});
});
// Pub/Sub has streaming methods and pagination
describe('pubsub', () => {
before(async () => {
await preparePackage('nodejs-pubsub');
});
it('should pass system tests', async () => {
await runSystemTest('nodejs-pubsub');
});
});
// Speech only has smoke tests, but still...
describe('speech', () => {
before(async () => {
await preparePackage('nodejs-speech');
});
it('should pass system tests', async () => {
await runSystemTest('nodejs-speech');
});
});
});
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"include": [
"src/*.ts",
"test/*.ts"
"test/*.ts",
"system-test/*.ts"

This comment was marked as spam.

]
}