http.createServer(function (req, res) { var url = URL.parse(req.url); res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(fs.readFileSync(__dirname + url.pathname)); })
test('upload - bad body encoding', function (t) { const dataDirectory = path.resolve( __dirname, 'fixtures', 'only-folder', '10000.clinic-doctor' ) const server = http.createServer(function (req, res) { res.end('not JSON') }) server.listen(0, '127.0.0.1', function () { const uploadUrl = `http://localhost:${server.address().port}` tarAndUpload(dataDirectory, uploadUrl, null, {}, function (err) { t.strictEqual(err.name, 'SyntaxError') server.close(() => t.end()) }) }) })
http.createServer((request, response) => { response.end(); })
res.end('hello') instance.info(res, 'my response') })
test('clinic upload - bad status code', function (t) { const server = http.createServer(function (req, res) { res.statusCode = 500 res.end() }) server.listen(function () { cli({ env: { CLINIC_JWT: successfulJwt }, relayStderr: false }, [ 'clinic', 'upload', '--server', `http://127.0.0.1:${server.address().port}`, '--no-open', doctorADirectory ], function (err, stdout, stderr) { t.strictDeepEqual(err, new Error('process exited with exit code 1')) t.strictDeepEqual(stdout.trim().split('\n'), [ 'Signed in as test@test.com.', `Uploading data for ${doctorADirectory} and ${doctorADirectory}.html` ]) t.ok(stderr.includes('Bad status code: 500')) server.close(() => t.end()) }) }) })
http.createServer(function (req, res) { var url = URL.parse(req.url, true), uri = decodeURIComponent(url.pathname), postData = ''; if (paths[uri] !== undefined) { if (req.method === 'POST') { req.on('data', function (chunk) { postData += chunk.toString(); }); req.on('end', function () { if (!req.headers['content-type'] || req.headers['content-type'].indexOf('multipart') !== 0) postData = qs.parse(postData); paths[uri](url, req, res, postData); }); } else { paths[uri](url, req, res); } } else { res.writeHead(404); res.end(); } })
originalReq = req instance.info({ req }, 'my request') res.end('hello') }) server.unref()
server = http.createServer(function (req, res) { t.fail('should not request the server') res.end() }) server.listen(0, '127.0.0.1', done) tarAndUpload(bigFileDirectory, uploadUrl, null, {}, function (err) { t.strictDeepEqual(err, new Error('Too much data. Should be less than 32MB')) server.close(() => t.end()) }) })
originalReq = req instance.info(req, 'my request') res.end('hello') }) server.unref()
res.setHeader('x-single', 'y') res.setHeader('x-multi', [1, 2]) res.end('hello') instance.info({ res }, 'my response') })
test('upload - error message from server', function (t) { const dataDirectory = path.resolve( __dirname, 'fixtures', 'only-folder', '10000.clinic-doctor' ) const server = http.createServer(function (req, res) { res.statusCode = 400 res.end('{"statusCode": 400, "error": "Bad Request", "message": "This is the message"}') }) server.listen(0, '127.0.0.1', function () { const uploadUrl = `http://localhost:${server.address().port}` tarAndUpload(dataDirectory, uploadUrl, null, {}, function (err) { t.strictDeepEqual(err, Object.assign(new Error('This is the message'), { reply: { statusCode: 400, error: 'Bad Request', message: 'This is the message' } })) server.close(() => t.end()) }) }) })
const child = instance.child({ req }) child.info('my request') res.end('hello') })
test('upload - bad status code', function (t) { const dataDirectory = path.resolve( __dirname, 'fixtures', 'only-folder', '10000.clinic-doctor' ) const server = http.createServer(function (req, res) { res.statusCode = 500 res.end() }) server.listen(0, '127.0.0.1', function () { const uploadUrl = `http://localhost:${server.address().port}` tarAndUpload(dataDirectory, uploadUrl, null, {}, function (err) { t.strictDeepEqual(err, new Error('Bad status code: 500')) server.close(() => t.end()) }) }) })