forked from Azure/autorest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
int.js
94 lines (88 loc) · 3.87 KB
/
int.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var express = require('express');
var router = express.Router();
var util = require('util');
var utils = require('../util/utils')
var integer = function(coverage) {
router.put('/max/:bits', function(req, res, next) {
var bits = parseInt(req.params.bits, 10);
if (bits === 32) {
if (parseInt(req.body, 10) !== Math.pow(2, bits - 1) - 1) {
utils.send400(res, next, "Did not like the value provided for max signed 32 bit in the req " + util.inspect(req.body));
} else {
coverage['putIntegerMax']++;
res.status(200).end();
}
} else if (bits === 64) {
if (req.body === 9223372036854776000) {
coverage['putLongMax']++;
res.status(200).end();
} else {
utils.send400(res, next, "Did not like the value provided for max signed 64 bit in the req " + util.inspect(req.body));
}
} else {
utils.send400(res, next, "Please use either 64 or 32 bits in the req " + util.inspect(req.body));
}
});
router.put('/min/:bits', function(req, res, next) {
var bits = parseInt(req.params.bits, 10);
if (bits === 32) {
if (parseInt(req.body, 10) !== -Math.pow(2, bits - 1)) {
utils.send400(res, next, "Did not like the value provided for min signed 32 bit in the req " + util.inspect(req.body));
} else {
coverage['putIntegerMin']++;
res.status(200).end();
}
} else if (bits === 64) {
if (req.body === -9223372036854776000) {
coverage['putLongMin']++;
res.status(200).end();
} else {
utils.send400(res, next, "Did not like the value provided for min signed 64 bit in the req " + util.inspect(req.body));
}
} else {
utils.send400(res, next, "Please use either 64 or 32 bits in the req " + util.inspect(req.body));
}
});
router.get('/:scenario', function(req, res, next) {
if (req.params.scenario === 'null') {
coverage['getIntegerNull']++;
res.status(200).end();
} else if (req.params.scenario === 'invalid') {
coverage['getIntegerInvalid']++;
res.status(200).end('123jkl');
} else if (req.params.scenario === 'overflowint32') {
coverage['getIntegerOverflow']++;
res.status(200).end('2147483656');
} else if (req.params.scenario === 'underflowint32') {
coverage['getIntegerUnderflow']++;
res.status(200).end('-2147483656');
} else if (req.params.scenario === 'overflowint64') {
coverage['getLongOverflow']++;
res.status(200).end('9223372036854775910');
} else if (req.params.scenario === 'underflowint64') {
coverage['getLongUnderflow']++;
res.status(200).end('-9223372036854775910');
} else if (req.params.scenario === 'unixtime') {
coverage['getUnixTime']++;
res.status(200).end('1460505600');
} else if (req.params.scenario === 'invalidunixtime') {
coverage['getInvalidUnixTime']++;
res.status(200).end('123jkl');
} else if (req.params.scenario === 'nullunixtime') {
coverage['getNullUnixTime']++;
res.status(200).end();
} else {
res.status(400).send('Request path must contain true or false');
}
});
router.put('/unixtime', function(req, res, next) {
if (req.body != 1460505600) {
utils.send400(res, next, "Did not like the value provided for unixtime in the req " + util.inspect(req.body));
} else {
coverage['putUnixTime']++;
res.status(200).end();
}
});
}
integer.prototype.router = router;
module.exports = integer;