td 0.13.2 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,7 +51,7 @@ module TreasureData::Command
51
51
 
52
52
  before do
53
53
  client = double(:client, bulk_imports: response)
54
- command.stub(:get_client).and_return(client)
54
+ allow(command).to receive(:get_client).and_return(client)
55
55
 
56
56
  command.import_list(option)
57
57
  end
@@ -86,7 +86,7 @@ module TreasureData::Command
86
86
 
87
87
  before do
88
88
  client = double(:client, bulk_imports: response)
89
- command.stub(:get_client).and_return(client)
89
+ allow(command).to receive(:get_client).and_return(client)
90
90
 
91
91
  command.import_list(option)
92
92
  end
@@ -104,13 +104,13 @@ module TreasureData::Command
104
104
  let(:client) { double(:client) }
105
105
 
106
106
  before do
107
- command.stub(:get_client).and_return(client)
107
+ allow(command).to receive(:get_client).and_return(client)
108
108
  end
109
109
 
110
110
  context 'not exists import' do
111
111
  it 'should be error' do
112
- client.should_receive(:bulk_import).with(import_name).and_return(nil)
113
- command.should_receive(:exit).with(1).and_return { raise CallSystemExitError }
112
+ expect(client).to receive(:bulk_import).with(import_name).and_return(nil)
113
+ expect(command).to receive(:exit).with(1) { raise CallSystemExitError }
114
114
 
115
115
  expect {
116
116
  command.import_show(option)
@@ -139,8 +139,8 @@ module TreasureData::Command
139
139
  }
140
140
 
141
141
  before do
142
- client.should_receive(:bulk_import).with(import_name).and_return(bulk_import)
143
- client.should_receive(:list_bulk_import_parts).with(import_name).and_return(bulk_import_parts)
142
+ expect(client).to receive(:bulk_import).with(import_name).and_return(bulk_import)
143
+ expect(client).to receive(:list_bulk_import_parts).with(import_name).and_return(bulk_import_parts)
144
144
 
145
145
  command.import_show(option)
146
146
  end
@@ -167,11 +167,11 @@ module TreasureData::Command
167
167
  let(:client) { double(:client) }
168
168
 
169
169
  before do
170
- command.stub(:get_client).and_return(client)
170
+ allow(command).to receive(:get_client).and_return(client)
171
171
  end
172
172
 
173
173
  it 'create bulk import' do
174
- client.should_receive(:create_bulk_import).with(import_name, database, table, {})
174
+ expect(client).to receive(:create_bulk_import).with(import_name, database, table, {})
175
175
 
176
176
  command.import_create(option)
177
177
 
@@ -195,8 +195,8 @@ module TreasureData::Command
195
195
  let(:apikey) { '1234ABCDEFGHIJKLMN' }
196
196
 
197
197
  before do
198
- TreasureData::Config.stub(:endpoint).and_return(endpoint)
199
- TreasureData::Config.stub(:apikey).and_return(apikey)
198
+ allow(TreasureData::Config).to receive(:endpoint).and_return(endpoint)
199
+ allow(TreasureData::Config).to receive(:apikey).and_return(apikey)
200
200
  end
201
201
 
202
202
  context 'unknown format' do
@@ -34,11 +34,11 @@ module TreasureData::Command
34
34
  let(:format) { "json" }
35
35
 
36
36
  it do
37
- FileUtils.should_receive(:mv).with(tempfile, file.path)
37
+ expect(FileUtils).to receive(:mv).with(tempfile, file.path)
38
38
  subject
39
39
  end
40
40
  it do
41
- command.should_receive(:open_file).with(tempfile, "w")
41
+ expect(command).to receive(:open_file).with(tempfile, "w")
42
42
  subject
43
43
  end
44
44
  end
@@ -47,11 +47,11 @@ module TreasureData::Command
47
47
  let(:format) { "csv" }
48
48
 
49
49
  it do
50
- FileUtils.should_receive(:mv).with(tempfile, file.path)
50
+ expect(FileUtils).to receive(:mv).with(tempfile, file.path)
51
51
  subject
52
52
  end
53
53
  it do
