-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtester.js
55 lines (45 loc) · 1.06 KB
/
tester.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
'use strict'
const BASEURL = 'http://127.0.0.1:3000'
const request = require('request')
const apiCall = async (options) => new Promise(function(resolve, reject) {
request(options, function(err, res, body) {
if (err) {reject(err)}
else if (res.statusCode !== 200) {reject(body)}
else {resolve(body)}
})
});
async function apiGet(key) {
const options = {
url: `${BASEURL}/cache/${key}`,
method: 'GET'
}
return apiCall(options)
}
async function apiPut(key, data) {
const options = {
url: `${BASEURL}/cache/${key}`,
method: 'PUT',
body: data,
headers: {
'Content-Type': 'application/octet-stream',
'Content-Length': data.length
}
}
return apiCall(options)
}
async function testGetSet() {
const testkey = 'testkey'
const testval = 'testvalue'
await apiPut(testkey, testval)
try {
const rv = await apiGet(testkey)
console.log('RETURNVAL:')
console.log(rv)
} catch (err) {
console.error('ERRFAIL:')
console.error(err)
}
}
(async function() {
await testGetSet()
})()