td 0.11.9 → 0.11.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,8 @@
1
+ require 'td/command/options'
2
+
1
3
  module TreasureData
2
4
  module Command
5
+ include Options
3
6
 
4
7
  def sched_list(op)
5
8
  require 'td/command/job' # job_priority_name_of
@@ -20,7 +23,7 @@ module Command
20
23
  map[:Name]
21
24
  }
22
25
 
23
- puts cmd_render_table(rows, :fields => [:Name, :Cron, :Timezone, :"Next schedule", :Delay, :Priority, :Result, :Database, :Query], :max_width=>500, :render_format => op.render_format)
26
+ $stdout.puts cmd_render_table(rows, :fields => [:Name, :Cron, :Timezone, :"Next schedule", :Delay, :Priority, :Result, :Database, :Query], :max_width=>500, :render_format => op.render_format)
24
27
  end
25
28
 
26
29
  def sched_create(op)
@@ -218,9 +221,9 @@ module Command
218
221
  end
219
222
 
220
223
  if newname && curname != newname
221
- puts "Schedule '#{curname}' is updated and its name changed to '#{newname}'."
224
+ $stdout.puts "Schedule '#{curname}' is updated and its name changed to '#{newname}'."
222
225
  else
223
- puts "Schedule '#{curname}' is updated."
226
+ $stdout.puts "Schedule '#{curname}' is updated."
224
227
  end
225
228
  end
226
229
 
@@ -259,16 +262,16 @@ module Command
259
262
 
260
263
  scheds = client.schedules
261
264
  if s = scheds.find {|s| s.name == name }
262
- puts "Name : #{s.name}"
263
- puts "Cron : #{s.cron}"
264
- puts "Timezone : #{s.timezone}"
265
- puts "Delay : #{s.delay} sec"
266
- puts "Next : #{s.next_time}"
267
- puts "Result : #{s.result_url}"
268
- puts "Priority : #{job_priority_name_of(s.priority)}"
269
- puts "Retry limit : #{s.retry_limit}"
270
- puts "Database : #{s.database}"
271
- puts "Query : #{s.query}"
265
+ $stdout.puts "Name : #{s.name}"
266
+ $stdout.puts "Cron : #{s.cron}"
267
+ $stdout.puts "Timezone : #{s.timezone}"
268
+ $stdout.puts "Delay : #{s.delay} sec"
269
+ $stdout.puts "Next : #{s.next_time}"
270
+ $stdout.puts "Result : #{s.result_url}"
271
+ $stdout.puts "Priority : #{job_priority_name_of(s.priority)}"
272
+ $stdout.puts "Retry limit : #{s.retry_limit}"
273
+ $stdout.puts "Database : #{s.database}"
274
+ $stdout.puts "Query : #{s.query}"
272
275
  end
273
276
 
274
277
  rows = []
@@ -277,7 +280,7 @@ module Command
277
280
  rows << {:Time => scheduled_at, :JobID => j.job_id, :Status => j.status, :Priority => job_priority_name_of(j.priority), :Result=>j.result_url}
278
281
  }
279
282
 
280
- puts cmd_render_table(rows, :fields => [:JobID, :Time, :Status, :Priority, :Result], :render_format => op.render_format)
283
+ $stdout.puts cmd_render_table(rows, :fields => [:JobID, :Time, :Status, :Priority, :Result], :render_format => op.render_format)
281
284
  end
282
285
 
283
286
  def sched_run(op)
@@ -320,7 +323,86 @@ module Command
320
323
  }
321
324
 
322
325
  $stderr.puts "Scheduled #{num} jobs from #{t}."
