fluent-plugin-github-activities 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,6 +24,7 @@ test_dir = File.join(base_dir, "test")
24
24
 
25
25
  require "test-unit"
26
26
  require "test/unit/notify"
27
+ require "webmock/test_unit"
27
28
 
28
29
  $LOAD_PATH.unshift(lib_dir)
29
30
 
@@ -20,26 +20,49 @@
20
20
  require "json"
21
21
 
22
22
  require "fluent/plugin/github-activities"
23
+ require "fluent/test"
23
24
 
24
25
  class CrawlerTest < Test::Unit::TestCase
26
+ class DummyStorage
27
+ def initialize
28
+ @store = {}
29
+ end
30
+
31
+ def get(key)
32
+ @store[key]
33
+ end
34
+
35
+ def put(key, value)
36
+ @store[key] = value
37
+ end
38
+
39
+ def save
40
+ end
41
+
42
+ def load
43
+ end
44
+ end
45
+
25
46
  def setup
26
47
  @emitted_records = []
27
48
 
28
- @crawler = ::Fluent::GithubActivities::Crawler.new(crawler_options)
49
+ @crawler = ::Fluent::Plugin::GithubActivities::Crawler.new(crawler_options)
29
50
  @crawler.on_emit = lambda do |tag, record|
30
- @emitted_records << { :tag => tag,
31
- :record => record }
51
+ @emitted_records << { tag: tag,
52
+ record: record }
32
53
  end
33
54
  @crawler.request_queue.clear
34
55
  end
35
56
 
36
57
  def crawler_options
