mock_gcm 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/mock_gcm/server.rb +37 -18
- data/lib/mock_gcm/version.rb +1 -1
- data/spec/mock_gcm_spec.rb +26 -12
- metadata +19 -30
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZmM2YTc2NGEyMWY2OWM0OWZmZWE2NTM3YWJhNmUwMmUxYjYwMDE5Ng==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YjY1NDJlOWUzMWY3NmVmOWE2MDVlNzQ0M2YxZGE2NDNkNDdhMWFiYg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTU0MmZmMzU4NzM5NTQ2MzM4YzRiZTFjMzFiZTg3MGNlNjE4NjY4MzUxM2Zm
|
10
|
+
YmY0NzAyM2FiYWNlMmEzMGIwMDE0ZWJiNzMwODcxMTQ0ZGQ3OGI5N2MwN2I0
|
11
|
+
OGQ5NGVjNmY0OWUzNDk2NjdhNDE1YzliOTkzYzNiOTAwYzVjMmU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjA0YThlZDE5OTkxMTgxMTI3MjE2NTZlYWM3ZGVkZDViYjQ3NTg1NmE4NzJl
|
14
|
+
ODljNTVhYzk3Mjc0MjE1OGNjODlhOTUzZTQ0NTEwZTc1Y2E0N2RiZTJlMjQ4
|
15
|
+
YzgxY2FlN2UwODVhYTljYzllZGMxMjY4OGJlMDMzODkwY2Q1ZTA=
|
data/lib/mock_gcm/server.rb
CHANGED
@@ -3,6 +3,16 @@ require 'json'
|
|
3
3
|
require 'thread'
|
4
4
|
require 'forwardable'
|
5
5
|
|
6
|
+
# Workaround bug in stdlib
|
7
|
+
HttpServer::Table.class_eval do
|
8
|
+
def initialize_with_dup(hash={})
|
9
|
+
initialize_without_dup(hash.dup)
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_method :initialize_without_dup, :initialize
|
13
|
+
alias_method :initialize, :initialize_with_dup
|
14
|
+
end
|
15
|
+
|
6
16
|
module MockGCM
|
7
17
|
class Server
|
8
18
|
extend Forwardable
|
@@ -18,7 +28,7 @@ module MockGCM
|
|
18
28
|
@server = HttpServer.new(self, port, DEFAULT_HOST, 1, File.open("/dev/null"), false, false)
|
19
29
|
|
20
30
|
# Configurable error behaviour
|
21
|
-
@
|
31
|
+
@next_request_failure = nil
|
22
32
|
@canonicals = {}
|
23
33
|
@errors = {}
|
24
34
|
end
|
@@ -27,8 +37,11 @@ module MockGCM
|
|
27
37
|
|
28
38
|
def_delegators :@server, :start, :stop, :stopped?
|
29
39
|
|
30
|
-
def mock_next_request_failure(errno)
|
31
|
-
@mutex.synchronize
|
40
|
+
def mock_next_request_failure(errno, retry_after = nil)
|
41
|
+
@mutex.synchronize do
|
42
|
+
@next_request_failure = {:errno => Integer(errno)}
|
43
|
+
@next_request_failure[:retry_after] = retry_after if retry_after
|
44
|
+
end
|
32
45
|
end
|
33
46
|
|
34
47
|
def mock_canonical_id(reg_id, canonical_reg_id)
|
@@ -61,13 +74,15 @@ module MockGCM
|
|
61
74
|
@mutex.synchronize { @received_messages.dup }
|
62
75
|
end
|
63
76
|
|
64
|
-
def add_received(reg_id, collapse_key, time_to_live, delay_while_idle, data)
|
77
|
+
def add_received(reg_id, collapse_key, time_to_live, delay_while_idle, data, dry_run, restrict_package_name)
|
65
78
|
hsh = {
|
66
|
-
'registration_id'
|
67
|
-
'collapse_key'
|
68
|
-
'time_to_live'
|
69
|
-
'delay_while_idle'
|
70
|
-
'data'
|
79
|
+
'registration_id' => reg_id.freeze,
|
80
|
+
'collapse_key' => collapse_key.freeze,
|
81
|
+
'time_to_live' => time_to_live.freeze,
|
82
|
+
'delay_while_idle' => delay_while_idle.freeze,
|
83
|
+
'data' => data.freeze,
|
84
|
+
'dry_run' => dry_run.freeze,
|
85
|
+
'restrict_package_name' => restrict_package_name.freeze
|
71
86
|
}.freeze
|
72
87
|
@mutex.synchronize { @received_messages << hsh }
|
73
88
|
end
|
@@ -75,16 +90,17 @@ module MockGCM
|
|
75
90
|
# Check stuff
|
76
91
|
|
77
92
|
def check_fail_next_request(request, response, req_data)
|
78
|
-
|
79
|
-
@
|
93
|
+
return true unless next_request_failure = @mutex.synchronize do
|
94
|
+
@next_request_failure.tap { @next_request_failure = nil }
|
80
95
|
end
|
81
96
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
true
|
97
|
+
response.status = next_request_failure[:errno]
|
98
|
+
|
99
|
+
next_request_failure[:retry_after].tap do |retry_after|
|
100
|
+
response.header['Retry-After'] = retry_after if retry_after
|
87
101
|
end
|
102
|
+
|
103
|
+
false
|
88
104
|
end
|
89
105
|
|
90
106
|
def check_authorization_header(request, response, req_data)
|
@@ -118,9 +134,11 @@ module MockGCM
|
|
118
134
|
# Optional
|
119
135
|
fail.call unless json.fetch("collapse_key", "").is_a?(String)
|
120
136
|
fail.call unless json.fetch("time_to_live", 1).is_a?(Integer)
|
137
|
+
fail.call unless json.fetch("restrict_package_name", "").is_a?(String)
|
138
|
+
fail.call unless [true,false].include?(json.fetch("dry_run", false))
|
121
139
|
fail.call unless [true,false].include?(json.fetch("delay_while_idle", false))
|
122
140
|
|
123
|
-
valid_fields = ["data", "registration_ids", "collapse_key", "time_to_live", "delay_while_idle"]
|
141
|
+
valid_fields = ["data", "registration_ids", "collapse_key", "time_to_live", "delay_while_idle", "dry_run", "restrict_package_name"]
|
124
142
|
json.keys.each do |key|
|
125
143
|
fail.call unless valid_fields.include?(key)
|
126
144
|
end
|
@@ -151,7 +169,8 @@ module MockGCM
|
|
151
169
|
success += 1
|
152
170
|
|
153
171
|
add_received(reg_id, req_json['collapse_key'], req_json['time_to_live'],
|
154
|
-
req_json['delay_while_idle'], req_json.fetch('data')
|
172
|
+
req_json['delay_while_idle'], req_json.fetch('data'),
|
173
|
+
req_json['dry_run'], req_json['restrict_package_name'])
|
155
174
|
end
|
156
175
|
end
|
157
176
|
|
data/lib/mock_gcm/version.rb
CHANGED
data/spec/mock_gcm_spec.rb
CHANGED
@@ -14,10 +14,12 @@ describe MockGCM do
|
|
14
14
|
}
|
15
15
|
let(:valid_data) {
|
16
16
|
{
|
17
|
-
"collapse_key"
|
18
|
-
"time_to_live"
|
19
|
-
"delay_while_idle"
|
20
|
-
"
|
17
|
+
"collapse_key" => "score_update",
|
18
|
+
"time_to_live" => 108,
|
19
|
+
"delay_while_idle" => true,
|
20
|
+
"restrict_package_name" => "com.google.sender",
|
21
|
+
"dry_run" => true,
|
22
|
+
"data" => {
|
21
23
|
"score" => "4x8",
|
22
24
|
"time" => "15:16.2342"
|
23
25
|
},
|
@@ -29,7 +31,7 @@ describe MockGCM do
|
|
29
31
|
after { mock_gcm.stop; sleep(0.01) until mock_gcm.stopped? }
|
30
32
|
|
31
33
|
context 'correct data' do
|
32
|
-
optional_keys = ["collapse_key", "time_to_live", "delay_while_idle"]
|
34
|
+
optional_keys = ["collapse_key", "time_to_live", "delay_while_idle", "dry_run", "restrict_package_name"]
|
33
35
|
([:all, :no] + optional_keys).each do |included_key|
|
34
36
|
it "should accept and report messages including #{included_key} optional key(s)" do
|
35
37
|
unless included_key == :all
|
@@ -56,11 +58,13 @@ describe MockGCM do
|
|
56
58
|
end
|
57
59
|
|
58
60
|
expected_report = valid_data['registration_ids'].map do |registration_id|
|
59
|
-
{ "collapse_key"
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
{ "collapse_key" => valid_data["collapse_key"],
|
62
|
+
"time_to_live" => valid_data["time_to_live"],
|
63
|
+
"delay_while_idle" => valid_data['delay_while_idle'],
|
64
|
+
"data" => valid_data["data"],
|
65
|
+
"restrict_package_name" => valid_data["restrict_package_name"],
|
66
|
+
"dry_run" => valid_data["dry_run"],
|
67
|
+
"registration_id" => registration_id }
|
64
68
|
end
|
65
69
|
mock_gcm.received_messages.should == expected_report
|
66
70
|
end
|
@@ -249,14 +253,22 @@ describe MockGCM do
|
|
249
253
|
end
|
250
254
|
end
|
251
255
|
|
256
|
+
it "should forward the retry-after param if set" do
|
257
|
+
mock_gcm.mock_next_request_failure(500, 10)
|
258
|
+
resp = http_client.post(mock_gcm_url, valid_data.to_json, headers)
|
259
|
+
resp.headers['Retry-after'].to_i.should == 10
|
260
|
+
end
|
261
|
+
|
252
262
|
it "should clear after one failure" do
|
253
|
-
mock_gcm.mock_next_request_failure(500)
|
263
|
+
mock_gcm.mock_next_request_failure(500, 10)
|
254
264
|
resp = http_client.post(mock_gcm_url, valid_data.to_json, headers)
|
255
265
|
resp.status.should == 500
|
266
|
+
resp.headers['Retry-after'].to_i.should == 10
|
256
267
|
mock_gcm.received_messages.should be_empty
|
257
268
|
|
258
269
|
resp = http_client.post(mock_gcm_url, valid_data.to_json, headers)
|
259
270
|
resp.should be_ok
|
271
|
+
resp.headers.should_not include('Retry-after')
|
260
272
|
end
|
261
273
|
|
262
274
|
end
|
@@ -293,7 +305,9 @@ describe MockGCM do
|
|
293
305
|
['registration_ids', [1]],
|
294
306
|
['time_to_live', "123"],
|
295
307
|
['collapse_key', 1],
|
296
|
-
['delay_while_idle', "1"]
|
308
|
+
['delay_while_idle', "1"],
|
309
|
+
['dry_run', "1"],
|
310
|
+
['restrict_package_name', 1]
|
297
311
|
].each do |key, value|
|
298
312
|
it "should fail (400) when #{key} = #{value.inspect} (incorrect type)" do
|
299
313
|
resp = http_client.post(mock_gcm_url, valid_data.tap { |d| d[key] = value }.to_json, headers)
|
metadata
CHANGED
@@ -1,80 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock_gcm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.1.1
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Anders Carling
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ~>
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.3'
|
15
19
|
version_requirements: !ruby/object:Gem::Requirement
|
16
20
|
requirements:
|
17
21
|
- - ~>
|
18
22
|
- !ruby/object:Gem::Version
|
19
23
|
version: '1.3'
|
20
|
-
none: false
|
21
|
-
name: bundler
|
22
24
|
type: :development
|
23
25
|
prerelease: false
|
26
|
+
name: bundler
|
27
|
+
- !ruby/object:Gem::Dependency
|
24
28
|
requirement: !ruby/object:Gem::Requirement
|
25
29
|
requirements:
|
26
|
-
- -
|
30
|
+
- - ! '>='
|
27
31
|
- !ruby/object:Gem::Version
|
28
|
-
version: '
|
29
|
-
none: false
|
30
|
-
- !ruby/object:Gem::Dependency
|
32
|
+
version: '0'
|
31
33
|
version_requirements: !ruby/object:Gem::Requirement
|
32
34
|
requirements:
|
33
35
|
- - ! '>='
|
34
36
|
- !ruby/object:Gem::Version
|
35
37
|
version: '0'
|
36
|
-
none: false
|
37
|
-
name: rake
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
|
+
name: rake
|
41
|
+
- !ruby/object:Gem::Dependency
|
40
42
|
requirement: !ruby/object:Gem::Requirement
|
41
43
|
requirements:
|
42
44
|
- - ! '>='
|
43
45
|
- !ruby/object:Gem::Version
|
44
46
|
version: '0'
|
45
|
-
none: false
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
47
|
version_requirements: !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
49
49
|
- - ! '>='
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
|
-
none: false
|
53
|
-
name: rspec
|
54
52
|
type: :development
|
55
53
|
prerelease: false
|
54
|
+
name: rspec
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - ! '>='
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
|
-
none: false
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
61
|
version_requirements: !ruby/object:Gem::Requirement
|
64
62
|
requirements:
|
65
63
|
- - ! '>='
|
66
64
|
- !ruby/object:Gem::Version
|
67
65
|
version: '0'
|
68
|
-
none: false
|
69
|
-
name: httpclient
|
70
66
|
type: :development
|
71
67
|
prerelease: false
|
72
|
-
|
73
|
-
requirements:
|
74
|
-
- - ! '>='
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '0'
|
77
|
-
none: false
|
68
|
+
name: httpclient
|
78
69
|
description: Fake GCM server for your integration testing needs
|
79
70
|
email:
|
80
71
|
- anders.carling@d05.se
|
@@ -96,6 +87,7 @@ files:
|
|
96
87
|
homepage: ''
|
97
88
|
licenses:
|
98
89
|
- MIT
|
90
|
+
metadata: {}
|
99
91
|
post_install_message:
|
100
92
|
rdoc_options: []
|
101
93
|
require_paths:
|
@@ -105,20 +97,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
97
|
- - ! '>='
|
106
98
|
- !ruby/object:Gem::Version
|
107
99
|
version: '0'
|
108
|
-
none: false
|
109
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
101
|
requirements:
|
111
102
|
- - ! '>='
|
112
103
|
- !ruby/object:Gem::Version
|
113
104
|
version: '0'
|
114
|
-
none: false
|
115
105
|
requirements: []
|
116
106
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.
|
107
|
+
rubygems_version: 2.1.9
|
118
108
|
signing_key:
|
119
|
-
specification_version:
|
109
|
+
specification_version: 4
|
120
110
|
summary: Fake GCM server for your integration testing needs
|
121
111
|
test_files:
|
122
112
|
- spec/mock_gcm_spec.rb
|
123
113
|
- spec/spec_helper.rb
|
124
|
-
has_rdoc:
|