323
- puts cmd_render_table(rows, :fields => [:JobID, :Time], :max_width=>500, :render_format => op.render_format)
326
+ $stdout.puts cmd_render_table(rows, :fields => [:JobID, :Time], :max_width=>500, :render_format => op.render_format)
327
+ end
328
+
329
+ def sched_result(op)
330
+ options = job_show_options(op)
331
+ back_number = 1
332
+ op.on('--last [Number]', Integer, "show the result before N from the last. default: 1") do |n|
333
+ back_number = n ? n : 1
334
+ end
335
+
336
+ # save argv before calling cmd_parse, which removes flags from the argv array
337
+ argv_saved = op.argv.dup
338
+ name = op.cmd_parse
339
+
340
+ verbose = options[:verbose]
341
+ wait = options[:wait]
342
+ output = options[:output]
343
+ format = options[:format]
344
+ render_opts = options[:render_opts]
345
+ limit = options[:limit]
346
+ exclude = options[:exclude]
347
+
348
+ client = get_client
349
+ history = get_history(client, name, (back_number - 1), back_number)
350
+
351
+ job = history.first
352
+
353
+ if job.nil?
354
+ $stderr.puts "No jobs available for this query. Refer to 'sched:history'."
355
+ exit 1
356
+ end
357
+
358
+ # build the job:show command now
359
+ argv = job_show_option_argv(argv_saved, name, back_number)
360
+ argv << job.job_id
361
+
362
+ Runner.new.run(argv)
363
+ end
364
+
365
+ def job_show_option_argv(argv_saved, name, back_number)
366
+ argv = ['job:show']
367
+ argv += (argv_saved - [name]) if argv_saved.length > 0
368
+
369
+ # there are three argvs parters for sched_result.
370
+ # 1. without --last
371
+ # 2. --last (without Num)
372
+ # 3. --last Num
373
+ # 'back_number' is value of Num which was parsed by OptionParser.
374
+ # remove both "--last" and Num if they are.
375
+
376
+ index_of_last = argv.index("--last")
377
+
378
+ return argv unless index_of_last
379
+
380
+ index_of_next_of_last = index_of_last + 1
381
+
382
+ # the arg value following to "--last"
383
+ next_of_last = argv[index_of_next_of_last]
384
+
385
+ indexes_of_options_for_sched_result = [index_of_last]
386
+ indexes_of_options_for_sched_result << index_of_next_of_last if next_of_last == back_number.to_s
387
+
388
+ indexes_of_options_for_sched_result.each do |index|
389
+ argv[index] = nil
390
+ end
391
+
392
+ argv.compact
393
+ end
394
+
395
+ def get_history(client, name, from, to)
396
+ begin
397
+ history = client.history(name, from, to)
398
+ rescue NotFoundError
399
+ cmd_debug_error $!
400
+ $stderr.puts "Schedule '#{name}' does not exist."
401
+ $stderr.puts "Use '#{$prog} " + Config.cl_options_string + "sched:list' to show list of the schedules."
402
+ exit 1
403
+ end
404
+
405
+ history
324
406
  end
325
407
 
326
408
  end # module Command
@@ -8,11 +8,11 @@ module Command
8
8
  client = get_client
9
9
  table = get_table(client, db_name, table_name)
10
10
 
11
- puts "#{db_name}.#{table_name} ("
11
+ $stdout.puts "#{db_name}.#{table_name} ("
12
12
  table.schema.fields.each {|f|
13
- puts " #{f.name}:#{f.type}"
13
+ $stdout.puts " #{f.name}:#{f.type}"
14
14
  }
15
- puts ")"
15
+ $stdout.puts ")"
16
16
  end
17
17
 
18
18
  def schema_set(op)
@@ -6,7 +6,7 @@ module Command
6
6
  def server_status(op)
7
7
  op.cmd_parse
8
8
 
9
- puts Client.server_status
9
+ $stdout.puts Client.server_status
10
10
  end
11
11
 
12
12
  def server_endpoint(op)
@@ -57,9 +57,9 @@ module Command
57
57
  x4, y4 = status_render(x3+2, y3, "[Results]", results, :fields => [:Name, :URL])
58
58
 