37
58
  {
38
- :include_commits_from_pull_request => false,
39
- :include_foreign_commits => false,
40
- :watching_users => [
59
+ include_commits_from_pull_request: false,
60
+ include_foreign_commits: false,
61
+ watching_users: [
41
62
  'piroor',
42
63
  ],
64
+ log: $log,
65
+ pos_storage: DummyStorage.new
43
66
  }
44
67
  end
45
68
 
@@ -68,19 +91,19 @@ class CrawlerTest < Test::Unit::TestCase
68
91
  end
69
92
 
70
93
  REQUEST_PATTERNS = {
71
- :user_events => {
72
- :request => { :type => :events,
73
- :user => "username" },
74
- :uri => "https://api.github.com/users/username/events/public",
75
- :headers => {},
94
+ user_events: {
95
+ request: { type: :events,
96
+ user: "username" },
97
+ uri: "https://api.github.com/users/username/events/public",
98
+ headers: {},
76
99
  },
77
- :user_events_with_previous_request => {
78
- :request => { :type => :events,
79
- :user => "username",
80
- :previous_entity_tag => "aaaaa",
81
- :process_after => 29 },
82
- :uri => "https://api.github.com/users/username/events/public",
83
- :headers => {
100
+ user_events_with_previous_request: {
101
+ request: { type: :events,
102
+ user: "username",
103
+ previous_entity_tag: "aaaaa",
104
+ process_after: 29 },
105
+ uri: "https://api.github.com/users/username/events/public",
106
+ headers: {
84
107
  "If-None-Match" => "aaaaa",
85
108
  },
86
109
  },
@@ -102,10 +125,10 @@ class CrawlerTest < Test::Unit::TestCase
102
125
  def test_without_previous_response
103
126
  now = Time.now
104
127
  @crawler.reserve_user_events("username",
105
- :now => now)
128
+ now: now)
106
129
  expected_request = {
107
- :type => :events,
108
- :user => "username",
130
+ type: :events,
131
+ user: "username",
109
132
  }
110
133
  assert_equal([expected_request],
111
134
  @crawler.request_queue)
@@ -114,16 +137,16 @@ class CrawlerTest < Test::Unit::TestCase
114
137
  def test_with_previous_response
115
138
  now = Time.now
116
139
  @crawler.reserve_user_events("username",
117
- :now => now,
118
- :previous_response => {
140
+ now: now,
141
+ previous_response: {
119
142
  "ETag" => "aaaaa",
120
143
  "X-Poll-Interval" => 60,
121
144
  })
122
145
  expected_request = {
123
- :type => :events,
124
- :user => "username",
125
- :previous_entity_tag => "aaaaa",
126
- :process_after => now.to_i + 60,
146
+ type: :events,
147
+ user: "username",
148
+ previous_entity_tag: "aaaaa",
149
+ process_after: now.to_i + 60,
127
150
  }
128
151
  assert_equal([expected_request],
129
152
  @crawler.request_queue)
@@ -139,15 +162,15 @@ class CrawlerTest < Test::Unit::TestCase
139
162
  }
140
163
  @crawler.process_user_event("username", event)
141
164
  expected = {
142
- :request_queue => [],
143
- :emitted_records => [
144
- { :tag => "test",
145
- :record => fill_extra_fields(event) },
165
+ request_queue: [],
166
+ emitted_records: [
167
+ { tag: "test",
168
+ record: fill_extra_fields(event) },
146
169
  ],
147
170
  }
148
171
  assert_equal(expected,
149
- { :request_queue => @crawler.request_queue,
150
- :emitted_records => @emitted_records })
172
+ { request_queue: @crawler.request_queue,
173
+ emitted_records: @emitted_records })
151
174
  end
152
175
  end
153
176
 
@@ -160,15 +183,15 @@ class CrawlerTest < Test::Unit::TestCase
160
183
  }
161
184
  @crawler.process_user_events("username", [event])
162
185
  expected = {
163
- :request_queue => [],
164
- :emitted_records => [
165
- { :tag => "test",
166
- :record => fill_extra_fields(event) },
186
+ request_queue: [],
187
+ emitted_records: [
188
+ { tag: "test",
189
+ record: fill_extra_fields(event) },
167
190
  ],
168
191
  }
169
192
  assert_equal(expected,
170
- { :request_queue => @crawler.request_queue,
171
- :emitted_records => @emitted_records })
193
+ { request_queue: @crawler.request_queue,
194
+ emitted_records: @emitted_records })
172
195
  end
173
196
  end
174
197
 
@@ -186,18 +209,18 @@ class CrawlerTest < Test::Unit::TestCase
186
209
 
187
210
  expected_push = fill_extra_fields(expected_push)
188
211
  expected = {
189
- :request_queue => [
190
- { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
191
- :uri => "#{base}/8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
192
- :sha => "8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
193
- :push => expected_push },
212
+ request_queue: [
213
+ { type: ::Fluent::Plugin::GithubActivities::TYPE_COMMIT,
214
+ uri: "#{base}/8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
215
+ sha: "8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
216
+ push: expected_push },
194
217
  ],
195
- :emitted_records => [
218
+ emitted_records: [
196
219
  ],
197
220
  }
198
221
  assert_equal(expected,
199
- { :request_queue => @crawler.request_queue,
200
- :emitted_records => @emitted_records })
222
+ { request_queue: @crawler.request_queue,
223
+ emitted_records: @emitted_records })
201
224
  end
202
225
 
203
226
  def test_multiple_commits
@@ -213,34 +236,34 @@ class CrawlerTest < Test::Unit::TestCase
213
236
 
214
237
  expected_push = fill_extra_fields(expected_push)
215
238
  expected = {
216
- :request_queue => [
217
- { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
218
- :uri => "#{base}/c908f319c7b6d5c5a69c8b675bde40dd990ee364",
219
- :sha => "c908f319c7b6d5c5a69c8b675bde40dd990ee364",
220
- :push => expected_push },
221
- { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
222
- :uri => "#{base}/8ce6de7582376187e17e233dbae13575311a8c0b",
223
- :sha => "8ce6de7582376187e17e233dbae13575311a8c0b",
224
- :push => expected_push },
225
- { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
226
- :uri => "#{base}/c85e33bace040b7b42983e14d2b11a491d102072",
227
- :sha => "c85e33bace040b7b42983e14d2b11a491d102072",
228
- :push => expected_push },
229
- { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
230
- :uri => "#{base}/63e085b7607a3043cfbf9a866561807fbdda8a10",
231
- :sha => "63e085b7607a3043cfbf9a866561807fbdda8a10",
232
- :push => expected_push },
233
- { :type => ::Fluent::GithubActivities::TYPE_COMMIT,
234
- :uri => "#{base}/8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
235
- :sha => "8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
236
- :push => expected_push },
239
+ request_queue: [
240
+ { type: ::Fluent::Plugin::GithubActivities::TYPE_COMMIT,
241
+ uri: "#{base}/c908f319c7b6d5c5a69c8b675bde40dd990ee364",
242
+ sha: "c908f319c7b6d5c5a69c8b675bde40dd990ee364",
243
+ push: expected_push },
244
+ { type: ::Fluent::Plugin::GithubActivities::TYPE_COMMIT,
245
+ uri: "#{base}/8ce6de7582376187e17e233dbae13575311a8c0b",
246
+ sha: "8ce6de7582376187e17e233dbae13575311a8c0b",
247
+ push: expected_push },
248
+ { type: ::Fluent::Plugin::GithubActivities::TYPE_COMMIT,
249
+ uri: "#{base}/c85e33bace040b7b42983e14d2b11a491d102072",
250
+ sha: "c85e33bace040b7b42983e14d2b11a491d102072",
251
+ push: expected_push },
252
+ { type: ::Fluent::Plugin::GithubActivities::TYPE_COMMIT,
253
+ uri: "#{base}/63e085b7607a3043cfbf9a866561807fbdda8a10",
254
+ sha: "63e085b7607a3043cfbf9a866561807fbdda8a10",
255
+ push: expected_push },
256
+ { type: ::Fluent::Plugin::GithubActivities::TYPE_COMMIT,
257
+ uri: "#{base}/8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
258
+ sha: "8e90721ff5d89f52b5b3adf0b86db01f03dc5588",
259
+ push: expected_push },
237
260
  ],
238
- :emitted_records => [
261
+ emitted_records: [
239
262
  ],
240
263
  }
241
264
  assert_equal(expected,
242
- { :request_queue => @crawler.request_queue,
243
- :emitted_records => @emitted_records })
265
+ { request_queue: @crawler.request_queue,
266
+ emitted_records: @emitted_records })
244
267
  end
245
268
  end
246
269
 
@@ -249,15 +272,15 @@ class CrawlerTest < Test::Unit::TestCase
249
272
  event = JSON.parse(fixture_data("issues-event.json"))
250
273
  @crawler.process_user_event("user", event)
251
274
  expected = {
252
- :request_queue => [],
253
- :emitted_records => [
254
- { :tag => "issue-open",
255
- :record => fill_extra_fields(event) }
275
+ request_queue: [],
276
+ emitted_records: [
277
+ { tag: "issue-open",
278
+ record: fill_extra_fields(event) }
256
279
  ],
257
280
  }
258
281
  assert_equal(expected,
259
- { :request_queue => @crawler.request_queue,
260
- :emitted_records => @emitted_records })
282
+ { request_queue: @crawler.request_queue,
283
+ emitted_records: @emitted_records })
261
284
  end
262
285
  end
263
286
 
@@ -266,15 +289,15 @@ class CrawlerTest < Test::Unit::TestCase
266
289
  event = JSON.parse(fixture_data("issue-comment-event.json"))
267
290
  @crawler.process_user_event("user", event)
268
291
  expected = {
269
- :request_queue => [],
270
- :emitted_records => [
271
- { :tag => "issue-comment",
272
- :record => fill_extra_fields(event) }
292
+ request_queue: [],
293
+ emitted_records: [
294
+ { tag: "issue-comment",
295
+ record: fill_extra_fields(event) }
273
296
  ],
274
297
  }
275
298
  assert_equal(expected,
276
- { :request_queue => @crawler.request_queue,
277
- :emitted_records => @emitted_records })
299
+ { request_queue: @crawler.request_queue,
300
+ emitted_records: @emitted_records })
278
301
  end
279
302
  end
280
303
 
@@ -283,15 +306,15 @@ class CrawlerTest < Test::Unit::TestCase
283
306
  event = JSON.parse(fixture_data("commit-comment-event.json"))
284
307
  @crawler.process_user_event("user", event)
285
308
  expected = {
286
- :request_queue => [],
287
- :emitted_records => [
288
- { :tag => "commit-comment",
289
- :record => fill_extra_fields(event) }
309
+ request_queue: [],
310
+ emitted_records: [
311
+ { tag: "commit-comment",
312
+ record: fill_extra_fields(event) }
290
313
  ],
291
314
  }
292
315
  assert_equal(expected,
293
- { :request_queue => @crawler.request_queue,
294
- :emitted_records => @emitted_records })
316
+ { request_queue: @crawler.request_queue,
317
+ emitted_records: @emitted_records })
295
318
  end
296
319
  end
297
320
 
@@ -300,15 +323,15 @@ class CrawlerTest < Test::Unit::TestCase
300
323
  event = JSON.parse(fixture_data("fork-event.json"))
301
324
  @crawler.process_user_event("user", event)
302
325
  expected = {
303
- :request_queue => [],
304
- :emitted_records => [
305
- { :tag => "fork",
306
- :record => fill_extra_fields(event) }
326
+ request_queue: [],
327
+ emitted_records: [
328
+ { tag: "fork",
329
+ record: fill_extra_fields(event) }
307
330
  ],
308
331
  }
309
332
  assert_equal(expected,
310
- { :request_queue => @crawler.request_queue,
311
- :emitted_records => @emitted_records })
333
+ { request_queue: @crawler.request_queue,
334
+ emitted_records: @emitted_records })
312
335
  end
313
336
  end
314
337
 
@@ -317,15 +340,15 @@ class CrawlerTest < Test::Unit::TestCase
317
340
  event = JSON.parse(fixture_data("pull-request-event.json"))
318
341
  @crawler.process_user_event("user", event)
319
342
  expected = {
320
- :request_queue => [],
321
- :emitted_records => [
322
- { :tag => "pull-request",
323
- :record => fill_extra_fields(event) }
343
+ request_queue: [],
344
+ emitted_records: [
345
+ { tag: "pull-request",
346
+ record: fill_extra_fields(event) }
324
347
  ],
325
348
  }
326
349
  assert_equal(expected,
327
- { :request_queue => @crawler.request_queue,
328
- :emitted_records => @emitted_records })
350
+ { request_queue: @crawler.request_queue,
351
+ emitted_records: @emitted_records })
329
352
  end
330
353
  end
331
354
 
@@ -347,17 +370,17 @@ class CrawlerTest < Test::Unit::TestCase
347
370
  expected_push = fill_extra_fields(expected_push)
348
371
 
349
372
  expected = {
350
- :request_queue => [],
351
- :emitted_records => [
352
- { :tag => "commit",
353
- :record => expected_commit },
354
- { :tag => "push",
355
- :record => expected_push }
373
+ request_queue: [],
374
+ emitted_records: [
375
+ { tag: "commit",
376
+ record: expected_commit },
377
+ { tag: "push",
378
+ record: expected_push }
356
379
  ],
357
380
  }
358
381
  assert_equal(expected,
359
- { :request_queue => @crawler.request_queue,
360
- :emitted_records => @emitted_records })
382
+ { request_queue: @crawler.request_queue,
383
+ emitted_records: @emitted_records })
361
384
  end
362
385
  end
363
386
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-github-activities
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - YUKI Hiroshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-27 00:00:00.000000000 Z
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.12.0
19
+ version: 0.14.13
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 0.14.0
22
+ version: '2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.12.0
29
+ version: 0.14.13
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 0.14.0
32
+ version: '2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: webmock
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
103
117
  description: This provides ability to crawl public activities of users.
104
118
  email:
105
119
  - yuki@clear-code.com
@@ -112,7 +126,6 @@ files:
112
126
  - fluent-plugin-github-activities.gemspec
113
127
  - lib/fluent/plugin/github-activities.rb
114
128
  - lib/fluent/plugin/github-activities/crawler.rb
115
- - lib/fluent/plugin/github-activities/safe_file_writer.rb
116
129
  - lib/fluent/plugin/github-activities/users_manager.rb
117
130
  - lib/fluent/plugin/in_github-activities.rb
118
131
  - test/fixture.rb
@@ -124,11 +137,14 @@ files:
124
137
  - test/fixture/issue-comment-event.json
125
138
  - test/fixture/issues-event.json
126
139
  - test/fixture/line-note-event.json
140
+ - test/fixture/piroor-events.json
127
141
  - test/fixture/pull-request-accepted-event.json
128
142
  - test/fixture/pull-request-comment-event.json
129
143
  - test/fixture/pull-request-event.json
130
144
  - test/fixture/push-event-multiple-commits.json
131
145
  - test/fixture/push-event.json
146
+ - test/fixture/users.txt
147
+ - test/plugin/test_in_github_activity.rb
132
148
  - test/run-test.rb
133
149
  - test/test_crawler.rb
134
150
  homepage: https://github.com/clear-code/fluent-plugin-github-activities
@@ -164,11 +180,14 @@ test_files:
164
180
  - test/fixture/issue-comment-event.json
165
181
  - test/fixture/commit.json
166
182
  - test/fixture/push-event-multiple-commits.json
183
+ - test/fixture/users.txt
167
184
  - test/fixture/branch-event.json
185
+ - test/fixture/piroor-events.json
168
186
  - test/fixture/push-event.json
169
187
  - test/fixture/fork-event.json
170
188
  - test/fixture/issues-event.json
171
189
  - test/fixture/accept-pull-request-event.json
172
190
  - test/run-test.rb
173
191
  - test/fixture.rb
192
+ - test/plugin/test_in_github_activity.rb
174
193
  - test/test_crawler.rb