Skip to content

Commit dce1778

Browse files
committed
use and set config file value
1 parent 251e992 commit dce1778

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

lib/td/command/connector.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,19 @@ def connector_issue(op)
139139
database, table, config_file = args
140140
end
141141

142-
required('database', database)
143-
required('table', table)
144-
145142
config = prepare_bulkload_job_config(config_file)
146-
(config['out'] ||= {})['time_column'] = time_column if time_column # TODO will not work once embulk implements multi-job
143+
overwrite_out_config(config, 'database' => database, 'table' => table, 'time_column' => time_column)
147144

148145
client = get_client()
149146

147+
required('database', config['out']['database'])
148+
required('table', config['out']['table'])
149+
150150
if auto_create
151-
create_database_and_table_if_not_exist(client, database, table)
151+
create_database_and_table_if_not_exist(client, config['out']['database'], config['out']['table'])
152152
end
153153

154-
job_id = client.bulk_load_issue(database, table, config: config)
154+
job_id = client.bulk_load_issue(config['out']['database'], config['out']['table'], config: config)
155155

156156
$stdout.puts "Job #{job_id} is queued."
157157
$stdout.puts "Use '#{$prog} " + Config.cl_options_string + "job:show #{job_id}' to show the status."
@@ -161,6 +161,15 @@ def connector_issue(op)
161161
end
162162
end
163163

164+
def overwrite_out_config(config, out_args)
165+
# TODO will not work once embulk implements multi-job
166+
config['out'] ||= {}
167+
168+
out_args.each do |key, value|
169+
config['out'][key] = value if value
170+
end
171+
end
172+
164173
def connector_list(op)
165174
set_render_format_option(op)
166175
op.cmd_parse

spec/td/command/connector_spec.rb

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,55 @@ module TreasureData::Command
8383
describe 'database and table arguments' do
8484
let(:database) { 'database' }
8585
let(:table) { 'table' }
86-
let(:config) { {} }
8786

8887
before do
8988
client = double(:client)
9089
command.stub(:get_client).and_return(client)
9190
command.stub(:create_database_and_table_if_not_exist)
9291
command.stub(:prepare_bulkload_job_config).and_return(config)
9392
client.should_receive(:bulk_load_issue).with(database, table, {config: expect_config}).and_return(1234)
93+
end
94+
95+
context 'set from config file' do
96+
let(:expect_config) {
97+
{'out' => {'database' => database, 'table' => table}}
98+
}
99+
100+
context 'without arguments' do
101+
let(:option) {
102+
List::CommandParser.new("connector:issue", ["config"], [], nil, [File.join("spec", "td", "fixture", "bulk_load.yml")], true)
103+
}
104+
let(:config) {
105+
{'out' => {'database' => database, 'table' => table}}
106+
}
107+
108+
it { expect { subject }.not_to raise_error }
109+
end
110+
111+
context 'with arguments' do
112+
let(:option) {
113+
List::CommandParser.new("connector:issue", ["config"], ['database', 'table'], nil, [File.join("spec", "td", "fixture", "bulk_load.yml"), '--database', database, '--table', table], true)
114+
}
115+
let(:config) {
116+
{'out' => {'database' => 'config_database', 'table' => 'config_table'}}
117+
}
94118

95-
subject
119+
it { expect { subject }.not_to raise_error }
120+
end
96121
end
97122

98123
context 'set --database and --table' do
99124
let(:option) {
100125
List::CommandParser.new("connector:issue", ["config"], ['database', 'table'], nil, [File.join("spec", "td", "fixture", "bulk_load.yml"), '--database', database, '--table', table], true)
101126
}
127+
let(:config) { {} }
102128
let(:expect_config) {
103129
{'out' => {'database' => database, 'table' => table}}
104130
}
105131

106132
it 'show warning' do
133+
subject
134+
107135
expect(stderr_io.string).to include '--database is obsolete option'
108136
expect(stderr_io.string).to include '--table is obsolete option'
109137
end
@@ -113,11 +141,14 @@ module TreasureData::Command
113141
let(:option) {
114142
List::CommandParser.new("connector:issue", ["config", 'database', 'table'], [], nil, [database, table, File.join("spec", "td", "fixture", "bulk_load.yml")], true)
115143
}
144+
let(:config) { {} }
116145
let(:expect_config) {
117146
{'out' => {'database' => database, 'table' => table}}
118147
}
119148

120149
it 'no warning' do
150+
subject
151+
121152
expect(stderr_io.string).not_to include '--database is obsolete option'
122153
expect(stderr_io.string).not_to include '--table is obsolete option'
123154
end

0 commit comments

Comments
 (0)