@@ -24,7 +24,8 @@ groups() ->
2424 [
2525 {non_parallel_tests , [], [
2626 tracing_test ,
27- tracing_validation_test
27+ tracing_validation_test ,
28+ trace_file_content_type_test
2829 ]}
2930 ].
3031
@@ -92,9 +93,10 @@ tracing_test(Config) ->
9293 # amqp_msg {props = # 'P_basic' {},
9394 payload = <<" Hello world" >>}),
9495
95- rabbit_ct_client_helpers :close_channel (Ch ),
96-
97- timer :sleep (100 ),
96+ rabbit_ct_helpers :await_condition (fun () ->
97+ TraceFiles = http_get (Config , " /trace-files/" ),
98+ lists :any (fun (#{name := Name }) -> Name =:= <<" test.log" >> end , TraceFiles )
99+ end ),
98100
99101 http_delete (Config , " /traces/%2f/test" , ? NO_CONTENT ),
100102 [] = http_get (Config , " /traces/%2f/" ),
@@ -128,6 +130,36 @@ tracing_validation_test(Config) ->
128130 http_delete (Config , Path , ? NO_CONTENT ),
129131 ok .
130132
133+ trace_file_content_type_test (Config ) ->
134+ case filelib :is_dir (? LOG_DIR ) of
135+ true -> {ok , Files } = file :list_dir (? LOG_DIR ),
136+ [ok = file :delete (? LOG_DIR ++ F ) || F <- Files ];
137+ _ -> ok
138+ end ,
139+
140+ Args = #{format => <<" text" >>,
141+ pattern => <<" #" >>},
142+ http_put (Config , " /traces/%2f/test-charset" , Args , ? CREATED ),
143+
144+ Ch = rabbit_ct_client_helpers :open_channel (Config ),
145+ amqp_channel :cast (Ch , # 'basic.publish' { exchange = <<" amq.topic" >>,
146+ routing_key = <<" key" >> },
147+ # amqp_msg {props = # 'P_basic' {},
148+ payload = <<" Test message" >>}),
149+
150+ rabbit_ct_helpers :await_condition (fun () ->
151+ TraceFiles = http_get (Config , " /trace-files/" ),
152+ lists :any (fun (#{name := Name }) -> Name =:= <<" test-charset.log" >> end , TraceFiles )
153+ end ),
154+
155+ http_delete (Config , " /traces/%2f/test-charset" , ? NO_CONTENT ),
156+ Headers = http_get_headers (Config , " /trace-files/test-charset.log" ),
157+ ContentType = proplists :get_value (" content-type" , Headers ),
158+ ? assertEqual (match , re :run (ContentType , " text/plain" , [{capture , none }])),
159+ ? assertEqual (match , re :run (ContentType , " charset=utf-8" , [{capture , none }])),
160+ http_delete (Config , " /trace-files/test-charset.log" , ? NO_CONTENT ),
161+ ok .
162+
131163% %---------------------------------------------------------------------------
132164% % TODO: Below is copied from rabbit_mgmt_test_http,
133165% % should be moved to use rabbit_mgmt_test_util once rabbitmq_management
@@ -154,6 +186,15 @@ http_get_raw(Config, Path, User, Pass, CodeExp) ->
154186 assert_code (CodeExp , CodeAct , " GET" , Path , ResBody ),
155187 ResBody .
156188
189+ http_get_headers (Config , Path ) ->
190+ http_get_headers (Config , Path , " guest" , " guest" , ? OK ).
191+
192+ http_get_headers (Config , Path , User , Pass , CodeExp ) ->
193+ {ok , {{_HTTP , CodeAct , _ }, Headers , ResBody }} =
194+ req (Config , get , Path , [auth_header (User , Pass )]),
195+ assert_code (CodeExp , CodeAct , " GET" , Path , ResBody ),
196+ Headers .
197+
157198http_put (Config , Path , List , CodeExp ) ->
158199 http_put_raw (Config , Path , format_for_upload (List ), CodeExp ).
159200
0 commit comments