1 | streams = require './streams'
|
2 |
|
3 | describe 'export', ->
|
4 |
|
5 | es = stdin = stdout = stderr = cmd = null
|
6 |
|
7 | beforeEach ->
|
8 | decache './trans.js'
|
9 | {es} = require('./mock-all')()
|
10 | stdin = streams.empty()
|
11 | stdout = streams.output()
|
12 | stderr = streams.output()
|
13 | cmd = require('../src/cmd')(stdin, stdout, stderr)
|
14 |
|
15 | afterEach ->
|
16 | mock.stopAll()
|
17 |
|
18 | describe 'with -t ./trans.js', ->
|
19 |
|
20 | describe 'with bad file', ->
|
21 |
|
22 | it 'reports error', ->
|
23 | cmd ['export', '-t', './test/xxx.json', 'http://localhost:9200/myindex']
|
24 | assert.deepEqual streams.string(stderr)
|
25 | , 'File not found: /Users/martin/dev/ductile/test/xxx.json\n'
|
26 |
|
27 | describe 'with good file', ->
|
28 |
|
29 | it 'exports transformed bulk', ->
|
30 | cmd ['export', '-t', './test/trans.js', 'http://localhost:9200/myindex']
|
31 | streams.promise(stdout)
|
32 | .then (bulk) ->
|
33 | cmp = ([
|
34 | {"index":{"_index":"panda index","_type":"panda type","_id":"panda id"}},
|
35 | Object.assign es.docs()[0], {panda:"TRUE PANDA"}
|
36 | ]).map (r) -> JSON.stringify(r)
|
37 | .join('\n') + '\n'
|
38 | assert.deepEqual bulk, cmp
|
39 | .then ->
|
40 | assert.deepEqual streams.string(stderr),
|
41 | 'Exported 10/42\nExported 20/42\nExported 30/42\n' +
|
42 | 'Exported 40/42\nExported 42/42\n'
|