-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
62 lines (57 loc) · 1.58 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
61
62
var app = require('./app.js');
var request = require('request');
var Docker = require('dockerode');
var docker = new Docker();
app.listen(8889, () => {
console.log("app is running ..");
test1();
})
function test1() {
console.log('Running test1 ...');
request({
uri: 'http://localhost:8889/listeners',
method: 'POST',
json: {
hook_url: 'http://localhost:8889/hook_tester/container+start',
hook_name: 'test1_start',
hook_method: 'POST',
app_name: 'com.example.com',
filters: {
type: ['container'],
event: ['start']
}
}
});
request({
uri: 'http://localhost:8889/listeners',
method: 'POST',
json: {
hook_url: 'http://localhost:8889/hook_tester/container+die',
hook_name: 'test1_stop',
hook_method: 'POST',
app_name: 'com.example.com',
filters: {
type: ['container'],
event: ['die']
}
}
});
app.all('/hook_tester/:id', (req, res) => {
if (req.params.id == req.body.Type + '+' + req.body.Action) {
console.log(`=> Test1#${req.params.id}: success`);
} else {
console.log(`=> Test1#${req.params.id}: Fail`);
}
});
console.log('running busybox as a sample container');
docker.run('busybox', ['sh', '-c', 'uname -a'], process.stdout, function(err, data, container) {
if (err) console.log(err);
console.log(`status_code: ${data.StatusCode}`);
console.log('removing container...');
container.remove({}, (err, data) => {
if (err) console.log(err);
console.log('removed.');
process.exit(0);
});
});
}