test: add requiring fixtures to specify implementation to test

This commit is contained in:
Kelvin Jin 2017-10-12 10:51:25 -07:00
parent b37aaab454
commit b192adf2a1
14 changed files with 64 additions and 14 deletions

29
test/any_grpc.js Normal file
View File

@ -0,0 +1,29 @@
module.exports = {};
function assignExportsFromGlobal(globalField, exportsField) {
if (global[globalField] === 'js') {
module.exports[exportsField] = require('../packages/grpc-js');
} else if (global[globalField] === 'native') {
module.exports[exportsField] = require('../packages/grpc-native');
} else {
throw new Error([
`Invalid value for global.${globalField}: ${global.globalField}.`,
'If running from the command line, please --require a fixture first.'
].join(' '));
}
}
// Set 'server' and 'client' fields on this module's exports.
// These don't refer to the portions of the gRPC interface that are
// relevant to an application behaving as a server or a client respectively.
// Instead, they refer to the entire gRPC module as it's visible to the
// application.
// In other words, a test that simulates a gRPC client should treat
// require('any-grpc').client as the value of require('grpc'), and would simply
// not be expected to use server components.
assignExportsFromGlobal('_server_implementation', 'server');
assignExportsFromGlobal('_client_implementation', 'client');
// Increase clarity when there's no distinction between client/server
if (module.exports.client === module.exports.server) {
module.exports.all = module.exports.client;
}

View File

@ -20,7 +20,7 @@
var assert = require('assert'); var assert = require('assert');
var grpc = require('grpc'); var grpc = require('../any_grpc').all;
var math = grpc.load( var math = grpc.load(
__dirname + '/../../packages/grpc-native-core/deps/grpc/src/proto/math/math.proto').math; __dirname + '/../../packages/grpc-native-core/deps/grpc/src/proto/math/math.proto').math;

View File

@ -22,7 +22,7 @@ var assert = require('assert');
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var grpc = require('grpc'); var grpc = require('../any_grpc').all;
/** /**
* This is used for testing functions with multiple asynchronous calls that * This is used for testing functions with multiple asynchronous calls that

View File

@ -20,7 +20,7 @@
var assert = require('assert'); var assert = require('assert');
var grpc = require('grpc'); var grpc = require('../any_grpc').all;
var math = require('./math/math_pb'); var math = require('./math/math_pb');
var MathClient = require('./math/math_grpc_pb').MathClient; var MathClient = require('./math/math_grpc_pb').MathClient;

View File

@ -18,7 +18,7 @@
'use strict'; 'use strict';
var Metadata = require('grpc').Metadata; var Metadata = require('../any_grpc').all.Metadata;
var assert = require('assert'); var assert = require('assert');

View File

@ -21,7 +21,7 @@
var assert = require('assert'); var assert = require('assert');
var _ = require('lodash'); var _ = require('lodash');
var grpc = require('grpc'); var grpc = require('../any_grpc').all;
var MathClient = grpc.load( var MathClient = grpc.load(
__dirname + '/../../packages/grpc-native-core/deps/grpc/src/proto/math/math.proto').math.Math; __dirname + '/../../packages/grpc-native-core/deps/grpc/src/proto/math/math.proto').math.Math;

2
test/fixtures/js_js.js vendored Normal file
View File

@ -0,0 +1,2 @@
global._server_implementation = 'native';
global._client_implementation = 'js';

2
test/fixtures/js_native.js vendored Normal file
View File

@ -0,0 +1,2 @@
global._server_implementation = 'js';
global._client_implementation = 'native';

2
test/fixtures/native_js.js vendored Normal file
View File

@ -0,0 +1,2 @@
global._server_implementation = 'js';
global._client_implementation = 'native';

2
test/fixtures/native_native.js vendored Normal file
View File

@ -0,0 +1,2 @@
global._server_implementation = 'native';
global._client_implementation = 'native';

View File

@ -22,6 +22,7 @@ const execa = require('execa');
const path = require('path'); const path = require('path');
const del = require('del'); const del = require('del');
const linkSync = require('../util').linkSync; const linkSync = require('../util').linkSync;
const merge = require('merge2');
// gulp-help monkeypatches tasks to have an additional description parameter // gulp-help monkeypatches tasks to have an additional description parameter
const gulp = help(_gulp); const gulp = help(_gulp);
@ -49,5 +50,19 @@ gulp.task('internal.test.link.add', 'Link local copies of dependencies', () => {
}); });
gulp.task('internal.test.test', 'Run API-level tests', () => { gulp.task('internal.test.test', 'Run API-level tests', () => {
return gulp.src(`${apiTestDir}/*.js`).pipe(mocha({reporter: 'mocha-jenkins-reporter'})); // run mocha tests matching a glob with a pre-required fixture,
// returning the associated gulp stream
const runTestsWithFixture = (glob, fixture) => gulp
.src(glob)
.pipe(mocha({
reporter: 'mocha-jenkins-reporter',
require: `${testDir}/fixtures/${fixture}.js`
}));
const interopTest = `${testDir}/interop/interop_test.js`;
const tasks = [].concat(
['native_native'/*, 'js_js'*/]
.map((fixture) => runTestsWithFixture(`${apiTestDir}/*.js`, fixture)),
['native_native', 'native_js'/*, 'js_native', 'js_js'*/]
.map((fixture) => runTestsWithFixture(interopTest, fixture)))
return merge(tasks);
}); });

View File

@ -20,10 +20,9 @@
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
// TODO(murgatroid99): use multiple grpc implementations var grpc = require('../any_grpc').client;
var grpc = require('grpc');
var testProto = grpc.load({ var testProto = grpc.load({
root: __dirname + '/../../packages/grpc-native-core/deps/grpc', root: __dirname + '/../../../packages/grpc-native-core/deps/grpc',
file: 'src/proto/grpc/testing/test.proto'}).grpc.testing; file: 'src/proto/grpc/testing/test.proto'}).grpc.testing;
var GoogleAuth = require('google-auth-library'); var GoogleAuth = require('google-auth-library');

View File

@ -18,8 +18,8 @@
'use strict'; 'use strict';
var interop_server = require('../interop/interop_server.js'); var interop_server = require('./interop_server.js');
var interop_client = require('../interop/interop_client.js'); var interop_client = require('./interop_client.js');
var server; var server;

View File

@ -22,10 +22,9 @@ var fs = require('fs');
var path = require('path'); var path = require('path');
var _ = require('lodash'); var _ = require('lodash');
var AsyncDelayQueue = require('./async_delay_queue'); var AsyncDelayQueue = require('./async_delay_queue');
// TODO(murgatroid99): use multiple grpc implementations var grpc = require('../any_grpc').server;
var grpc = require('grpc');
var testProto = grpc.load({ var testProto = grpc.load({
root: __dirname + '/../../packages/grpc-native-core/deps/grpc', root: __dirname + '/../../../packages/grpc-native-core/deps/grpc',
file: 'src/proto/grpc/testing/test.proto'}).grpc.testing; file: 'src/proto/grpc/testing/test.proto'}).grpc.testing;
var ECHO_INITIAL_KEY = 'x-grpc-test-echo-initial'; var ECHO_INITIAL_KEY = 'x-grpc-test-echo-initial';