59
59
  (y3-y4-1).times do
60
- print "\eD"
60
+ $stdout.print "\eD"
61
61
  end
62
- print "\eE"
62
+ $stdout.print "\eE"
63
63
  end
64
64
 
65
65
  private
@@ -69,13 +69,13 @@ module Command
69
69
  lines.unshift(msg)
70
70
  #lines.unshift("")
71
71
 
72
- print "\e[#{movey}A" if movey > 0
72
+ $stdout.print "\e[#{movey}A" if movey > 0
73
73
 
74
74
  max_width = 0
75
75
  height = 0
76
76
  lines.each {|line|
77
- print "\e[#{movex}C" if movex > 0
78
- puts line
77
+ $stdout.print "\e[#{movex}C" if movex > 0
78
+ $stdout.puts line
79
79
  width = line.length
80
80
  max_width = width if max_width < width
81
81
  height += 1
@@ -191,7 +191,7 @@ module Command
191
191
  else
192
192
  fields = [:Database, :Table, :Type, :Count, :Size, 'Last import', 'Last log timestamp', :Schema]
193
193
  end
194
- puts cmd_render_table(rows, :fields => fields, :max_width => 500, :render_format => op.render_format)
194
+ $stdout.puts cmd_render_table(rows, :fields => fields, :max_width => 500, :render_format => op.render_format)
195
195
 
196
196
  if rows.empty?
197
197
  if db_name
@@ -231,16 +231,16 @@ module Command
231
231
 
232
232
  table = get_table(client, db_name, table_name)
233
233
 
234
- puts "Name : #{table.db_name}.#{table.name}"
235
- puts "Type : #{table.type}"
236
- puts "Count : #{table.count}"
237
- # p table.methods.each {|m| puts m}
238
- puts "Primary key : #{table.primary_key}:#{table.primary_key_type}" if table.type == :item
239
- puts "Schema : ("
234
+ $stdout.puts "Name : #{table.db_name}.#{table.name}"
235
+ $stdout.puts "Type : #{table.type}"
236
+ $stdout.puts "Count : #{table.count}"
237
+ # p table.methods.each {|m| $stdout.puts m}
238
+ $stdout.puts "Primary key : #{table.primary_key}:#{table.primary_key_type}" if table.type == :item
239
+ $stdout.puts "Schema : ("
240
240
  table.schema.fields.each {|f|
241
- puts " #{f.name}:#{f.type}"
241
+ $stdout.puts " #{f.name}:#{f.type}"
242
242
  }
243
- puts ")"
243
+ $stdout.puts ")"
244
244
  end
245
245
 
246
246
  def table_tail(op)
@@ -288,11 +288,11 @@ module Command
288
288
  :space => ' '
289
289
  }
290
290
  rows.each {|row|
291
- puts row.to_json(opts)
291
+ $stdout.puts row.to_json(opts)
292
292
  }
293
293
  else
294
294
  rows.each {|row|
295
- puts row.to_json
295
+ $stdout.puts row.to_json
296
296
  }
297
297
  end
298
298
  end
@@ -301,6 +301,7 @@ module Command
301
301
  from = nil
302
302
  to = nil
303
303
  wait = false
304
+ pool_name = nil
304
305
 
