elasticsearch-transport 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +23 -6
- data/Rakefile +15 -0
- data/elasticsearch-transport.gemspec +8 -0
- data/lib/elasticsearch/transport/client.rb +10 -4
- data/lib/elasticsearch/transport/extensions/test_cluster.rb +0 -5
- data/lib/elasticsearch/transport/transport/base.rb +13 -0
- data/lib/elasticsearch/transport/transport/connections/connection.rb +5 -1
- data/lib/elasticsearch/transport/transport/http/curb.rb +14 -9
- data/lib/elasticsearch/transport/transport/http/faraday.rb +2 -2
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/test/test_helper.rb +2 -2
- data/test/unit/client_test.rb +62 -9
- data/test/unit/connection_test.rb +10 -0
- data/test/unit/transport_base_test.rb +22 -1
- data/test/unit/transport_curb_test.rb +26 -7
- data/test/unit/transport_faraday_test.rb +6 -1
- metadata +50 -2
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
# Elasticsearch::
|
1
|
+
# Elasticsearch::Transport
|
2
2
|
|
3
3
|
**This library is part of the [`elasticsearch-ruby`](https://github.com/elasticsearch/elasticsearch-ruby/) package;
|
4
4
|
please refer to it, unless you want to use this library standalone.**
|
5
5
|
|
6
6
|
----
|
7
7
|
|
8
|
-
The `elasticsearch-
|
8
|
+
The `elasticsearch-transport` library provides a low-level Ruby client for connecting
|
9
9
|
to an [Elasticsearch](http://elasticsearch.org) cluster.
|
10
10
|
|
11
11
|
It handles connecting to multiple nodes in the cluster, rotating across connections,
|
@@ -31,16 +31,16 @@ Features overview:
|
|
31
31
|
|
32
32
|
Install the package from [Rubygems](https://rubygems.org):
|
33
33
|
|
34
|
-
gem install elasticsearch-
|
34
|
+
gem install elasticsearch-transport
|
35
35
|
|
36
36
|
To use an unreleased version, either add it to your `Gemfile` for [Bundler](http://gembundler.com):
|
37
37
|
|
38
|
-
gem 'elasticsearch-
|
38
|
+
gem 'elasticsearch-transport', git: 'git://github.com/elasticsearch/elasticsearch-ruby.git'
|
39
39
|
|
40
40
|
or install it from a source code checkout:
|
41
41
|
|
42
42
|
git clone https://github.com/elasticsearch/elasticsearch-ruby.git
|
43
|
-
cd elasticsearch-ruby/elasticsearch-
|
43
|
+
cd elasticsearch-ruby/elasticsearch-transport
|
44
44
|
bundle install
|
45
45
|
rake install
|
46
46
|
|
@@ -49,12 +49,14 @@ or install it from a source code checkout:
|
|
49
49
|
In the simplest form, connect to Elasticsearch running on <http://localhost:9200>
|
50
50
|
without any configuration:
|
51
51
|
|
52
|
-
require 'elasticsearch/
|
52
|
+
require 'elasticsearch/transport'
|
53
53
|
|
54
54
|
client = Elasticsearch::Client.new
|
55
55
|
response = client.perform_request 'GET', '_cluster/health'
|
56
56
|
# => #<Elasticsearch::Transport::Transport::Response:0x007fc5d506ce38 @status=200, @body={ ... } >
|
57
57
|
|
58
|
+
Full documentation is available at <http://rubydoc.info/gems/elasticsearch-transport>.
|
59
|
+
|
58
60
|
## Configuration
|
59
61
|
|
60
62
|
The client supports many configurations options for setting up and managing connections,
|
@@ -78,6 +80,10 @@ Instead of Strings, you can pass host information as an array of Hashes:
|
|
78
80
|
|
79
81
|
Elasticsearch::Client.new hosts: [ { host: 'myhost1', port: 8080 }, { host: 'myhost2', port: 8080 } ]
|
80
82
|
|
83
|
+
Scheme, HTTP authentication credentials and URL prefixes are handled automatically:
|
84
|
+
|
85
|
+
Elasticsearch::Client.new url: 'https://myserver:4430/search'
|
86
|
+
|
81
87
|
### Logging
|
82
88
|
|
83
89
|
To log requests and responses to standard output with the default logger (an instance of Ruby's {::Logger}) class):
|
@@ -209,6 +215,17 @@ It's possible to customize the _Curb_ instance by passing a block to the constru
|
|
209
215
|
|
210
216
|
client = Elasticsearch::Client.new transport: transport
|
211
217
|
|
218
|
+
Instead of passing the transport to the constructor, you can inject it at run time:
|
219
|
+
|
220
|
+
faraday_client = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
|
221
|
+
hosts: [ { host: '33.33.33.10', port: '443', user: 'USERNAME', password: 'PASSWORD', scheme: 'https' } ],
|
222
|
+
& lambda { |f| f.instance_variable_set :@ssl, { verify: false }
|
223
|
+
f.options[:ssl] = { verify: false }
|
224
|
+
f.adapter :excon }
|
225
|
+
|
226
|
+
client = Elasticsearch::Client.new
|
227
|
+
client.transport = faraday_client
|
228
|
+
|
212
229
|
You can write your own transport implementation easily, by including the
|
213
230
|
{Elasticsearch::Transport::Transport::Base} module, implementing the required contract,
|
214
231
|
and passing it to the client as the `transport_class` parameter. All the arguments
|
data/Rakefile
CHANGED
@@ -8,7 +8,19 @@ task :test => 'test:unit'
|
|
8
8
|
|
9
9
|
require 'rake/testtask'
|
10
10
|
namespace :test do
|
11
|
+
task :ci_reporter do
|
12
|
+
ENV['CI_REPORTS'] ||= 'tmp/reports'
|
13
|
+
if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
|
14
|
+
require 'ci/reporter/rake/test_unit'
|
15
|
+
Rake::Task['ci:setup:testunit'].invoke
|
16
|
+
else
|
17
|
+
require 'ci/reporter/rake/minitest'
|
18
|
+
Rake::Task['ci:setup:minitest'].invoke
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
11
22
|
Rake::TestTask.new(:unit) do |test|
|
23
|
+
Rake::Task['test:ci_reporter'].invoke if ENV['CI']
|
12
24
|
test.libs << 'lib' << 'test'
|
13
25
|
test.test_files = FileList["test/unit/**/*_test.rb"]
|
14
26
|
# test.verbose = true
|
@@ -16,16 +28,19 @@ namespace :test do
|
|
16
28
|
end
|
17
29
|
|
18
30
|
Rake::TestTask.new(:integration) do |test|
|
31
|
+
Rake::Task['test:ci_reporter'].invoke if ENV['CI']
|
19
32
|
test.libs << 'lib' << 'test'
|
20
33
|
test.test_files = FileList["test/integration/**/*_test.rb"]
|
21
34
|
end
|
22
35
|
|
23
36
|
Rake::TestTask.new(:all) do |test|
|
37
|
+
Rake::Task['test:ci_reporter'].invoke if ENV['CI']
|
24
38
|
test.libs << 'lib' << 'test'
|
25
39
|
test.test_files = FileList["test/unit/**/*_test.rb", "test/integration/**/*_test.rb"]
|
26
40
|
end
|
27
41
|
|
28
42
|
Rake::TestTask.new(:profile) do |test|
|
43
|
+
Rake::Task['test:ci_reporter'].invoke if ENV['CI']
|
29
44
|
test.libs << 'lib' << 'test'
|
30
45
|
test.test_files = FileList["test/profile/**/*_test.rb"]
|
31
46
|
end
|
@@ -35,15 +35,23 @@ Gem::Specification.new do |s|
|
|
35
35
|
s.add_development_dependency "turn"
|
36
36
|
s.add_development_dependency "yard"
|
37
37
|
s.add_development_dependency "ruby-prof"
|
38
|
+
s.add_development_dependency "pry"
|
39
|
+
s.add_development_dependency "ci_reporter"
|
38
40
|
|
39
41
|
# Gems for testing integrations
|
40
42
|
s.add_development_dependency "curb"
|
41
43
|
s.add_development_dependency "typhoeus"
|
42
44
|
|
45
|
+
# Prevent unit test failures on Ruby 1.8
|
46
|
+
if defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
|
47
|
+
s.add_development_dependency "test-unit", '~> 2'
|
48
|
+
end
|
49
|
+
|
43
50
|
if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
44
51
|
s.add_development_dependency "simplecov"
|
45
52
|
s.add_development_dependency "cane"
|
46
53
|
s.add_development_dependency "require-prof"
|
54
|
+
s.add_development_dependency "coveralls"
|
47
55
|
end
|
48
56
|
|
49
57
|
s.description = <<-DESC.gsub(/^ /, '')
|
@@ -105,13 +105,19 @@ module Elasticsearch
|
|
105
105
|
hosts = hosts_config.map do |host|
|
106
106
|
case host
|
107
107
|
when String
|
108
|
-
|
109
|
-
|
110
|
-
|
108
|
+
if host =~ /^[a-z]+\:\/\//
|
109
|
+
uri = URI.parse(host)
|
110
|
+
{ :scheme => uri.scheme, :user => uri.user, :password => uri.password, :host => uri.host, :path => uri.path, :port => uri.port.to_s }
|
111
|
+
else
|
112
|
+
host, port = host.split(':')
|
113
|
+
{ :host => host, :port => port }
|
114
|
+
end
|
115
|
+
when URI
|
116
|
+
{ :scheme => host.scheme, :user => host.user, :password => host.password, :host => host.host, :path => host.path, :port => host.port.to_s }
|
111
117
|
when Hash
|
112
118
|
host
|
113
119
|
else
|
114
|
-
raise ArgumentError, "Please pass host as a String or Hash
|
120
|
+
raise ArgumentError, "Please pass host as a String, URI or Hash -- #{host.class} given."
|
115
121
|
end
|
116
122
|
end
|
117
123
|
|
@@ -27,11 +27,6 @@ module Elasticsearch
|
|
27
27
|
def start(arguments={})
|
28
28
|
arguments[:command] = ENV['TEST_CLUSTER_COMMAND'] || 'elasticsearch'
|
29
29
|
|
30
|
-
unless system "which #{arguments[:command]} > /dev/null 2>&1"
|
31
|
-
STDERR.puts ANSI.red("[ERROR] Elasticsearch can't be started, is it installed? Run: $ which elasticsearch"), ''
|
32
|
-
abort
|
33
|
-
end
|
34
|
-
|
35
30
|
@@number_of_nodes = arguments[:count] if arguments[:count]
|
36
31
|
|
37
32
|
arguments[:port] = (ENV['TEST_CLUSTER_PORT'] || 9250).to_i
|
@@ -139,6 +139,19 @@ module Elasticsearch
|
|
139
139
|
o = o.is_a?(String) ? o : serializer.dump(o, options)
|
140
140
|
end
|
141
141
|
|
142
|
+
# Returns a full URL based on information from host
|
143
|
+
#
|
144
|
+
# @param host [Hash] Host configuration passed in from {Client}
|
145
|
+
#
|
146
|
+
# @api private
|
147
|
+
def __full_url(host)
|
148
|
+
url = "#{host[:protocol]}://"
|
149
|
+
url += "#{host[:user]}:#{host[:password]}@" if host[:user]
|
150
|
+
url += "#{host[:host]}:#{host[:port]}"
|
151
|
+
url += "#{host[:path]}" if host[:path]
|
152
|
+
url
|
153
|
+
end
|
154
|
+
|
142
155
|
# Performs a request to Elasticsearch, while handling logging, tracing, marking dead connections,
|
143
156
|
# retrying the request and reloading the connections.
|
144
157
|
#
|
@@ -36,7 +36,11 @@ module Elasticsearch
|
|
36
36
|
# @return [String]
|
37
37
|
#
|
38
38
|
def full_url(path, params={})
|
39
|
-
"#{host[:protocol]}
|
39
|
+
url = "#{host[:protocol]}://"
|
40
|
+
url += "#{host[:user]}:#{host[:password]}@" if host[:user]
|
41
|
+
url += "#{host[:host]}:#{host[:port]}"
|
42
|
+
url += "#{host[:path]}" if host[:path]
|
43
|
+
url += "/#{full_path(path, params)}"
|
40
44
|
end
|
41
45
|
|
42
46
|
# Returns the complete endpoint path with serialized parameters.
|
@@ -20,15 +20,14 @@ module Elasticsearch
|
|
20
20
|
connection.connection.url = url
|
21
21
|
|
22
22
|
case method
|
23
|
-
when 'HEAD'
|
24
|
-
when 'PUT'
|
25
|
-
|
26
|
-
when 'POST'
|
27
|
-
connection.connection.post_body = __convert_to_json(body) if body
|
28
|
-
connection.connection.http_post
|
23
|
+
when 'HEAD'
|
24
|
+
when 'GET', 'POST', 'PUT', 'DELETE'
|
25
|
+
connection.connection.put_data = __convert_to_json(body) if body
|
29
26
|
else raise ArgumentError, "Unsupported HTTP method: #{method}"
|
30
27
|
end
|
31
28
|
|
29
|
+
connection.connection.http(method.to_sym)
|
30
|
+
|
32
31
|
Response.new connection.connection.response_code, connection.connection.body_str
|
33
32
|
end
|
34
33
|
end
|
@@ -40,13 +39,19 @@ module Elasticsearch
|
|
40
39
|
def __build_connections
|
41
40
|
Connections::Collection.new \
|
42
41
|
:connections => hosts.map { |host|
|
43
|
-
host[:protocol]
|
42
|
+
host[:protocol] = host[:scheme] || DEFAULT_PROTOCOL
|
44
43
|
host[:port] ||= DEFAULT_PORT
|
45
44
|
|
46
45
|
client = ::Curl::Easy.new
|
47
46
|
client.resolve_mode = :ipv4
|
48
|
-
client.headers = {'Content-Type' => 'application/json'}
|
49
|
-
client.url =
|
47
|
+
client.headers = {'User-Agent' => "Curb #{Curl::CURB_VERSION}", 'Content-Type' => 'application/json' }
|
48
|
+
client.url = __full_url(host)
|
49
|
+
|
50
|
+
if host[:user]
|
51
|
+
client.http_auth_types = host[:auth_type] || :basic
|
52
|
+
client.username = host[:user]
|
53
|
+
client.password = host[:password]
|
54
|
+
end
|
50
55
|
|
51
56
|
client.instance_eval &@block if @block
|
52
57
|
|
@@ -33,9 +33,9 @@ module Elasticsearch
|
|
33
33
|
def __build_connections
|
34
34
|
Connections::Collection.new \
|
35
35
|
:connections => hosts.map { |host|
|
36
|
-
host[:protocol]
|
36
|
+
host[:protocol] = host[:scheme] || DEFAULT_PROTOCOL
|
37
37
|
host[:port] ||= DEFAULT_PORT
|
38
|
-
url =
|
38
|
+
url = __full_url(host)
|
39
39
|
|
40
40
|
Connections::Connection.new \
|
41
41
|
:host => host,
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
|
2
2
|
|
3
|
-
if RUBY_1_8
|
3
|
+
if RUBY_1_8 and not ENV['BUNDLE_GEMFILE']
|
4
4
|
require 'rubygems'
|
5
5
|
gem 'test-unit'
|
6
6
|
end
|
@@ -19,7 +19,7 @@ require 'mocha/setup'
|
|
19
19
|
require 'ansi/code'
|
20
20
|
require 'turn' unless ENV["TM_FILEPATH"] || ENV["NOTURN"] || RUBY_1_8
|
21
21
|
|
22
|
-
require 'test_extensions'
|
22
|
+
require File.expand_path('../test_extensions', __FILE__)
|
23
23
|
|
24
24
|
require 'require-prof' if ENV["REQUIRE_PROF"]
|
25
25
|
require 'elasticsearch-transport'
|
data/test/unit/client_test.rb
CHANGED
@@ -66,30 +66,83 @@ class Elasticsearch::Transport::ClientTest < Test::Unit::TestCase
|
|
66
66
|
|
67
67
|
context "extracting hosts" do
|
68
68
|
should "handle defaults" do
|
69
|
-
|
69
|
+
hosts = @client.__extract_hosts
|
70
|
+
|
71
|
+
assert_equal 'localhost', hosts[0][:host]
|
72
|
+
assert_nil hosts[0][:port]
|
70
73
|
end
|
71
74
|
|
72
75
|
should "extract from string" do
|
73
|
-
|
76
|
+
hosts = @client.__extract_hosts 'myhost'
|
77
|
+
|
78
|
+
assert_equal 'myhost', hosts[0][:host]
|
79
|
+
assert_nil hosts[0][:port]
|
74
80
|
end
|
75
81
|
|
76
82
|
should "extract from array" do
|
77
|
-
|
83
|
+
hosts = @client.__extract_hosts ['myhost']
|
84
|
+
|
85
|
+
assert_equal 'myhost', hosts[0][:host]
|
78
86
|
end
|
79
87
|
|
80
88
|
should "extract from array with multiple hosts" do
|
81
|
-
|
82
|
-
|
89
|
+
hosts = @client.__extract_hosts ['host1', 'host2']
|
90
|
+
|
91
|
+
assert_equal 'host1', hosts[0][:host]
|
92
|
+
assert_equal 'host2', hosts[1][:host]
|
83
93
|
end
|
84
94
|
|
85
95
|
should "extract from array with ports" do
|
86
|
-
|
87
|
-
|
96
|
+
hosts = @client.__extract_hosts ['host1:1000', 'host2:2000']
|
97
|
+
|
98
|
+
assert_equal 'host1', hosts[0][:host]
|
99
|
+
assert_equal '1000', hosts[0][:port]
|
100
|
+
|
101
|
+
assert_equal 'host2', hosts[1][:host]
|
102
|
+
assert_equal '2000', hosts[1][:port]
|
103
|
+
end
|
104
|
+
|
105
|
+
should "extract path" do
|
106
|
+
hosts = @client.__extract_hosts 'https://myhost:8080/api'
|
107
|
+
|
108
|
+
assert_equal '/api', hosts[0][:path]
|
109
|
+
end
|
110
|
+
|
111
|
+
should "extract scheme (protocol)" do
|
112
|
+
hosts = @client.__extract_hosts 'https://myhost:8080'
|
113
|
+
|
114
|
+
assert_equal 'https', hosts[0][:scheme]
|
115
|
+
assert_equal 'myhost', hosts[0][:host]
|
116
|
+
assert_equal '8080', hosts[0][:port]
|
117
|
+
end
|
118
|
+
|
119
|
+
should "extract credentials" do
|
120
|
+
hosts = @client.__extract_hosts 'http://USERNAME:PASSWORD@myhost:8080'
|
121
|
+
|
122
|
+
assert_equal 'http', hosts[0][:scheme]
|
123
|
+
assert_equal 'USERNAME', hosts[0][:user]
|
124
|
+
assert_equal 'PASSWORD', hosts[0][:password]
|
125
|
+
assert_equal 'myhost', hosts[0][:host]
|
126
|
+
assert_equal '8080', hosts[0][:port]
|
88
127
|
end
|
89
128
|
|
90
129
|
should "pass Hashes over" do
|
91
|
-
|
92
|
-
|
130
|
+
hosts = @client.__extract_hosts [{:host => 'myhost', :port => '1000', :foo => 'bar'}]
|
131
|
+
|
132
|
+
assert_equal 'myhost', hosts[0][:host]
|
133
|
+
assert_equal '1000', hosts[0][:port]
|
134
|
+
assert_equal 'bar', hosts[0][:foo]
|
135
|
+
end
|
136
|
+
|
137
|
+
should "use URL instance" do
|
138
|
+
require 'uri'
|
139
|
+
hosts = @client.__extract_hosts URI.parse('https://USERNAME:PASSWORD@myhost:4430')
|
140
|
+
|
141
|
+
assert_equal 'https', hosts[0][:scheme]
|
142
|
+
assert_equal 'USERNAME', hosts[0][:user]
|
143
|
+
assert_equal 'PASSWORD', hosts[0][:password]
|
144
|
+
assert_equal 'myhost', hosts[0][:host]
|
145
|
+
assert_equal '4430', hosts[0][:port]
|
93
146
|
end
|
94
147
|
|
95
148
|
should "raise error for incompatible argument" do
|
@@ -25,6 +25,16 @@ class Elasticsearch::Transport::Transport::Connections::ConnectionTest < Test::U
|
|
25
25
|
assert_equal 'http://localhost:9200/_search?foo=bar', c.full_url('_search', {:foo => 'bar'})
|
26
26
|
end
|
27
27
|
|
28
|
+
should "return full url with credentials" do
|
29
|
+
c = Connection.new :host => { :protocol => 'http', :user => 'U', :password => 'P', :host => 'localhost', :port => '9200' }
|
30
|
+
assert_equal 'http://U:P@localhost:9200/_search?foo=bar', c.full_url('_search', {:foo => 'bar'})
|
31
|
+
end
|
32
|
+
|
33
|
+
should "return full url with path" do
|
34
|
+
c = Connection.new :host => { :protocol => 'http', :host => 'localhost', :port => '9200', :path => '/foo' }
|
35
|
+
assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('_search', {:foo => 'bar'})
|
36
|
+
end
|
37
|
+
|
28
38
|
should "have a string representation" do
|
29
39
|
c = Connection.new :host => 'x'
|
30
40
|
assert_match /host: x/, c.to_s
|
@@ -57,6 +57,25 @@ class Elasticsearch::Transport::Transport::BaseTest < Test::Unit::TestCase
|
|
57
57
|
transport = DummyTransport.new :options => { :sniffer_class => DummySniffer }
|
58
58
|
assert_instance_of DummySniffer, transport.sniffer
|
59
59
|
end
|
60
|
+
|
61
|
+
context "when combining the URL" do
|
62
|
+
setup do
|
63
|
+
@transport = DummyTransport.new
|
64
|
+
@basic_parts = { :protocol => 'http', :host => 'myhost', :port => 8080 }
|
65
|
+
end
|
66
|
+
|
67
|
+
should "combine basic parts" do
|
68
|
+
assert_equal 'http://myhost:8080', @transport.__full_url(@basic_parts)
|
69
|
+
end
|
70
|
+
|
71
|
+
should "combine path" do
|
72
|
+
assert_equal 'http://myhost:8080/api', @transport.__full_url(@basic_parts.merge :path => '/api')
|
73
|
+
end
|
74
|
+
|
75
|
+
should "combine authentication credentials" do
|
76
|
+
assert_equal 'http://U:P@myhost:8080', @transport.__full_url(@basic_parts.merge :user => 'U', :password => 'P')
|
77
|
+
end
|
78
|
+
end
|
60
79
|
end
|
61
80
|
|
62
81
|
context "getting a connection" do
|
@@ -260,7 +279,9 @@ class Elasticsearch::Transport::Transport::BaseTest < Test::Unit::TestCase
|
|
260
279
|
end
|
261
280
|
|
262
281
|
should "log the request and response" do
|
263
|
-
@transport.logger.expects(:info). with
|
282
|
+
@transport.logger.expects(:info). with do |line|
|
283
|
+
line =~ %r|POST localhost\:9200/_search\?size=1 \[status\:200, request:.*s, query:n/a\]|
|
284
|
+
end
|
264
285
|
@transport.logger.expects(:debug). with '> {"foo":"bar"}'
|
265
286
|
@transport.logger.expects(:debug). with '< {"foo":"bar"}'
|
266
287
|
|
@@ -14,7 +14,7 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestC
|
|
14
14
|
assert_equal 1, @transport.hosts.size
|
15
15
|
assert_equal 1, @transport.connections.size
|
16
16
|
|
17
|
-
assert_instance_of ::Curl::Easy,
|
17
|
+
assert_instance_of ::Curl::Easy, @transport.connections.first.connection
|
18
18
|
assert_equal 'http://foobar:1234', @transport.connections.first.connection.url
|
19
19
|
end
|
20
20
|
|
@@ -23,23 +23,36 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestC
|
|
23
23
|
@transport.perform_request 'GET', '/'
|
24
24
|
end
|
25
25
|
|
26
|
+
should "set body for GET request" do
|
27
|
+
@transport.connections.first.connection.expects(:put_data=).with('{"foo":"bar"}')
|
28
|
+
@transport.connections.first.connection.expects(:http).with(:GET).returns(stub_everything)
|
29
|
+
@transport.perform_request 'GET', '/', {}, '{"foo":"bar"}'
|
30
|
+
end
|
31
|
+
|
32
|
+
should "set body for PUT request" do
|
33
|
+
@transport.connections.first.connection.expects(:put_data=)
|
34
|
+
@transport.connections.first.connection.expects(:http).with(:PUT).returns(stub_everything)
|
35
|
+
@transport.perform_request 'PUT', '/', {}, {:foo => 'bar'}
|
36
|
+
end
|
37
|
+
|
26
38
|
should "serialize the request body" do
|
27
|
-
@transport.connections.first.connection.expects(:
|
39
|
+
@transport.connections.first.connection.expects(:http).with(:POST).returns(stub_everything)
|
28
40
|
@transport.serializer.expects(:dump)
|
29
41
|
@transport.perform_request 'POST', '/', {}, {:foo => 'bar'}
|
30
42
|
end
|
31
43
|
|
32
44
|
should "not serialize a String request body" do
|
33
|
-
@transport.connections.first.connection.expects(:
|
45
|
+
@transport.connections.first.connection.expects(:http).with(:POST).returns(stub_everything)
|
34
46
|
@transport.serializer.expects(:dump).never
|
35
47
|
@transport.perform_request 'POST', '/', {}, '{"foo":"bar"}'
|
36
48
|
end
|
37
49
|
|
38
50
|
should "handle HTTP methods" do
|
39
|
-
@transport.connections.first.connection.expects(:http).
|
40
|
-
@transport.connections.first.connection.expects(:
|
41
|
-
@transport.connections.first.connection.expects(:
|
42
|
-
@transport.connections.first.connection.expects(:
|
51
|
+
@transport.connections.first.connection.expects(:http).with(:HEAD).returns(stub_everything)
|
52
|
+
@transport.connections.first.connection.expects(:http).with(:GET).returns(stub_everything)
|
53
|
+
@transport.connections.first.connection.expects(:http).with(:PUT).returns(stub_everything)
|
54
|
+
@transport.connections.first.connection.expects(:http).with(:POST).returns(stub_everything)
|
55
|
+
@transport.connections.first.connection.expects(:http).with(:DELETE).returns(stub_everything)
|
43
56
|
|
44
57
|
%w| HEAD GET PUT POST DELETE |.each { |method| @transport.perform_request method, '/' }
|
45
58
|
|
@@ -54,6 +67,12 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestC
|
|
54
67
|
assert_equal( {"Content-Type"=>"application/json", "User-Agent"=>"myapp-0.0"},
|
55
68
|
transport.connections.first.connection.headers )
|
56
69
|
end
|
70
|
+
|
71
|
+
should "set the credentials if passed" do
|
72
|
+
transport = Curb.new :hosts => [ { :host => 'foobar', :port => 1234, :user => 'foo', :password => 'bar' } ]
|
73
|
+
assert_equal 'foo', transport.connections.first.connection.username
|
74
|
+
assert_equal 'bar', transport.connections.first.connection.password
|
75
|
+
end
|
57
76
|
end
|
58
77
|
|
59
78
|
end
|
@@ -17,7 +17,7 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestC
|
|
17
17
|
assert_equal 1, @transport.connections.size
|
18
18
|
|
19
19
|
assert_instance_of ::Faraday::Connection, @transport.connections.first.connection
|
20
|
-
assert_equal 'http://foobar:1234/',
|
20
|
+
assert_equal 'http://foobar:1234/', @transport.connections.first.connection.url_prefix.to_s
|
21
21
|
end
|
22
22
|
|
23
23
|
should "perform the request" do
|
@@ -68,6 +68,11 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestC
|
|
68
68
|
handlers = transport.connections.first.connection.instance_variable_get(:@builder).instance_variable_get(:@handlers)
|
69
69
|
assert handlers.include?(::Faraday::Response::Logger), "#{handlers.inspect} does not include <::Faraday::Adapter::Typhoeus>"
|
70
70
|
end
|
71
|
+
|
72
|
+
should "set the credentials if passed" do
|
73
|
+
transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234, :user => 'foo', :password => 'bar' } ]
|
74
|
+
assert_equal 'Basic Zm9vOmJhcg==', transport.connections.first.connection.headers['Authorization']
|
75
|
+
end
|
71
76
|
end
|
72
77
|
|
73
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-transport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -171,6 +171,38 @@ dependencies:
|
|
171
171
|
- - ! '>='
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: pry
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ! '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ! '>='
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
- !ruby/object:Gem::Dependency
|
191
|
+
name: ci_reporter
|
192
|
+
requirement: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ! '>='
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
type: :development
|
199
|
+
prerelease: false
|
200
|
+
version_requirements: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
202
|
+
requirements:
|
203
|
+
- - ! '>='
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
174
206
|
- !ruby/object:Gem::Dependency
|
175
207
|
name: curb
|
176
208
|
requirement: !ruby/object:Gem::Requirement
|
@@ -251,6 +283,22 @@ dependencies:
|
|
251
283
|
- - ! '>='
|
252
284
|
- !ruby/object:Gem::Version
|
253
285
|
version: '0'
|
286
|
+
- !ruby/object:Gem::Dependency
|
287
|
+
name: coveralls
|
288
|
+
requirement: !ruby/object:Gem::Requirement
|
289
|
+
none: false
|
290
|
+
requirements:
|
291
|
+
- - ! '>='
|
292
|
+
- !ruby/object:Gem::Version
|
293
|
+
version: '0'
|
294
|
+
type: :development
|
295
|
+
prerelease: false
|
296
|
+
version_requirements: !ruby/object:Gem::Requirement
|
297
|
+
none: false
|
298
|
+
requirements:
|
299
|
+
- - ! '>='
|
300
|
+
- !ruby/object:Gem::Version
|
301
|
+
version: '0'
|
254
302
|
description: ! 'Ruby client for Elasticsearch. See the `elasticsearch` gem for full
|
255
303
|
integration.
|
256
304
|
|