@@ -3,9 +3,13 @@ using Test
33using Mocking
44using HTTP
55using JSON
6+ using JSON3
67
78Mocking. activate ()
89
10+ serializer = JSON. json
11+ deserializer = JSON. parse
12+
913hosts = [
1014 Dict {Symbol, Any} (:host => " localhost" , :schema => " https" ),
1115 Dict {Symbol, Any} (:host => " 127.0.0.1" , :schema => " http" , :port => 9250 ),
@@ -102,15 +106,15 @@ nodes_response_mock = HTTP.Response(
102106
103107@testset " Transport test" begin
104108 @testset " Transport initialization" begin
105- transport = ElasticsearchClient. ElasticTransport. Transport (;hosts, options)
109+ transport = ElasticsearchClient. ElasticTransport. Transport (;hosts, options, http_client = HTTP, serializer = serializer, deserializer = deserializer )
106110
107111 @test length (transport. connections. connections) == length (hosts)
108112 @test transport. use_compression == options[:compression ]
109113 @test transport. retry_on_status == options[:retry_on_status ]
110114 end
111115
112116 @testset " Performing request" begin
113- transport = ElasticsearchClient. ElasticTransport. Transport (;hosts, options= options)
117+ transport = ElasticsearchClient. ElasticTransport. Transport (;hosts, options= options, http_client = HTTP, serializer = serializer, deserializer = deserializer )
114118
115119 @testset " Testing with successful response" begin
116120 @testset " Testing GET request with params" begin
@@ -223,14 +227,34 @@ nodes_response_mock = HTTP.Response(
223227 @test length (ElasticsearchClient. ElasticTransport. Connections. dead (transport. connections)) == 1
224228 end
225229 end
230+
231+ @testset " Testing GET request with custom serializer/deserializer" begin
232+ http_patch = @patch HTTP. request (args... ;kwargs... ) = successful_health_response_mock
233+ custom_transport = ElasticsearchClient. ElasticTransport. Transport (;
234+ hosts,
235+ options= options,
236+ http_client= HTTP,
237+ serializer= JSON3. write,
238+ deserializer= JSON3. read
239+ )
240+
241+
242+ apply (http_patch) do
243+ response = ElasticsearchClient. ElasticTransport. perform_request (custom_transport, " GET" , " /_cluster/health" ; params = Dict (" pretty" => true ))
244+
245+ @test response isa HTTP. Response
246+ @test response. status == 200
247+ @test haskey (response. body, :cluster_name )
248+ end
249+ end
226250 end
227251 end
228252
229253 @testset " Testing sniffing" begin
230254 @testset " Testing successful sniffing" begin
231255 http_patch = @patch HTTP. request (args... ;kwargs... ) = nodes_response_mock
232256
233- transport = ElasticsearchClient. ElasticTransport. Transport (;hosts, options= options)
257+ transport = ElasticsearchClient. ElasticTransport. Transport (;hosts, options= options, http_client = HTTP, serializer = serializer, deserializer = deserializer )
234258
235259 apply (http_patch) do
236260 hosts = ElasticsearchClient. ElasticTransport. sniff_hosts (transport) |>
@@ -256,7 +280,7 @@ nodes_response_mock = HTTP.Response(
256280 @testset " Testing sniffing timeout" begin
257281 http_patch = @patch HTTP. request (args... ;kwargs... ) = sleep (ElasticsearchClient. ElasticTransport. DEFAULT_SNIFFING_TIMEOUT + 0.5 )
258282
259- transport = ElasticsearchClient. ElasticTransport. Transport (;hosts, options= options)
283+ transport = ElasticsearchClient. ElasticTransport. Transport (;hosts, options= options, http_client = HTTP, serializer = serializer, deserializer = deserializer )
260284
261285 apply (http_patch) do
262286 @test_throws ElasticsearchClient. ElasticTransport. SniffingTimetoutError ElasticsearchClient. ElasticTransport. sniff_hosts (transport)
@@ -267,7 +291,7 @@ nodes_response_mock = HTTP.Response(
267291 @testset " Testing reload connections" begin
268292 http_patch = @patch HTTP. request (args... ;kwargs... ) = nodes_response_mock
269293
270- transport = ElasticsearchClient. ElasticTransport. Transport (;hosts, options= options)
294+ transport = ElasticsearchClient. ElasticTransport. Transport (;hosts, options= options, http_client = HTTP, serializer = serializer, deserializer = deserializer )
271295
272296 apply (http_patch) do
273297 ElasticsearchClient. ElasticTransport. reload_connections! (transport)
0 commit comments