305
306
  op.on('-t', '--to TIME', 'end time of logs to delete in Unix time multiple of 3600 (1 hour)',
306
307
  ' or Ruby time string format (e.g. \'2014-07-01 14:00:00 JST\') where',
@@ -326,6 +327,9 @@ module Command
326
327
  op.on('-w', '--wait', 'wait for the job to finish', TrueClass) {|b|
327
328
  wait = b
328
329
  }
330
+ op.on('-O', '--pool-name NAME', 'specify resource pool by name') {|s|
331
+ pool_name = s
332
+ }
329
333
 
330
334
  db_name, table_name = op.cmd_parse
331
335
 
@@ -350,6 +354,7 @@ module Command
350
354
  table = get_table(client, db_name, table_name)
351
355
 
352
356
  opts = {}
357
+ opts['pool_name'] = pool_name if pool_name
353
358
  job = client.partial_delete(db_name, table_name, to, from, opts)
354
359
 
355
360
  $stderr.puts "Partial delete job #{job.job_id} is queued."
@@ -357,7 +362,7 @@ module Command
357
362
 
358
363
  if wait && !job.finished?
359
364
  wait_job(job)
360
- puts "Status : #{job.status}"
365
+ $stdout.puts "Status : #{job.status}"
361
366
  end
362
367
  end
363
368
 
@@ -374,9 +379,9 @@ module Command
374
379
  client.update_expire(db_name, table_name, expire_days)
375
380
 
376
381
  if expire_days == 0
377
- puts "Data expiration disabled for this table."
382
+ $stdout.puts "Data expiration disabled for this table."
378
383
  else
379
- puts "Table set to expire data older than #{expire_days} days."
384
+ $stdout.puts "Table set to expire data older than #{expire_days} days."
380
385
  end
381
386
  end
382
387
 
@@ -488,12 +493,12 @@ module Command
488
493
  begin
489
494
  db = client.database(db_name)
490
495
  rescue ForbiddenError => e
491
- puts "Warning: database and table validation skipped - #{e.message}"
496
+ $stdout.puts "Warning: database and table validation skipped - #{e.message}"
492
497
  else
493
498
  begin
494
499
  table = db.table(table_name)
495
500
  rescue ForbiddenError => e
496
- puts "Warning: table validation skipped - #{e.message}"
501
+ $stdout.puts "Warning: table validation skipped - #{e.message}"
497
502
  end
498
503
  end
499
504
 
@@ -522,12 +527,12 @@ module Command
522
527
  import_log_file(file, path, client, db_name, table_name, parser)
523
528
  }
524
529
 
525
- puts "done."
530
+ $stdout.puts "done."
526
531
  end
527
532
 
528
533
  private
529
534
  def import_log_file(file, path, client, db_name, table_name, parser)
530
- puts "importing #{path}..."
535
+ $stdout.puts "importing #{path}..."
531
536
 
532
537
  out = Tempfile.new('td-import')
533
538
  out.binmode if out.respond_to?(:binmode)
@@ -549,17 +554,17 @@ module Command
549
554
  n += 1
550
555
  x += 1
551
556
  if n % 10000 == 0 # by records imported
552
- puts " imported #{n} entries from #{path}..."
557
+ $stdout.puts " imported #{n} entries from #{path}..."
553
558
 
554
559
  # TODO size
555
560
  elsif out.pos > 1024 * 1024 # by 1 MB chunks
556
- puts " imported #{n} entries from #{path}..."
561
+ $stdout.puts " imported #{n} entries from #{path}..."
557
562
  begin
558
563
  writer.finish
559
564
  size = out.pos
560
565
  out.pos = 0
561
566
 
562
- puts " uploading #{size} bytes..."
567
+ $stdout.puts " uploading #{size} bytes..."
563
568
  client.import(db_name, table_name, "msgpack.gz", out, size)
564
569
 
565
570
  out.truncate(0)
@@ -579,7 +584,7 @@ module Command
579
584
  size = out.pos
580
585
  out.pos = 0
581
586
 
582
- puts " uploading #{size} bytes..."
587
+ $stdout.puts " uploading #{size} bytes..."
583
588
  # TODO upload on background thread
584
589
  client.import(db_name, table_name, "msgpack.gz", out, size)
585
590
  end
@@ -589,7 +594,7 @@ module Command
589
594
  raise ImportError, "no valid record to import from #{path}"
590
595
  end
591
596
 
592
- puts " imported #{n} entries from #{path}."
597
+ $stdout.puts " imported #{n} entries from #{path}."
593
598
  $stderr.puts normalized_message if has_bignum
