mamiya 0.0.1.alpha19 → 0.0.1.alpha20

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,127 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'json'
4
- require 'villein/event'
5
-
6
- require 'mamiya/agent/handlers/fetch'
7
-
8
- describe Mamiya::Agent::Handlers::Fetch do
9
- let(:event) do
10
- Villein::Event.new(
11
- {
12
- 'SERF_EVENT' => 'user',
13
- 'SERF_USER_EVENT' => 'mamiya:fetch',
14
- },
15
- payload: {
16
- application: 'app',
17
- package: 'package',
18
- }.to_json,
19
- )
20
- end
21
-
22
- let(:fetcher) { double('fetcher', start!: nil) }
23
- let(:serf) { double('serf', name: 'myname', event: nil) }
24
-
25
- let(:agent) do
26
- double('agent', fetcher: fetcher, serf: serf, update_tags!: nil)
27
- end
28
-
29
- subject(:handler) { described_class.new(agent, event) }
30
-
31
- before do
32
- allow(fetcher).to receive(:queue_size).and_return(0)
33
- allow(fetcher).to receive(:enqueue) do |&block|
34
- block.call
35
- end
36
- end
37
-
38
- it "enqueue a request" do
39
- expect(fetcher).to receive(:enqueue).with('app', 'package', kind_of(Hash))
40
-
41
- handler.run!
42
- end
43
-
44
- it "responds ack" do
45
- allow(fetcher).to receive(:enqueue).with('app', 'package')
46
- expect(serf).to receive(:event).with('mamiya:fetch-result:ack',
47
- {name: serf.name, application: 'app', package: 'package', pending: 1}.to_json,
48
- coalesce: false,
49
- )
50
-
51
- handler.run!
52
- end
53
-
54
- it "kicks update_tag! on start" do
55
- allow(fetcher).to receive(:enqueue) do |app, package, options, &block|
56
- options[:before].call
57
- end
58
- expect(agent).to receive(:update_tags!)
59
- handler.run!
60
- end
61
-
62
- it "reports start" do
63
- allow(fetcher).to receive(:enqueue) do |app, package, options, &block|
64
- options[:before].call
65
- end
66
- expect(serf).to receive(:event).with('mamiya:fetch-result:start',
67
- {name: serf.name, application: 'app', package: 'package', pending: 1}.to_json,
68
- coalesce: false
69
- )
70
-
71
- handler.run!
72
- end
73
-
74
- it "responds success" do
75
- callback = nil
76
- allow(fetcher).to receive(:enqueue).with('app', 'package', kind_of(Hash)) do |&block|
77
- callback = block
78
- end
79
-
80
- handler.run!
81
-
82
- expect(serf).to receive(:event).with(
83
- 'mamiya:fetch-result:success',
84
- {name: serf.name, application: 'app', package: 'package', pending: 0}.to_json,
85
- coalesce: false
86
- )
87
-
88
- callback.call
89
- end
90
-
91
- it "updates tag" do
92
- expect(agent).to receive(:update_tags!)
93
- handler.run!
94
- end
95
-
96
- context "when failed" do
97
- it "notifies error" do
98
- callback = nil
99
- allow(fetcher).to receive(:enqueue).with('app', 'package', kind_of(Hash)) do |&block|
100
- callback = block
101
- end
102
-
103
- handler.run!
104
-
105
- error = RuntimeError.new('test')
106
- expect(serf).to receive(:event).with(
107
- 'mamiya:fetch-result:error',
108
- {
109
- name: serf.name, application: 'app', package: 'package',
110
- error: error.class, pending: 0,
111
- }.to_json,
112
- coalesce: false,
113
- )
114
-
115
- callback.call(error)
116
- end
117
-
118
- it "updates tag" do
119
- allow(fetcher).to receive(:enqueue) do |&block|
120
- block.call(Exception.new)
121
- end
122
-
123
- expect(agent).to receive(:update_tags!)
124
- handler.run!
125
- end
126
- end
127
- end