spec/td/client/import_api_spec.rb in td-client-0.8.85 vs spec/td/client/import_api_spec.rb in td-client-0.9.0dev1
- old
+ new
@@ -6,137 +6,62 @@
describe 'Import API' do
include_context 'spec symbols'
include_context 'common helper'
let :api do
- API.new(nil, :endpoint => endpoint)
+ API.new(nil, :endpoint => 'https://api.treasuredata.com')
end
let :api_old do
- API.new(nil, :endpoint => endpoint_old)
+ API.new(nil, :endpoint => 'http://api.treasure-data.com')
end
- let :api_default do
- API.new(nil)
- end
-
- let :api_default_http do
- API.new(nil, :ssl => false)
- end
-
- let :api_unknown_host do
- API.new(nil, :endpoint => endpoint_unknown)
- end
-
- let :api_unknown_host_http do
- API.new(nil, :endpoint => endpoint_unknown, :ssl => false)
- end
-
- let(:endpoint) { 'api.treasuredata.com' }
- let(:endpoint_old) { TreasureData::API::OLD_ENDPOINT }
- let(:endpoint_unknown) { "example.com" }
- let(:endpoint_import) { "api-import.treasuredata.com" }
- let(:endpoint_import_old) { "api-import.treasure-data.com" }
- let(:endpoint_import_unknown) { endpoint_unknown }
-
describe 'import' do
it 'runs with unique_id' do
t = Tempfile.new('import_api_spec')
File.open(t.path, 'w') do |f|
f << '12345'
end
- stub_request(:put, "https://#{endpoint_import}/v3/table/import_with_id/db/table/unique_id/format").
+ stub_request(:put, "https://api-import.treasuredata.com/v3/table/import_with_id/db/table/unique_id/format").
with(:body => '12345').
to_return(:body => '{"elapsed_time":"1.23"}')
File.open(t.path) do |f|
- expect(api.import('db', 'table', 'format', f, 5, 'unique_id')).to eq(1.23)
+ api.import('db', 'table', 'format', f, 5, 'unique_id').should == 1.23
end
end
it 'runs without unique_id' do
t = Tempfile.new('import_api_spec')
File.open(t.path, 'w') do |f|
f << '12345'
end
- stub_request(:put, "https://#{endpoint_import}/v3/table/import/db/table/format").
+ stub_request(:put, "https://api-import.treasuredata.com/v3/table/import/db/table/format").
with(:body => '12345').
to_return(:body => '{"elapsed_time":"1.23"}')
File.open(t.path) do |f|
- expect(api.import('db', 'table', 'format', f, 5)).to eq(1.23)
+ api.import('db', 'table', 'format', f, 5).should == 1.23
end
end
- it 'runs for old endpoint (force "http" instead of "https" for compatibility)' do
+ it 'runs for old endpoint' do
t = Tempfile.new('import_api_spec')
File.open(t.path, 'w') do |f|
f << '12345'
end
- stub_request(:put, "http://#{endpoint_import_old}/v3/table/import/db/table/format").
+ stub_request(:put, "http://api-import.treasure-data.com/v3/table/import/db/table/format").
with(:body => '12345').
to_return(:body => '{"elapsed_time":"1.23"}')
File.open(t.path) do |f|
- expect(api_old.import('db', 'table', 'format', f, 5)).to eq(1.23)
+ api_old.import('db', 'table', 'format', f, 5).should == 1.23
end
end
- it 'runs for no endpoint specified (default behavior)' do
- t = Tempfile.new('import_api_spec')
- File.open(t.path, 'w') do |f|
- f << '12345'
- end
- stub_request(:put, "https://#{endpoint_import}/v3/table/import/db/table/format").
- with(:body => '12345').
- to_return(:body => '{"elapsed_time":"1.23"}')
- File.open(t.path) do |f|
- expect(api_default.import('db', 'table', 'format', f, 5)).to eq 1.23
- end
- end
-
- it 'runs for no endpoint specified with ssl: false' do
- t = Tempfile.new('import_api_spec')
- File.open(t.path, 'w') do |f|
- f << '12345'
- end
- stub_request(:put, "http://#{endpoint_import}/v3/table/import/db/table/format").
- with(:body => '12345').
- to_return(:body => '{"elapsed_time":"1.23"}')
- File.open(t.path) do |f|
- expect(api_default_http.import('db', 'table', 'format', f, 5)).to eq 1.23
- end
- end
-
- it 'runs for unknown endpoint specified' do
- t = Tempfile.new('import_api_spec')
- File.open(t.path, 'w') do |f|
- f << '12345'
- end
- stub_request(:put, "https://#{endpoint_unknown}/v3/table/import/db/table/format").
- with(:body => '12345').
- to_return(:body => '{"elapsed_time":"1.23"}')
- File.open(t.path) do |f|
- expect(api_unknown_host.import('db', 'table', 'format', f, 5)).to eq 1.23
- end
- end
-
- it 'runs for unknown endpoint with ssl=false specified' do
- t = Tempfile.new('import_api_spec')
- File.open(t.path, 'w') do |f|
- f << '12345'
- end
- stub_request(:put, "http://#{endpoint_unknown}/v3/table/import/db/table/format").
- with(:body => '12345').
- to_return(:body => '{"elapsed_time":"1.23"}')
- File.open(t.path) do |f|
- expect(api_unknown_host_http.import('db', 'table', 'format', f, 5)).to eq 1.23
- end
- end
-
it 'raises APIError' do
t = Tempfile.new('import_api_spec')
File.open(t.path, 'w') do |f|
f << '12345'
end
- stub_request(:put, "https://#{endpoint_import}/v3/table/import/db/table/format").
+ stub_request(:put, "https://api-import.treasuredata.com/v3/table/import/db/table/format").
with(:body => '12345').
to_return(:status => 500)
File.open(t.path) do |f|
expect {
api.import('db', 'table', 'format', f, 5)