594
599
  ensure
595
600
  out.close rescue nil
@@ -12,11 +12,11 @@ module Command
12
12
  end
13
13
 
14
14
  start_time = Time.now
15
- puts "Updating 'td' from #{TOOLBELT_VERSION}..."
15
+ $stdout.puts "Updating 'td' from #{TOOLBELT_VERSION}..."
16
16
  if new_version = Updater.update
17
- puts "Successfully updated to #{new_version} in #{Command.humanize_time((Time.now - start_time).to_i)}."
17
+ $stdout.puts "Successfully updated to #{new_version} in #{Command.humanize_time((Time.now - start_time).to_i)}."
18
18
  else
19
- puts "Nothing to update."
19
+ $stdout.puts "Nothing to update."
20
20
  end
21
21
  end
22
22
 
@@ -33,7 +33,7 @@ module Command
33
33
  rows << {:Name => user.name, :Email => user.email}
34
34
  }
35
35
 
36
- puts cmd_render_table(rows, :fields => [:Name, :Email], :render_format => op.render_format)
36
+ $stdout.puts cmd_render_table(rows, :fields => [:Name, :Email], :render_format => op.render_format)
37
37
 
38
38
  if rows.empty?
39
39
  $stderr.puts "There are no users."
@@ -73,13 +73,13 @@ module Command
73
73
  1.times { r << symbol.sort_by{rand}.first }
74
74
  password = r.sort_by{rand}.join
75
75
 
76
- puts "Password: #{password}"
76
+ $stdout.puts "Password: #{password}"
77
77
 
78
78
  else
79
79
  3.times do
80
80
  begin
81
81
  system "stty -echo" # TODO termios
82
- print "Password (typing will be hidden): "
82
+ $stdout.print "Password (typing will be hidden): "
83
83
  password = STDIN.gets || ""
84
84
  password = password[0..-2] # strip \n
85
85
  rescue Interrupt
@@ -87,7 +87,7 @@ module Command
87
87
  exit 1
88
88
  ensure
89
89
  system "stty echo" # TODO termios
90
- print "\n"
90
+ $stdout.print "\n"
91
91
  end
92
92
 
93
93
  if password.empty?
@@ -97,7 +97,7 @@ module Command
97
97
 
98
98
  begin
99
99
  system "stty -echo" # TODO termios
100
- print "Retype password: "
100
+ $stdout.print "Retype password: "
101
101
  password2 = STDIN.gets || ""
102
102
  password2 = password2[0..-2] # strip \n
103
103
  rescue Interrupt
@@ -105,14 +105,14 @@ module Command
105
105
  exit 1
106
106
  ensure
107
107
  system "stty echo" # TODO termios
108
- print "\n"
108
+ $stdout.print "\n"
109
109
  end
110
110
 
111
111
  if password == password2
112
112
  break
113
113
  end
114
114
 
115
- puts "Doesn't match."
115
+ $stdout.puts "Doesn't match."
116
116
  end
117
117
  end
118
118
 
@@ -185,7 +185,7 @@ module Command
185
185
  rows << {:Key => key}
186
186
  }
187
187
 
188
- puts cmd_render_table(rows, :fields => [:Key], :render_format => op.render_format)
188
+ $stdout.puts cmd_render_table(rows, :fields => [:Key], :render_format => op.render_format)
189
189
  end
190
190
 
191
191
  def user_password_change(op)
@@ -196,7 +196,7 @@ module Command
196
196
  3.times do
197
197
  begin
198
198
  system "stty -echo" # TODO termios
199
- print "New password (typing will be hidden): "
199
+ $stdout.print "New password (typing will be hidden): "
200
200
  password = STDIN.gets || ""
201
201
  password = password[0..-2] # strip \n
202
202
  rescue Interrupt
@@ -204,7 +204,7 @@ module Command
204
204
  exit 1
205
205
  ensure
