mirror of https://github.com/grpc/grpc-node.git
test: add requiring fixtures to specify implementation to test
This commit is contained in:
parent
b37aaab454
commit
b192adf2a1
|
@ -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;
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
var assert = require('assert');
|
||||
|
||||
var grpc = require('grpc');
|
||||
var grpc = require('../any_grpc').all;
|
||||
var math = grpc.load(
|
||||
__dirname + '/../../packages/grpc-native-core/deps/grpc/src/proto/math/math.proto').math;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ var assert = require('assert');
|
|||
var fs = require('fs');
|
||||
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
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
var assert = require('assert');
|
||||
|
||||
var grpc = require('grpc');
|
||||
var grpc = require('../any_grpc').all;
|
||||
var math = require('./math/math_pb');
|
||||
var MathClient = require('./math/math_grpc_pb').MathClient;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var Metadata = require('grpc').Metadata;
|
||||
var Metadata = require('../any_grpc').all.Metadata;
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
var assert = require('assert');
|
||||
var _ = require('lodash');
|
||||
|
||||
var grpc = require('grpc');
|
||||
var grpc = require('../any_grpc').all;
|
||||
|
||||
var MathClient = grpc.load(
|
||||
__dirname + '/../../packages/grpc-native-core/deps/grpc/src/proto/math/math.proto').math.Math;
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
global._server_implementation = 'native';
|
||||
global._client_implementation = 'js';
|
|
@ -0,0 +1,2 @@
|
|||
global._server_implementation = 'js';
|
||||
global._client_implementation = 'native';
|
|
@ -0,0 +1,2 @@
|
|||
global._server_implementation = 'js';
|
||||
global._client_implementation = 'native';
|
|
@ -0,0 +1,2 @@
|
|||
global._server_implementation = 'native';
|
||||
global._client_implementation = 'native';
|
|
@ -22,6 +22,7 @@ const execa = require('execa');
|
|||
const path = require('path');
|
||||
const del = require('del');
|
||||
const linkSync = require('../util').linkSync;
|
||||
const merge = require('merge2');
|
||||
|
||||
// gulp-help monkeypatches tasks to have an additional description parameter
|
||||
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', () => {
|
||||
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);
|
||||
});
|
||||
|
|
|
@ -20,10 +20,9 @@
|
|||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
// TODO(murgatroid99): use multiple grpc implementations
|
||||
var grpc = require('grpc');
|
||||
var grpc = require('../any_grpc').client;
|
||||
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;
|
||||
var GoogleAuth = require('google-auth-library');
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var interop_server = require('../interop/interop_server.js');
|
||||
var interop_client = require('../interop/interop_client.js');
|
||||
var interop_server = require('./interop_server.js');
|
||||
var interop_client = require('./interop_client.js');
|
||||
|
||||
var server;
|
||||
|
|
@ -22,10 +22,9 @@ var fs = require('fs');
|
|||
var path = require('path');
|
||||
var _ = require('lodash');
|
||||
var AsyncDelayQueue = require('./async_delay_queue');
|
||||
// TODO(murgatroid99): use multiple grpc implementations
|
||||
var grpc = require('grpc');
|
||||
var grpc = require('../any_grpc').server;
|
||||
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;
|
||||
|
||||
var ECHO_INITIAL_KEY = 'x-grpc-test-echo-initial';
|
||||
|
|
Loading…
Reference in New Issue