-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.js
60 lines (51 loc) · 1.56 KB
/
test.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
'use strict';
const test = require('tape');
const nock = require('nock');
const BbPromise = require('bluebird');
const FaaS = require('./faas');
test('Test typeofs', t => {
t.plan(6);
t.equals(typeof FaaS, 'function');
const faas = FaaS('http://localhost:8080');
t.equals(typeof faas, 'object');
t.equals(typeof faas.deploy, 'function');
t.equals(typeof faas.invoke, 'function');
t.equals(typeof faas.compose, 'function');
t.equals(typeof faas.remove, 'function');
});
test('Test full API', t => {
nock('http://localhost:8080')
.post('/system/functions', {
service: 'test-func',
network: 'func_functions',
image: 'hello-serverless'
}).reply(200)
.post('/function/test-func').reply(200, {status: 'done'})
.post('/function/func_nodeinfo').reply(200, 'hello cruel world')
.post('/function/func_echoit', 'hello cruel world').reply(200, 'hello cruel world')
.post('/function/func_wordcount', 'hello cruel world').reply(200, 3)
.delete('/system/functions', {functionName: 'test-func'}).reply(200);
t.plan(5);
const faas = FaaS('http://localhost:8080');
faas.deploy(
'test-func',
'func_functions',
'hello-serverless'
)
.then(x => t.equals(x.statusCode, 200))
.then(() => faas.invoke('test-func',null, true))
.then(x => t.same(x.body, {status: 'done'}))
.then(() => faas.compose('', [
'func_nodeinfo',
'func_echoit',
'func_wordcount'
]
))
.then(x => {
t.equals(x.statusCode, 200)
t.equals(x.body, '3')
})
.then(() => faas.remove('test-func'))
.then(x => t.equals(x.statusCode, 200))
.catch(err => console.log(err));
});