206
206
  system "stty echo" # TODO termios
207
- print "\n"
207
+ $stdout.print "\n"
208
208
  end
209
209
 
210
210
  if password.empty?
@@ -214,7 +214,7 @@ module Command
214
214
 
215
215
  begin
216
216
  system "stty -echo" # TODO termios
217
- print "Retype new password: "
217
+ $stdout.print "Retype new password: "
218
218
  password2 = STDIN.gets || ""
219
219
  password2 = password2[0..-2] # strip \n
220
220
  rescue Interrupt
@@ -222,14 +222,14 @@ module Command
222
222
  exit 1
223
223
  ensure
224
224
  system "stty echo" # TODO termios
225
- print "\n"
225
+ $stdout.print "\n"
226
226
  end
227
227
 
228
228
  if password == password2
229
229
  break
230
230
  end
231
231
 
232
- puts "Doesn't match."
232
+ $stdout.puts "Doesn't match."
233
233
  end
234
234
 
235
235
  client = get_client(:ssl => true)
data/lib/td/helpers.rb CHANGED
@@ -3,12 +3,7 @@ module TreasureData
3
3
  module_function
4
4
 
5
5
  def format_with_delimiter(number, delimiter = ',')
6
- num = number.to_s
7
- if formatted = num.gsub!(/(\d)(?=(?:\d{3})+(?!\d))/, "\\1#{delimiter}")
8
- formatted
9
- else
10
- num
11
- end
6
+ number.to_s.gsub(/(\d)(?=(?:\d{3})+(?!\d))/, "\\1#{delimiter}")
12
7
  end
13
8
 
14
9
  def home_directory
data/lib/td/updater.rb CHANGED
@@ -166,14 +166,14 @@ module ModuleDefinition
166
166
  # downloading the update compressed file
167
167
  File.open("#{download_dir}/td-update.zip", "wb") do |file|
168
168
  endpoint = update_package_endpoint
169
- puts "\npackage '#{endpoint}'... " unless ENV['TD_TOOLBELT_DEBUG'].nil?
169
+ $stdout.puts "\npackage '#{endpoint}'... " unless ENV['TD_TOOLBELT_DEBUG'].nil?
170
170
  stream_fetch(endpoint, file) {
171
171
  indicator.update
172
172
  }
173
173
  end
174
174
  indicator.finish
175
175
 
176
- print "Unpacking updated toolbelt package..."
176
+ $stdout.print "Unpacking updated toolbelt package..."
177
177
  Zip::ZipFile.open("#{download_dir}/td-update.zip") do |zip|
178
178
  zip.each do |entry|
179
179
  target = File.join(download_dir, entry.to_s)
@@ -181,7 +181,7 @@ module ModuleDefinition
181
181
  zip.extract(entry, target) { true }
182
182
  end
183
183
  end
184
- print "done\n"
184
+ $stdout.print "done\n"
185
185
 
186
186
  FileUtils.rm "#{download_dir}/td-update.zip"
187
187
 
@@ -270,7 +270,7 @@ module ModuleDefinition
270
270
 
