UNPKG

2.63 kBtext/coffeescriptView Raw
1streams = require './streams'
2
3describe 'export', ->
4
5 es = stdin = stdout = stderr = cmd = null
6
7 beforeEach ->
8 {es} = require('./mock-all')()
9 stdin = streams.empty()
10 stdout = streams.output()
11 stderr = streams.output()
12 cmd = require('../src/cmd')(stdin, stdout, stderr)
13
14 afterEach ->
15 mock.stopAll()
16
17 describe 'with no options', ->
18 it 'exports to bulk', ->
19 cmd ['export', 'http://localhost:9200/myindex']
20 streams.promise(stdout)
21 .then (bulk) ->
22 cmp = ([].concat.apply [], es.docs().map (d) ->
23 [{index:{_index:'myindex', _type:'mytype', _id:d.uid}}, d]
24 ).map (r) -> JSON.stringify(r)
25 .join('\n') + '\n'
26 assert.deepEqual bulk, cmp
27 .then ->
28 assert.deepEqual streams.string(stderr),
29 'Exported 10/42\nExported 20/42\nExported 30/42\nExported 40/42\nExported 42/42\n'
30
31 describe 'without index/type in the url', ->
32 it 'exports to bulk without index/type', ->
33 cmd ['export', 'http://localhost:9200']
34 streams.promise(stdout).then ->
35 assert.deepEqual es().search.args[0][0],
36 body:query:match_all:{}
37 scroll: '60s'
38 size: 200
39
40 describe 'with index in the url', ->
41 it 'exports to bulk with index', ->
42 cmd ['export', 'http://localhost:9200/panda']
43 streams.promise(stdout).then ->
44 assert.deepEqual es().search.args[0][0],
45 body:query:match_all:{}
46 index: 'panda'
47 scroll: '60s'
48 size: 200
49
50 describe 'with index/type in the url', ->
51 it 'exports to bulk with index/type', ->
52 cmd ['export', 'http://localhost:9200/panda/cub']
53 streams.promise(stdout).then ->
54 assert.deepEqual es().search.args[0][0],
55 body:query:match_all:{}
56 index: 'panda'
57 type: 'cub'
58 scroll: '60s'
59 size: 200
60
61 describe 'with a q= in the url', ->
62 it 'includes q field in the body', ->
63 cmd ['export', 'http://localhost:9200/panda/cub?q=published:true']
64 streams.promise(stdout).then ->
65 assert.deepEqual es().search.args[0][0],
66 q: 'published:true'
67 index: 'panda'
68 type: 'cub'
69 scroll: '60s'
70 size: 200