Skip to content

Commit

Permalink
[tests] Added multi-language tests #6
Browse files Browse the repository at this point in the history
  * Includes `microservice-examples` package
  * Adds "hello world" tests for all languages
  • Loading branch information
Marak committed Oct 5, 2016
1 parent c75d769 commit 0bbd430
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"devDependencies": {
"express": "^4.14.0",
"request": "^2.75.0",
"microservice-examples": "3.0.0"
"tape": "^4.6.0"
}
}
64 changes: 64 additions & 0 deletions test/all-languages-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// all-languages-tests.js
var test = require("tape");
var express = require('express');
var request = require('request');

var stack, handler, app, server, examples;

stack = require('../');

// Remark: babel and coffee-script are commented out since they aren't included in the package
// Even as devDependencies they are too big
var languages = ['bash', /* 'babel', 'coffee-script', */ 'smalltalk', 'lua', 'javascript', 'perl', 'php', 'python', 'python3', 'ruby', 'scheme', 'tcl'];

test('attempt to require microservice-examples module', function (t) {
examples = require('microservice-examples');
t.equal(typeof examples.services, "object", "returned services object");
t.end();
});

test('check if examples are available for all languages', function (t) {
languages.forEach(function (lang) {
t.equal(true, Object.keys(examples.services).indexOf(lang + '-hello-world') > 0, 'found example service for ' + lang);
});
t.end();
});

test('attempt to start server with handlers for all languages', function (t) {
app = express();
app.use(stack.plugins.bodyParser());
languages.forEach(function (lang) {
var service = examples.services[lang + '-hello-world'];
var handler = stack.spawn({
language: lang,
code: service.code
});
app.use('/' + lang, handler);
t.equal(typeof handler, "function", "/" + lang + " HTTP endpoint added");
});
server = app.listen(3000, function () {
t.end();
});
});

test('attempt to run hello world all languages', function (t) {
t.plan(languages.length);
languages.forEach(function (lang) {
request('http://localhost:3000/' + lang, function (err, res, body) {
var noCarriageReturn = ["perl", "scheme", "php"];
if (noCarriageReturn.indexOf(lang) !== -1) {
t.equal(body, 'hello world', 'got correct response from ' + lang);
} else {
t.equal(body, 'hello world\n', 'got correct response from ' + lang);
}
});
});
});
// TODO: request params test with JSON / language specific output

test('attempt to end server', function (t) {
server.close(function(){
t.ok(true, "ended server");
t.end();
});
});

0 comments on commit 0bbd430

Please sign in to comment.