54
- command.should_receive(:open_file).with(tempfile, "w")
54
+ expect(command).to receive(:open_file).with(tempfile, "w")
55
55
  subject
56
56
  end
57
57
  end
@@ -60,11 +60,11 @@ module TreasureData::Command
60
60
  let(:format) { "tsv" }
61
61
 
62
62
  it do
63
- FileUtils.should_receive(:mv).with(tempfile, file.path)
63
+ expect(FileUtils).to receive(:mv).with(tempfile, file.path)
64
64
  subject
65
65
  end
66
66
  it do
67
- command.should_receive(:open_file).with(tempfile, "w")
67
+ expect(command).to receive(:open_file).with(tempfile, "w")
68
68
  subject
69
69
  end
70
70
  end
@@ -73,15 +73,15 @@ module TreasureData::Command
73
73
  let(:format) { "msgpack" }
74
74
 
75
75
  before do
76
- job.stub(:result_format) # for msgpack
76
+ allow(job).to receive(:result_format) # for msgpack
77
77
  end
78
78
 
79
79
  it do
80
- FileUtils.should_receive(:mv).with(tempfile, file.path)
80
+ expect(FileUtils).to receive(:mv).with(tempfile, file.path)
81
81
  subject
82
82
  end
83
83
  it do
84
- command.should_receive(:open_file).with(tempfile, "wb")
84
+ expect(command).to receive(:open_file).with(tempfile, "wb")
85
85
  subject
86
86
  end
87
87
  end
@@ -90,15 +90,15 @@ module TreasureData::Command
90
90
  let(:format) { "msgpack.gz" }
91
91
 
92
92
  before do
93
- job.stub(:result_raw) # for msgpack.gz
93
+ allow(job).to receive(:result_raw) # for msgpack.gz
94
94
  end
95
95
 
96
96
  it do
97
- FileUtils.should_receive(:mv).with(tempfile, file.path)
97
+ expect(FileUtils).to receive(:mv).with(tempfile, file.path)
98
98
  subject
99
99
  end
100
100
  it do
101
- command.should_receive(:open_file).with(tempfile, "wb")
101
+ expect(command).to receive(:open_file).with(tempfile, "wb")
102
102
  subject
103
103
  end
104
104
  end
@@ -107,17 +107,17 @@ module TreasureData::Command
107
107
  context 'result without nil' do
108
108
  it 'supports json output' do
109
109
  command.send(:show_result, job, file, nil, 'json')
110
- File.read(file.path).should == %Q([["1",2.0,{"key":3}],\n["4",5.0,{"key":6}],\n["7",8.0,{"key":9}]])
110
+ expect(File.read(file.path)).to eq(%Q([["1",2.0,{"key":3}],\n["4",5.0,{"key":6}],\n["7",8.0,{"key":9}]]))
111
111
  end
112
112
 
113
113
  it 'supports csv output' do
114
114
  command.send(:show_result, job, file, nil, 'csv')
115
- File.read(file.path).should == %Q(1,2.0,"{""key"":3}"\n4,5.0,"{""key"":6}"\n7,8.0,"{""key"":9}"\n)
115
+ expect(File.read(file.path)).to eq(%Q(1,2.0,"{""key"":3}"\n4,5.0,"{""key"":6}"\n7,8.0,"{""key"":9}"\n))
116
116
  end
117
117
 
118
118
  it 'supports tsv output' do
119
119
  command.send(:show_result, job, file, nil, 'tsv')
120
- File.read(file.path).should == %Q(1\t2.0\t{"key":3}\n4\t5.0\t{"key":6}\n7\t8.0\t{"key":9}\n)
120
+ expect(File.read(file.path)).to eq(%Q(1\t2.0\t{"key":3}\n4\t5.0\t{"key":6}\n7\t8.0\t{"key":9}\n))
121
121
  end
122
122
  end
123
123
 
@@ -138,49 +138,49 @@ module TreasureData::Command
138
138
 
139
139
  context 'with --column-header option' do
140
140
  before do
