Commit a97d5de3 authored by Indrek Jentson's avatar Indrek Jentson

Testid parandatud

Signed-off-by: Indrek Jentson's avatarIndrek Jentson <indrek.jentson@ut.ee>
parent 5c98a90b
...@@ -34,3 +34,5 @@ $ docker exec -it kl_wrapper_name bash ...@@ -34,3 +34,5 @@ $ docker exec -it kl_wrapper_name bash
$ docker exec kl_wrapper_name /wrapper/docker_update.sh $ docker exec kl_wrapper_name /wrapper/docker_update.sh
# Wrapperi koodi testimine
...@@ -89,6 +89,4 @@ router.get('/:sessionId/kill', function(req, res) { ...@@ -89,6 +89,4 @@ router.get('/:sessionId/kill', function(req, res) {
}); });
}); });
module.exports = router; module.exports = router;
{ {
"name": "keeleliin-wrapper-service", "name": "keeleliin-wrapper-service",
"version": "1.1.0", "version": "1.1.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
...@@ -572,28 +572,6 @@ ...@@ -572,28 +572,6 @@
"vary": "~1.1.2" "vary": "~1.1.2"
}, },
"dependencies": { "dependencies": {
"body-parser": {
"version": "1.18.3",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz",
"integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=",
"requires": {
"bytes": "3.0.0",
"content-type": "~1.0.4",
"debug": "2.6.9",
"depd": "~1.1.2",
"http-errors": "~1.6.3",
"iconv-lite": "0.4.23",
"on-finished": "~2.3.0",
"qs": "6.5.2",
"raw-body": "2.3.3",
"type-is": "~1.6.16"
}
},
"bytes": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg="
},
"debug": { "debug": {
"version": "2.6.9", "version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
...@@ -601,53 +579,6 @@ ...@@ -601,53 +579,6 @@
"requires": { "requires": {
"ms": "2.0.0" "ms": "2.0.0"
} }
},
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
},
"iconv-lite": {
"version": "0.4.23",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz",
"integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==",
"requires": {
"safer-buffer": ">= 2.1.2 < 3"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
"requires": {
"ee-first": "1.1.1"
}
},
"qs": {
"version": "6.5.2",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
},
"raw-body": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.3.tgz",
"integrity": "sha512-9esiElv1BrZoI3rCDuOuKCBRbuApGGaDPQfjSflGxdy4oyzqghxu6klEkkVIvBje+FF0BX9coEv8KqW6X/7njw==",
"requires": {
"bytes": "3.0.0",
"http-errors": "1.6.3",
"iconv-lite": "0.4.23",
"unpipe": "1.0.0"
}
} }
} }
}, },
...@@ -698,24 +629,6 @@ ...@@ -698,24 +629,6 @@
"requires": { "requires": {
"ms": "2.0.0" "ms": "2.0.0"
} }
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
"requires": {
"ee-first": "1.1.1"
}
} }
} }
}, },
...@@ -1878,33 +1791,10 @@ ...@@ -1878,33 +1791,10 @@
"ms": "2.0.0" "ms": "2.0.0"
} }
}, },
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
},
"mime": { "mime": {
"version": "1.4.1", "version": "1.4.1",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz",
"integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==" "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ=="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
"requires": {
"ee-first": "1.1.1"
}
} }
} }
}, },
...@@ -1929,41 +1819,6 @@ ...@@ -1929,41 +1819,6 @@
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz",
"integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ=="
}, },
"should": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/should/-/should-7.1.1.tgz",
"integrity": "sha1-ZGTEi298Hh8YrASDV4+i3VXCxuA=",
"dev": true,
"requires": {
"should-equal": "0.5.0",
"should-format": "0.3.1",
"should-type": "0.2.0"
}
},
"should-equal": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/should-equal/-/should-equal-0.5.0.tgz",
"integrity": "sha1-x5fxNfMGf+tp6+zbMGscP+IbPm8=",
"dev": true,
"requires": {
"should-type": "0.2.0"
}
},
"should-format": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/should-format/-/should-format-0.3.1.tgz",
"integrity": "sha1-LLt4JGFnCs5CkrKx7EaNuM+Z4zA=",
"dev": true,
"requires": {
"should-type": "0.2.0"
}
},
"should-type": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/should-type/-/should-type-0.2.0.tgz",
"integrity": "sha1-ZwfvlVKdmJ3MCY/gdTqx+RNrt/Y=",
"dev": true
},
"slice-stream": { "slice-stream": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/slice-stream/-/slice-stream-1.0.0.tgz", "resolved": "https://registry.npmjs.org/slice-stream/-/slice-stream-1.0.0.tgz",
...@@ -2085,9 +1940,9 @@ ...@@ -2085,9 +1940,9 @@
} }
}, },
"supertest": { "supertest": {
"version": "3.3.0", "version": "3.4.2",
"resolved": "https://registry.npmjs.org/supertest/-/supertest-3.3.0.tgz", "resolved": "https://registry.npmjs.org/supertest/-/supertest-3.4.2.tgz",
"integrity": "sha512-dMQSzYdaZRSANH5LL8kX3UpgK9G1LRh/jnggs/TI0W2Sz7rkMx9Y48uia3K9NgcaWEV28tYkBnXE4tiFC77ygQ==", "integrity": "sha512-WZWbwceHUo2P36RoEIdXvmqfs47idNNZjCuJOqDz6rvtkk8ym56aU5oglORCpPeXGxT7l9rkJ41+O1lffQXYSA==",
"dev": true, "dev": true,
"requires": { "requires": {
"methods": "^1.1.2", "methods": "^1.1.2",
......
{ {
"name": "keeleliin-wrapper-service", "name": "keeleliin-wrapper-service",
"version": "1.1.0", "version": "1.1.1",
"private": true, "private": true,
"scripts": { "scripts": {
"start": "node ./app.js", "start": "node ./app.js",
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
"body-parser": "^1.18.3", "body-parser": "^1.18.3",
"debug": "^4.1.1", "debug": "^4.1.1",
"diskusage": "^1.0.0", "diskusage": "^1.0.0",
"express": "~4.16.0", "express": "^4.16.4",
"fs": "0.0.2", "fs": "0.0.2",
"graceful-fs": "^4.1.2", "graceful-fs": "^4.1.15",
"is-gzip": "^1.0.0", "is-gzip": "^1.0.0",
"is-tar": "^1.0.0", "is-tar": "^1.0.0",
"is-zip": "^1.0.0", "is-zip": "^1.0.0",
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
"assert": "^1.3.0", "assert": "^1.3.0",
"istanbul": "^0.4.5", "istanbul": "^0.4.5",
"mocha": "^5.2.0", "mocha": "^5.2.0",
"should": "^7.0.1", "should": "^13.2.3",
"supertest": "^3.3.0" "supertest": "^3.4.2"
} }
} }
...@@ -62,9 +62,6 @@ function ServiceRequest( requestBody, requestFiles ) { ...@@ -62,9 +62,6 @@ function ServiceRequest( requestBody, requestFiles ) {
async.forEachOf(config.wrapper.requestConf.requestFiles, function (requestFile, fileId, innerCb) { async.forEachOf(config.wrapper.requestConf.requestFiles, function (requestFile, fileId, innerCb) {
logger.debug( requestFile );
logger.debug( fileId );
var fileItem = self.files[fileId]; var fileItem = self.files[fileId];
if(!fileItem){ if(!fileItem){
......
/** /**
* Created by priit on 18.06.15. * Created by priit on 18.06.15.
*/ */
var routesTests = require('./routes'); var routesTests = require('./routes');
\ No newline at end of file var payloadTests = require('./payload');
\ No newline at end of file
/**
* sudo npm install -g mocha
* # start redis-server
* # create config.js and set desired values to paths
* # run tests:
* npm test
*/
var server = require('../../www/server');
var config = require('../../config');
var should = require('should');
var assert = require('assert');
var request = require('request');
var fs = require('fs');
describe('Services', function() {
var url = 'http://127.0.0.1:' + config.wrapper.port;
buildData = function(body, fileName) {
var form = {};
form['body'] = body;
var file = { key: 'content', path: fileName };
var attachment = fs.createReadStream( fileName );
if (form[file.key] == undefined){
form[file.key] = attachment;
} else if(Array.isArray(form[file.key])) {
form[file.key].push( attachment );
} else {
var previousAttachment = form[file.key];
form[file.key] = [previousAttachment, attachment];
}
return form;
};
describe('With files', function() {
it('Vastab sünkroonselt teenuse päringule', function(done){
var body = {
service: {
meta: {
isAsync: false
},
pipecontent: {
content: "data"
}
}
};
var tmpPath = config.fs.tmpPath;
var source = tmpPath + '/test.txt';
fs.writeFileSync(source, 'Faili sisu');
var formData = buildData(JSON.stringify(body), source);
request
.post({"url":url+'/api/v1/service', formData:formData}, function(err,res,body) {
if (err) {
throw err;
}
// console.log('res: '+JSON.stringify(res));
var body = JSON.parse(res.body);
body.response.should.have.property('success');
body.response.success.should.equal(true);
done();
});
});
it('Vastab asünkroonselt', function(done){
var body = {
service: {
meta: {
isAsync: true
},
pipecontent: {
content: 'data'
}
}
};
var tmpPath = config.fs.tmpPath;
var source = tmpPath + '/test.txt';
fs.writeFileSync(source, 'Faili sisu');
var formData = buildData(JSON.stringify(body), source);
request
.post({"url":url+'/api/v1/service', formData:formData}, function(err,res,body) {
if (err) {
throw err;
}
// console.log('res: '+JSON.stringify(res));
var body = JSON.parse(res.body);
body.response.should.have.property('success');
body.response.success.should.equal(true);
done();
});
/*
request(url)
.post('/api/v1/service')
.field('body', body)
.attach('files', source)
.expect('Content-Type', /json/)
.expect(200) //Status code
.end(function(err,res) {
if (err) {
throw err;
}
res.body.should.have.property('success');
if (res.body.success) {
res.body.should.have.property('response');
res.body.response.should.have.property('sessionId');
res.body.response.message.should.equal('RUNNING');
res.body.response.should.not.have.property('pipecontent');
var sessionId = res.body.response.serviceId;
setTimeout(function () {
request(url)
.get('/api/v1/service/' + sessionId)
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) {
throw err;
}
res.body.should.not.have.property('errors');
res.body.response.message.should.equal('OK');
res.body.response.should.have.property('pipecontent');
done();
});
}, 5000);
} else {
console.log('THIS is NOT working :(');
done()
};
});
*/
});
});
});
\ No newline at end of file
/** /**
* sudo npm install -g mocha * sudo npm install -g mocha
* # start redis-server
* # create config.js and set desired values to paths
* # run tests:
* npm test
*/ */
var server = require('../../www/server'); var server = require('../../www/server');
var config = require('../../config'); var config = require('../../config');
...@@ -7,6 +11,7 @@ var config = require('../../config'); ...@@ -7,6 +11,7 @@ var config = require('../../config');
var should = require('should'); var should = require('should');
var assert = require('assert'); var assert = require('assert');
var request = require('supertest'); var request = require('supertest');
var fs = require('fs');
describe('Routing', function() { describe('Routing', function() {
var url = 'http://127.0.0.1:' + config.wrapper.port; var url = 'http://127.0.0.1:' + config.wrapper.port;
...@@ -67,36 +72,6 @@ describe('Routing', function() { ...@@ -67,36 +72,6 @@ describe('Routing', function() {
}) })
}); });
it('Vastab sünkroonselt teenuse päringule', function(done){
var body = {
service: {
meta: {
isAsync: false
},
pipecontent: {
content: 'data'
}
}
};
request(url)
.post('/api/v1/service')
.send(body)
.expect('Content-Type', /json/)
.expect(200) //Status code
.end(function(err,res) {
if (err) {
throw err;
}
res.body.should.have.property('success');
res.body.success.should.equal(false);
res.body.should.have.property('errors');
res.body.errors.should.have.property('content');
res.body.errors.content.should.equal('Nõutud faili ei saadetud');
done();
});
});
it('Annab pipecontenti contenti puudumise vea', function(done){ it('Annab pipecontenti contenti puudumise vea', function(done){
var body = { var body = {
service: { service: {
...@@ -125,50 +100,5 @@ describe('Routing', function() { ...@@ -125,50 +100,5 @@ describe('Routing', function() {
}); });
}); });
it('Vastab asünkroonselt', function(done){
var body = {
service: {
meta: {
isAsync: true
},
pipecontent: {
content: 'data'
}
}
};
request(url)
.post('/api/v1/service')
.send(body)
.expect('Content-Type', /json/)
.expect(200) //Status code
.end(function(err,res) {
if (err) {
throw err;
}
res.body.response.should.have.property('sessionId');
res.body.response.message.should.equal('RUNNING');
res.body.response.should.not.have.property('pipecontent');
var sessionId = res.body.response.serviceId;
setTimeout(function () {
request(url)
.get('/api/v1/service/' + sessionId)
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) {
throw err;
}
res.body.should.not.have.property('errors');
res.body.response.message.should.equal('OK');
res.body.response.should.have.property('pipecontent');
done();
});
}, 5000);
});
});
}); });
}); });
\ No newline at end of file
...@@ -18,7 +18,27 @@ describe('File util', function() { ...@@ -18,7 +18,27 @@ describe('File util', function() {
done(); done();
}); });
it('Faili liigutamine', function(done) { it('should copy file from source to target', function(done) {
//loo fail
fs.writeFileSync(mvSource, 'Faili sisu');
fs.unlink(mvTarget, function () {
should(fs.existsSync(mvSource)).be.ok();
should(fs.existsSync(mvTarget)).not.be.ok();
FileUtil.cp(mvSource, mvTarget, function(){
should(fs.existsSync(mvSource)).be.ok();
should(fs.existsSync(mvTarget)).be.ok();
fs.unlink(mvTarget, function () {
done();
});
});
});
});
it('should move file from source to target', function(done) {
//loo fail //loo fail
fs.writeFileSync(mvSource, 'Faili sisu'); fs.writeFileSync(mvSource, 'Faili sisu');
...@@ -38,7 +58,7 @@ describe('File util', function() { ...@@ -38,7 +58,7 @@ describe('File util', function() {
}); });
}); });
it('Olematu Faili kopeerimine', function(done) { it('should try to copy not existing source to target', function(done) {
fs.unlink(mvTarget, function () { fs.unlink(mvTarget, function () {
should(fs.existsSync(mvSource)).not.be.ok(); should(fs.existsSync(mvSource)).not.be.ok();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment