@@ -11,24 +11,48 @@ module Impl
11
11
subject { EventSender }
12
12
13
13
let ( :sdk_key ) { "sdk_key" }
14
- let ( :fake_data ) { '{"things":[]}' }
14
+ let ( :fake_data ) { '{"things":[],"stuff":false,"other examples":["you", "me", "us", "we"] }' }
15
15
16
- def make_sender ( server )
17
- make_sender_with_events_uri ( server . base_uri . to_s )
16
+ def make_sender ( config_options = { } )
17
+ config_options = { logger : $null_log} . merge ( config_options )
18
+ subject . new ( sdk_key , Config . new ( config_options ) , nil , 0.1 )
18
19
end
19
20
20
- def make_sender_with_events_uri ( events_uri )
21
- subject . new ( sdk_key , Config . new ( events_uri : events_uri , logger : $null_log, application : { id : "id" , version : "version" } ) , nil , 0.1 )
21
+ def with_sender_and_server ( config_options = { } )
22
+ enable_compression = config_options [ :compress_events ] || false
23
+ with_server ( enable_compression : enable_compression ) do |server |
24
+ config_options [ :events_uri ] = server . base_uri . to_s
25
+ yield make_sender ( config_options ) , server
26
+ end
22
27
end
23
28
24
- def with_sender_and_server
25
- with_server do |server |
26
- yield make_sender ( server ) , server
29
+ it "sends analytics event data without compression enabled" do
30
+ with_sender_and_server ( compress_events : false ) do |es , server |
31
+ server . setup_ok_response ( "/bulk" , "" )
32
+
33
+ result = es . send_event_data ( fake_data , "" , false )
34
+
35
+ expect ( result . success ) . to be true
36
+ expect ( result . must_shutdown ) . to be false
37
+ expect ( result . time_from_server ) . not_to be_nil
38
+
39
+ req , body = server . await_request_with_body
40
+ expect ( body ) . to eq fake_data
41
+ expect ( req . header ) . to include ( {
42
+ "authorization" => [ sdk_key ] ,
43
+ "content-type" => [ "application/json" ] ,
44
+ "user-agent" => [ "RubyClient/" + LaunchDarkly ::VERSION ] ,
45
+ "x-launchdarkly-event-schema" => [ "4" ] ,
46
+ "connection" => [ "Keep-Alive" ] ,
47
+ } )
48
+ expect ( req . header [ 'x-launchdarkly-payload-id' ] ) . not_to eq [ ]
49
+ expect ( req . header [ 'content-encoding' ] ) . to eq [ ]
50
+ expect ( req . header [ 'content-length' ] [ 0 ] . to_i ) . to eq fake_data . length
27
51
end
28
52
end
29
53
30
- it "sends analytics event data" do
31
- with_sender_and_server do |es , server |
54
+ it "sends analytics event data with compression enabled " do
55
+ with_sender_and_server ( compress_events : true ) do |es , server |
32
56
server . setup_ok_response ( "/bulk" , "" )
33
57
34
58
result = es . send_event_data ( fake_data , "" , false )
@@ -37,17 +61,18 @@ def with_sender_and_server
37
61
expect ( result . must_shutdown ) . to be false
38
62
expect ( result . time_from_server ) . not_to be_nil
39
63
40
- req = server . await_request
41
- expect ( req . body ) . to eq fake_data
64
+ req , body = server . await_request_with_body
65
+ expect ( body ) . to eq fake_data
42
66
expect ( req . header ) . to include ( {
43
67
"authorization" => [ sdk_key ] ,
68
+ "content-encoding" => [ "gzip" ] ,
44
69
"content-type" => [ "application/json" ] ,
45
70
"user-agent" => [ "RubyClient/" + LaunchDarkly ::VERSION ] ,
46
71
"x-launchdarkly-event-schema" => [ "4" ] ,
47
- "x-launchdarkly-tags" => [ "application-id/id application-version/version" ] ,
48
72
"connection" => [ "Keep-Alive" ] ,
49
73
} )
50
74
expect ( req . header [ 'x-launchdarkly-payload-id' ] ) . not_to eq [ ]
75
+ expect ( req . header [ 'content-length' ] [ 0 ] . to_i ) . to be > fake_data . length
51
76
end
52
77
end
53
78
@@ -63,8 +88,8 @@ def with_sender_and_server
63
88
result = es . send_event_data ( fake_data , "" , false )
64
89
65
90
expect ( result . success ) . to be true
66
- req = server . await_request
67
- expect ( req . body ) . to eq fake_data
91
+ req , body = server . await_request_with_body
92
+ expect ( body ) . to eq fake_data
68
93
expect ( req . host ) . to eq "fake-event-server"
69
94
end
70
95
end
@@ -123,7 +148,7 @@ def with_sender_and_server
123
148
begin
124
149
ENV [ "http_proxy" ] = proxy . base_uri . to_s
125
150
126
- es = make_sender_with_events_uri ( fake_target_uri )
151
+ es = make_sender ( events_uri : fake_target_uri )
127
152
128
153
result = es . send_event_data ( fake_data , "" , false )
129
154
0 commit comments