141
- job.stub(:hive_result_schema).and_return([['c0', 'time'], ['c1', 'double'], ['v', nil], ['c3', 'long']])
141
+ allow(job).to receive(:hive_result_schema).and_return([['c0', 'time'], ['c1', 'double'], ['v', nil], ['c3', 'long']])
142
142
  client = Object.new
143
- client.stub(:job).with(job_id).and_return(job)
144
- command.stub(:get_client).and_return(client)
143
+ allow(client).to receive(:job).with(job_id).and_return(job)
144
+ allow(command).to receive(:get_client).and_return(client)
145
145
  end
146
146
 
147
147
  it 'supports json output' do
148
148
  command.send(:show_result, job, file, nil, 'json', { header: true })
149
- File.read(file.path).should == %Q([{"c0":null,"c1":2.0,"v":{"key":3},"c3":null}])
149
+ expect(File.read(file.path)).to eq(%Q([{"c0":null,"c1":2.0,"v":{"key":3},"c3":null}]))
150
150
  end
151
151
 
152
152
  it 'supports csv output' do
153
153
  command.send(:show_result, job, file, nil, 'csv', { header: true })
154
- File.read(file.path).should == %Q(c0,c1,v,c3\nnull,2.0,"{""key"":3}"\n)
154
+ expect(File.read(file.path)).to eq(%Q(c0,c1,v,c3\nnull,2.0,"{""key"":3}"\n))
155
155
  end
156
156
 
157
157
  it 'supports tsv output' do
158
158
  command.send(:show_result, job, file, nil, 'tsv', { header: true })
159
- File.read(file.path).should == %Q(c0\tc1\tv\tc3\nnull\t2.0\t{"key":3}\n)
159
+ expect(File.read(file.path)).to eq(%Q(c0\tc1\tv\tc3\nnull\t2.0\t{"key":3}\n))
160
160
  end
161
161
  end
162
162
 
163
163
  context 'without --null option' do
164
164
  it 'supports json output' do
165
165
  command.send(:show_result, job, file, nil, 'json')
166
- File.read(file.path).should == %Q([[null,2.0,{"key":3}]])
166
+ expect(File.read(file.path)).to eq(%Q([[null,2.0,{"key":3}]]))
167
167
  end
168
168
 
169
169
  it 'supports csv output' do
170
170
  command.send(:show_result, job, file, nil, 'csv')
171
- File.read(file.path).should == %Q(null,2.0,"{""key"":3}"\n)
171
+ expect(File.read(file.path)).to eq(%Q(null,2.0,"{""key"":3}"\n))
172
172
  end
173
173
 
174
174
  it 'supports tsv output' do
175
175
  command.send(:show_result, job, file, nil, 'tsv')
176
- File.read(file.path).should == %Q(null\t2.0\t{"key":3}\n)
176
+ expect(File.read(file.path)).to eq(%Q(null\t2.0\t{"key":3}\n))
177
177
  end
178
178
  end
179
179
 
180
180
  context 'with --null option' do
181
181
  it 'dose not effect json output (nil will be shown as null)' do
182
182
  command.send(:show_result, job, file, nil, 'json', { null_expr: "NULL" })
183
- File.read(file.path).should == %Q([[null,2.0,{"key":3}]])
183
+ expect(File.read(file.path)).to eq(%Q([[null,2.0,{"key":3}]]))
184
184
  end
185
185
 
186
186
  context 'csv format' do
@@ -189,7 +189,7 @@ module TreasureData::Command
189
189
 
190
190
  it 'shows nill as specified string' do
191
191
  command.send(:show_result, job, file, nil, 'csv', { null_expr: null_expr })
192
- File.read(file.path).should == %Q(NULL,2.0,"{""key"":3}"\n)
192
+ expect(File.read(file.path)).to eq(%Q(NULL,2.0,"{""key"":3}"\n))
193
193
  end
194
194
  end
195
195
 
@@ -198,14 +198,14 @@ module TreasureData::Command
198
198
 
199
199
  it 'shows nill as empty string' do
200
200
  command.send(:show_result, job, file, nil, 'csv', { null_expr: null_expr })
201
- File.read(file.path).should == %Q("",2.0,"{""key"":3}"\n)
201
+ expect(File.read(file.path)).to eq(%Q("",2.0,"{""key"":3}"\n))
202
202
  end
