3030raw_key = File . read ( File . join ( PROJECT_PATH , '/.ci/certs/testnode.key' ) )
3131key = OpenSSL ::PKey ::RSA . new ( raw_key )
3232
33- if TEST_SUITE == 'security'
34- TRANSPORT_OPTIONS . merge! ( :ssl => { verify : false ,
35- client_cert : certificate ,
36- client_key : key ,
37- ca_file : '.ci/certs/ca.crt' } )
38-
39- password = ENV [ 'ELASTIC_PASSWORD' ]
40- URL = "https://elastic:#{ password } @#{ TEST_HOST } :#{ TEST_PORT } "
41- else
42- URL = "http://#{ TEST_HOST } :#{ TEST_PORT } "
43- end
4433
45- ADMIN_CLIENT = Elasticsearch ::Client . new ( host : URL , transport_options : TRANSPORT_OPTIONS )
34+ if defined? ( TEST_HOST ) && defined? ( TEST_PORT )
35+ if TEST_SUITE == 'security'
36+ TRANSPORT_OPTIONS . merge! ( :ssl => { verify : false ,
37+ client_cert : certificate ,
38+ client_key : key ,
39+ ca_file : '.ci/certs/ca.crt' } )
40+
41+ password = ENV [ 'ELASTIC_PASSWORD' ]
42+ URL = "https://elastic:#{ password } @#{ TEST_HOST } :#{ TEST_PORT } "
43+ else
44+ URL = "http://#{ TEST_HOST } :#{ TEST_PORT } "
45+ end
46+
47+ ADMIN_CLIENT = Elasticsearch ::Client . new ( host : URL , transport_options : TRANSPORT_OPTIONS )
4648
47- if ENV [ 'QUIET' ] == 'true'
48- DEFAULT_CLIENT = Elasticsearch ::Client . new ( host : URL , transport_options : TRANSPORT_OPTIONS )
49- else
50- DEFAULT_CLIENT = Elasticsearch ::Client . new ( host : URL ,
51- transport_options : TRANSPORT_OPTIONS ,
52- tracer : Logger . new ( $stdout) )
49+ if ENV [ 'QUIET' ] == 'true'
50+ DEFAULT_CLIENT = Elasticsearch ::Client . new ( host : URL , transport_options : TRANSPORT_OPTIONS )
51+ else
52+ DEFAULT_CLIENT = Elasticsearch ::Client . new ( host : URL ,
53+ transport_options : TRANSPORT_OPTIONS ,
54+ tracer : Logger . new ( $stdout) )
55+ end
5356end
5457
5558
@@ -116,3 +119,31 @@ def split_and_parse_key(key)
116119 ( key =~ /\A [-+]?[0-9]+\z / ) ? key . to_i : key . gsub ( '\\' , '' )
117120 end . reject { |k | k == '$body' }
118121end
122+
123+
124+ module HelperModule
125+ def self . included ( context )
126+
127+ context . let ( :client_double ) do
128+ Class . new { include Elasticsearch ::XPack ::API } . new . tap do |client |
129+ expect ( client ) . to receive ( :perform_request ) . with ( *expected_args ) . and_return ( response_double )
130+ end
131+ end
132+
133+ context . let ( :client ) do
134+ Class . new { include Elasticsearch ::XPack ::API } . new . tap do |client |
135+ expect ( client ) . to receive ( :perform_request ) . with ( *expected_args ) . and_return ( response_double )
136+ end
137+ end
138+
139+ context . let ( :response_double ) do
140+ double ( 'response' , status : 200 , body : { } , headers : { } )
141+ end
142+ end
143+ end
144+
145+ RSpec . configure do |config |
146+ config . include ( HelperModule )
147+ config . formatter = 'documentation'
148+ config . color = true
149+ end
0 commit comments