mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 18:25:57 +01:00
more sequelize as usual
This commit is contained in:
@@ -2,10 +2,31 @@
|
||||
|
||||
const express = require('express')
|
||||
|
||||
function check_helper(req, res) {
|
||||
if (req.params.param.length > 2) {
|
||||
res.status(404)
|
||||
res.send('ko')
|
||||
} else {
|
||||
return req.params.param + 'ok'
|
||||
}
|
||||
}
|
||||
|
||||
const app = express()
|
||||
app.get('/', (req, res) => {
|
||||
res.send('hello world')
|
||||
})
|
||||
app.get('/check-helper-1/:param', (req, res) => {
|
||||
const ret = check_helper(req, res)
|
||||
if (ret) {
|
||||
res.send(ret)
|
||||
}
|
||||
})
|
||||
app.get('/check-helper-2/:param', (req, res) => {
|
||||
const ret = check_helper(req, res)
|
||||
if (ret) {
|
||||
res.send(ret)
|
||||
}
|
||||
})
|
||||
app.get('/error', async (req, res, next) => {
|
||||
try {
|
||||
throw 'my error'
|
||||
@@ -14,6 +35,12 @@ app.get('/error', async (req, res, next) => {
|
||||
next(error);
|
||||
}
|
||||
})
|
||||
app.get('/query', (req, res) => {
|
||||
res.send(`aa: ${req.query.aa} bb: ${req.query.bb}`)
|
||||
})
|
||||
app.get('/splat/:splat(*)', (req, res) => {
|
||||
res.send('splat ' + req.params.splat)
|
||||
})
|
||||
const server = app.listen(3000, () => {
|
||||
console.log(`listening: http://localhost:${server.address().port}`)
|
||||
|
||||
@@ -28,11 +55,10 @@ const server = app.listen(3000, () => {
|
||||
method: method,
|
||||
}
|
||||
http.request(options, res => {
|
||||
console.error(res.statusCode);
|
||||
assert(res.statusCode === status);
|
||||
assert.strictEqual(res.statusCode, status);
|
||||
res.on('data', d => {
|
||||
if (body !== undefined) {
|
||||
assert(d.toString() === body);
|
||||
assert.strictEqual(d.toString(), body);
|
||||
}
|
||||
})
|
||||
}).end()
|
||||
@@ -40,6 +66,21 @@ const server = app.listen(3000, () => {
|
||||
test('/', 'GET', 200, 'hello world')
|
||||
test('/', 'POST', 404)
|
||||
test('/dontexist', 'GET', 404)
|
||||
|
||||
// Shows 'my error' on terminal, without stack trace.
|
||||
test('/error', 'GET', 500)
|
||||
|
||||
test('/query?aa=000&bb=111', 'GET', 200, 'aa: 000 bb: 111')
|
||||
|
||||
// https://stackoverflow.com/questions/10020099/express-js-routing-optional-splat-param
|
||||
// https://stackoverflow.com/questions/16829803/express-js-route-parameter-with-slashes
|
||||
// https://stackoverflow.com/questions/34571784/how-to-use-parameters-containing-a-slash-character
|
||||
test('/splat/aaa', 'GET', 200, 'splat aaa')
|
||||
test('/splat/aaa/bbb', 'GET', 200, 'splat aaa/bbb')
|
||||
test('/splat/aaa/bbb/ccc', 'GET', 200, 'splat aaa/bbb/ccc')
|
||||
|
||||
test('/check-helper-1/aa', 'GET', 200, 'aaok')
|
||||
test('/check-helper-2/bb', 'GET', 200, 'bbok')
|
||||
test('/check-helper-1/ccc', 'GET', 404, 'ko')
|
||||
test('/check-helper-2/ddd', 'GET', 404, 'ko')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user