203
203
  end
204
204
  end
205
205
 
206
206
  it 'supports tsv output' do
207
207
  command.send(:show_result, job, file, nil, 'tsv', { null_expr: "\"\"" })
208
- File.read(file.path).should == %Q(""\t2.0\t{"key":3}\n)
208
+ expect(File.read(file.path)).to eq(%Q(""\t2.0\t{"key":3}\n))
209
209
  end
210
210
  end
211
211
  end
@@ -214,17 +214,17 @@ module TreasureData::Command
214
214
 
215
215
  it 'supports json output' do
216
216
  command.send(:show_result, job, file, nil, 'json')
217
- File.read(file.path).should == %Q([["1",2.0,{"key":3}],\n["4",5.0,{"key":6}],\n["7",8.0,{"key":9}]])
217
+ expect(File.read(file.path)).to eq(%Q([["1",2.0,{"key":3}],\n["4",5.0,{"key":6}],\n["7",8.0,{"key":9}]]))
218
218
  end
219
219
 
220
220
  it 'supports csv output' do
221
221
  command.send(:show_result, job, file, nil, 'csv')
222
- File.read(file.path).should == %Q(1,2.0,"{""key"":3}"\n4,5.0,"{""key"":6}"\n7,8.0,"{""key"":9}"\n)
222
+ expect(File.read(file.path)).to eq(%Q(1,2.0,"{""key"":3}"\n4,5.0,"{""key"":6}"\n7,8.0,"{""key"":9}"\n))
223
223
  end
224
224
 
225
225
  it 'supports tsv output' do
226
226
  command.send(:show_result, job, file, nil, 'tsv')
227
- File.read(file.path).should == %Q(1\t2.0\t{"key":3}\n4\t5.0\t{"key":6}\n7\t8.0\t{"key":9}\n)
227
+ expect(File.read(file.path)).to eq(%Q(1\t2.0\t{"key":3}\n4\t5.0\t{"key":6}\n7\t8.0\t{"key":9}\n))
228
228
  end
229
229
  end
230
230
 
@@ -251,7 +251,7 @@ module TreasureData::Command
251
251
 
252
252
  it 'supports csv output' do
253
253
  command.send(:show_result, job, file, nil, 'csv')
254
- File.read(file.path).should == <<text
254
+ expect(File.read(file.path)).to eq <<text
255
255
  """NaN""","""Infinity""","""-Infinity"""
256
256
  "[""NaN"",""Infinity"",""-Infinity""]",5.0,"{""key"":6}"
257
257
  7,8.0,"{""key"":9}"
@@ -260,7 +260,7 @@ text
260
260
 
261
261
  it 'supports tsv output' do
262
262
  command.send(:show_result, job, file, nil, 'tsv')
263
- File.read(file.path).should == <<text
263
+ expect(File.read(file.path)).to eq <<text
264
264
  "NaN"\t"Infinity"\t"-Infinity"
265
265
  ["NaN","Infinity","-Infinity"]\t5.0\t{"key":6}
266
266
  7\t8.0\t{"key":9}
@@ -301,16 +301,16 @@ text
301
301
  end
302
302
 
303
303
  before do
304
- job.stub(:finished?).and_return(true)
304
+ allow(job).to receive(:finished?).and_return(true)
305
305
 
306
306
  client = Object.new
307
- client.stub(:job).with(job_id).and_return(job)
308
- command.stub(:get_client).and_return(client)
307
+ allow(client).to receive(:job).with(job_id).and_return(job)
308
+ allow(command).to receive(:get_client).and_return(client)
309
309
  end
310
310
 
311
311
  context 'without --null option' do
312
312
  it 'calls #show_result without null_expr option' do
313
- command.stub(:show_result).with(job, nil, nil, nil, {:header=>false})
313
+ allow(command).to receive(:show_result).with(job, nil, nil, nil, {:header=>false})
314
314
  op = List::CommandParser.new("job:show", %w[job_id], %w[], nil, ["12345"], true)
315
315
  command.job_show(op)
316
316
  end
