Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / http-proxy / test / core / run-single
1 #!/usr/bin/env node
2 /*
3   run-single.js: test runner for core tests
4
5   Copyright (c) 2011 Nodejitsu
6
7   Permission is hereby granted, free of charge, to any person obtaining
8   a copy of this software and associated documentation files (the
9   "Software"), to deal in the Software without restriction, including
10   without limitation the rights to use, copy, modify, merge, publish,
11   distribute, sublicense, and/or sell copies of the Software, and to
12   permit persons to whom the Software is furnished to do so, subject to
13   the following conditions:
14
15   The above copyright notice and this permission notice shall be
16   included in all copies or substantial portions of the Software.
17
18   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22   LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 */
27
28 //
29 // Basic idea behind core test runner is to modify core tests as little as
30 // possible. That's why we start up node-http-proxy here instead of embeeding
31 // this code in tests.
32 //
33 // In most cases only modification to core tests you'll need is changing port
34 // of http client to common.PROXY_PORT.
35 //
36
37 var path = require('path'),
38     spawn = require('child_process').spawn,
39     httpProxy = require('../../'),
40     common = require('./common');
41
42 var test = process.argv[2],
43     testProcess;
44
45 if (!test) {
46   return console.error('Need test to run');
47 }
48
49 console.log('Running test ' + test);
50
51 var proxy = httpProxy.createServer(common.PORT, 'localhost');
52 proxy.listen(common.PROXY_PORT);
53
54 proxy.on('listening', function () {
55   console.log('Proxy server listening on ' + common.PROXY_PORT);
56   testProcess = spawn(process.argv[0], [ process.argv[2] ]);
57   testProcess.stdout.pipe(process.stdout);
58   testProcess.stderr.pipe(process.stderr);
59
60   testProcess.on('exit', function (code) {
61     process.exit(code);
62   });
63 });
64
65 process.on('SIGTERM', function () {
66   testProcess.kill();
67   process.exit(1);
68 });
69
70 // vim:filetype=javascript