271
271
  http.request_get(uri.path) {|response|
272
272
  if response.class == Net::HTTPOK
273
- # print a . every tick_period seconds
273
+ # $stdout.print a . every tick_period seconds
274
274
  response.read_body do |chunk|
275
275
  binfile.write chunk
276
276
  progress.call unless progress.nil?
@@ -279,7 +279,7 @@ module ModuleDefinition
279
279
  elsif response.class == Net::HTTPFound || \
280
280
  response.class == Net::HTTPRedirection
281
281
  unless ENV['TD_TOOLBELT_DEBUG'].nil?
282
- puts "redirect '#{url}' to '#{response['Location']}'... "
282
+ $stdout.puts "redirect '#{url}' to '#{response['Location']}'... "
283
283
  end
284
284
  return stream_fetch(response['Location'], binfile, &progress)
285
285
  else
@@ -353,15 +353,15 @@ end # module ModuleDefinition
353
353
  indicator.finish()
354
354
 
355
355
  if status
356
- puts "Installed td-import.jar v#{version} in '#{Updater.jarfile_dest_path}'.\n"
356
+ $stdout.puts "Installed td-import.jar v#{version} in '#{Updater.jarfile_dest_path}'.\n"
357
357
  File.rename 'td-import.jar.new', 'td-import.jar'
358
358
  else
359
- puts "Update of td-import.jar failed." unless ENV['TD_TOOLBELT_DEBUG'].nil?
359
+ $stdout.puts "Update of td-import.jar failed." unless ENV['TD_TOOLBELT_DEBUG'].nil?
360
360
  File.delete 'td-import.jar.new' if File.exists? 'td-import.jar.new'
361
361
  end
362
362
  end
363
363
  else
364
- puts 'Installed td-import.jar is already at the latest version.' unless hourly
364
+ $stdout.puts 'Installed td-import.jar is already at the latest version.' unless hourly
365
365
  end
366
366
  end
367
367
 
@@ -370,7 +370,7 @@ end # module ModuleDefinition
370
370
  if !ENV['TD_TOOLBELT_JAR_UPDATE'].nil?
371
371
  # also validates the TD_TOOLBELT_JAR_UPDATE environment variable value
372
372
  if ENV['TD_TOOLBELT_JAR_UPDATE'] == "0"
373
- puts "Warning: Bulk Import JAR auto-update disabled by TD_TOOLBELT_JAR_UPDATE=0"
373
+ $stdout.puts "Warning: Bulk Import JAR auto-update disabled by TD_TOOLBELT_JAR_UPDATE=0"
374
374
  return
375
375
  elsif ENV['TD_TOOLBELT_JAR_UPDATE'] != "1"
376
376
  raise UpdateError,
data/lib/td/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TreasureData
2
- TOOLBELT_VERSION = '0.11.9'
2
+ TOOLBELT_VERSION = '0.11.10'
3
3
  end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'td/command/common'
3
+ require 'td/command/list'
4
+ require 'td/command/connector'
5
+
6
+ module TreasureData::Command
7
+ describe 'connector commands' do
8
+ describe '#connector_preview' do
9
+ subject do
10
+ backup = $stdout.dup
11
+ buf = StringIO.new
12
+
13
+ begin
14
+ $stdout = buf
15
+
16
+ TreasureData::Command::Runner.new.run ["connector:preview", tempfile]
17
+
18
+ buf.string
19
+ ensure
20
+ $stdout = backup
21
+ end
22
+ end
23
+
24
+ let(:tempfile) do
25
+ File.join("spec", "td", "fixture", "bulk_load.yml")
26
+ end
27
+
28
+ let(:preview_result) do
29
+ {
30
+ "schema" => [
31
+ {"index" => 0, "name" => "c0_too_l#{'o' * 60}ng_column_name", "type" => "string"},
32
+ {"index" => 1, "name" => "c1", "type" => "long"},
33
+ {"index" => 2, "name" => "c2", "type" => "string"},
34
+ {"index" => 3, "name" => "c3", "type" => "string"}
35
+ ],
36
+ "records" => [
37
+ ["19920116", 32864, "06612", "00195"],
38
+ ["19910729", 14824, "07706", "00058"],
39
+ ["19881022", 26114, "06960", "00175"]
40
+ ]
41
+ }
42
+ end
43
+
44
+ before do
45
+ TreasureData::Client.any_instance.stub(:bulk_load_preview).and_return(preview_result)
46
+ end
47
+
48
+ it 'should include too_long_column_name without truncated' do
49
+ too_long_column_name = preview_result["schema"][0]["name"]
50
+ expect(subject).to include "#{too_long_column_name}:string"
51
+ end
52
+ end
53
+ end
54
+ end