@@ -318,13 +318,13 @@ text
318
318
 
319
319
  context 'with --null option' do
320
320
  it 'calls #show_result with null_expr option' do
321
- command.stub(:show_result).with(job, nil, nil, nil, {:header=>false, :null_expr=>"NULL"} )
321
+ allow(command).to receive(:show_result).with(job, nil, nil, nil, {:header=>false, :null_expr=>"NULL"} )
322
322
  op = List::CommandParser.new("job:show", %w[job_id], %w[], nil, ["12345", "--null", "NULL"], true)
323
323
  command.job_show(op)
324
324
  end
325
325
 
326
326
  it 'calls #show_result with null_expr option' do
327
- command.stub(:show_result).with(job, nil, nil, nil, {:header=>false, :null_expr=>'""'} )
327
+ allow(command).to receive(:show_result).with(job, nil, nil, nil, {:header=>false, :null_expr=>'""'} )
328
328
  op = List::CommandParser.new("job:show", %w[job_id], %w[], nil, ["12345", "--null", '""'], true)
329
329
  command.job_show(op)
330
330
  end
@@ -388,8 +388,8 @@ text
388
388
 
389
389
  before do
390
390
  client = Object.new
391
- client.stub(:jobs).and_return(jobs)
392
- command.stub(:get_client).and_return(client)
391
+ allow(client).to receive(:jobs).and_return(jobs)
392
+ allow(command).to receive(:get_client).and_return(client)
393
393
  end
394
394
 
395
395
  it 'should display all job list' do
@@ -437,31 +437,31 @@ ACTUAL
437
437
 
438
438
  it 'assumes test setting is correct' do
439
439
  # the String is actually in Windows-31J but encoding is UTF-8 msgpack-ruby reports
440
- multibyte_string.encoding.should == Encoding::UTF_8
441
- multibyte_string.force_encoding('Windows-31J').encode('UTF-8').should == 'メール'
440
+ expect(multibyte_string.encoding).to eq(Encoding::UTF_8)
441
+ expect(multibyte_string.force_encoding('Windows-31J').encode('UTF-8')).to eq('メール')
442
442
  end
443
443
 
444
444
  it 'supports json output' do
445
445
  row = multibyte_row
446
446
  file = Tempfile.new("job_spec").tap {|s| s.close }
447
447
  command.send(:show_result, job, file, nil, 'json')
448
- File.read(file.path, encoding: 'UTF-8').should == '[' + [row, row].map { |e| Yajl.dump(e) }.join(",\n") + ']'
448
+ expect(File.read(file.path, encoding: 'UTF-8')).to eq('[' + [row, row].map { |e| Yajl.dump(e) }.join(",\n") + ']')
449
449
  end
450
450
 
451
451
  it 'supports csv output' do
452
452
  row = multibyte_row.map { |e| dump_column(e) }
453
453
  file = Tempfile.new("job_spec").tap {|s| s.close }
454
454
  command.send(:show_result, job, file, nil, 'csv')
455
- File.binread(file.path).should == [row, row].map { |e| CSV.generate_line(e, :row_sep => line_separator) }.join
456
- File.open(file.path, 'r:Windows-31J').read.encode('UTF-8').split.first.should == 'メール,2.0,"{""メール"":""メール""}"'
455
+ expect(File.binread(file.path)).to eq([row, row].map { |e| CSV.generate_line(e, :row_sep => line_separator) }.join)
456
+ expect(File.open(file.path, 'r:Windows-31J').read.encode('UTF-8').split.first).to eq('メール,2.0,"{""メール"":""メール""}"')
457
457
  end
458
458
 
459
459
  it 'supports tsv output' do
460
460
  row = multibyte_row.map { |e| dump_column(e) }
461
461
  file = Tempfile.new("job_spec").tap {|s| s.close }
462
462
  command.send(:show_result, job, file, nil, 'tsv')
463
- File.binread(file.path).should == [row, row].map { |e| e.join("\t") + line_separator }.join
464
- File.open(file.path, 'r:Windows-31J').read.encode('UTF-8').split("\n").first.should == "メール\t2.0\t{\"メール\":\"メール\"}"
463
+ expect(File.binread(file.path)).to eq([row, row].map { |e| e.join("\t") + line_separator }.join)
464
+ expect(File.open(file.path, 'r:Windows-31J').read.encode('UTF-8').split("\n").first).to eq("メール\t2.0\t{\"メール\":\"メール\"}")
465
465
  end
466
466
  end
467
467
 
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'td/command/common'
5
+ require 'td/command/list'
6
+ require 'td/command/query'
7
+ require 'td/client'
8
+ require 'tempfile'
9
+
10
+ module TreasureData::Command
11
+ describe 'query commands' do
12
+ let :client do
13
+ double('client')
14
+ end
15
+ let :job do
16
+ double('job', job_id: 123)
17
+ end
18
+ let :command do
19
+ Class.new { include TreasureData::Command }.new
20
+ end
21
+ before do
22
+ allow(command).to receive(:get_client).and_return(client)
23
+ expect(client).to receive(:database).with('sample_datasets')
24
+ end
25
+
26
+ it 'accepts --domain-key' do
27
+ expect(client).to receive(:query).
28
+ with("sample_datasets", "SELECT 1;", nil, nil, nil, {"domain_key"=>"hoge"}).
29
+ and_return(job)
30
+ op = List::CommandParser.new("query", %w[query], %w[], nil, ['--domain-key=hoge', '-dsample_datasets', 'SELECT 1;'], false)
31
+ command.query(op)
32
+ end
33
+
34
+ it 'raises error if --domain-key is duplicated' do
35
+ expect(client).to receive(:query).
36
+ with("sample_datasets", "SELECT 1;", nil, nil, nil, {"domain_key"=>"hoge"}).
37
+ and_raise(::TreasureData::AlreadyExistsError.new('Query failed: domain_key has already been taken'))
38
+ op = List::CommandParser.new("query", %w[query], %w[], nil, ['--domain-key=hoge', '-dsample_datasets', 'SELECT 1;'], false)
39
+ expect{ command.query(op) }.to raise_error(TreasureData::AlreadyExistsError)
40
+ end
41
+ end
42
+ end
@@ -23,13 +23,13 @@ module TreasureData::Command
23
23
  let(:op) { List::CommandParser.new('sched:last_job', %w[], %w[], false, argv, []) }
24
24
 
25
25
  before do
26
- client.stub(:schedules).and_return(schedules)
27
- command.stub(:get_client).and_return(client)
26
+ allow(client).to receive(:schedules).and_return(schedules)
27
+ allow(command).to receive(:get_client).and_return(client)
28
28
  end
29
29
 
30
30
  describe 'sched_history' do
31
31
  before do
32
- client.stub(:history).and_return(history)
32
+ allow(client).to receive(:history).and_return(history)
33
33
  end
34
34
 
35
35
  let(:history) { [job1, job2] }
@@ -45,12 +45,12 @@ module TreasureData::Command
45
45
  subject { command.sched_result(op) }
46
46
 
47
47
  before do
48
- command.stub(:get_history).with(client, nil, (back_number - 1), back_number).and_return(history)
48
+ allow(command).to receive(:get_history).with(client, nil, (back_number - 1), back_number).and_return(history)
49
49
  end
50
50
 
51
51
  shared_examples_for("passing argv and job_id to job:show") do
52
52
  it "invoke 'job:show [original argv] [job id]'" do
53
- TreasureData::Command::Runner.any_instance.should_receive(:run).with(["job:show", *show_arg, job_id])
53
+ expect_any_instance_of(TreasureData::Command::Runner).to receive(:run).with(["job:show", *show_arg, job_id])
54
54
  subject
55
55
  end
56
56
  end
@@ -135,7 +135,7 @@ module TreasureData::Command
135
135
  context "history dose not exists" do
136
136
  let(:back_number) { 1 }
137
137
  let(:history) { [] }
138
- before { client.stub(:history) { raise TreasureData::NotFoundError } }
138
+ before { allow(client).to receive(:history) { raise TreasureData::NotFoundError } }
139
139
 
140
140
  it "exit with 1" do
141
141
  begin