right_scraper 1.0.26 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. data/Gemfile +16 -0
  2. data/README.rdoc +9 -28
  3. data/Rakefile +51 -39
  4. data/lib/right_scraper/builders/base.rb +64 -0
  5. data/lib/right_scraper/builders/filesystem.rb +96 -0
  6. data/lib/right_scraper/builders/union.rb +57 -0
  7. data/lib/right_scraper/logger.rb +102 -0
  8. data/lib/right_scraper/loggers/noisy.rb +85 -0
  9. data/lib/right_scraper/processes/ssh.rb +188 -0
  10. data/lib/right_scraper/repositories/base.rb +299 -0
  11. data/lib/right_scraper/repositories/download.rb +90 -0
  12. data/lib/right_scraper/repositories/git.rb +92 -0
  13. data/lib/right_scraper/repositories/mock.rb +70 -0
  14. data/lib/right_scraper/repositories/svn.rb +96 -0
  15. data/lib/right_scraper/resources/base.rb +70 -0
  16. data/{spec/scraper_base_spec.rb → lib/right_scraper/resources/cookbook.rb} +9 -23
  17. data/lib/right_scraper/resources/workflow.rb +55 -0
  18. data/lib/right_scraper/retrievers/base.rb +114 -0
  19. data/lib/right_scraper/retrievers/checkout.rb +79 -0
  20. data/lib/right_scraper/retrievers/download.rb +97 -0
  21. data/lib/right_scraper/retrievers/git.rb +140 -0
  22. data/lib/right_scraper/retrievers/svn.rb +87 -0
  23. data/lib/right_scraper/scanners/base.rb +111 -0
  24. data/lib/right_scraper/scanners/cookbook_manifest.rb +59 -0
  25. data/lib/right_scraper/scanners/cookbook_metadata.rb +69 -0
  26. data/lib/right_scraper/scanners/cookbook_s3_upload.rb +84 -0
  27. data/lib/right_scraper/scanners/union.rb +89 -0
  28. data/lib/right_scraper/scanners/workflow_manifest.rb +86 -0
  29. data/lib/right_scraper/scanners/workflow_metadata.rb +70 -0
  30. data/lib/right_scraper/scanners/workflow_s3_upload.rb +85 -0
  31. data/lib/right_scraper/scraper.rb +81 -57
  32. data/lib/right_scraper/scraper_logger.rb +61 -0
  33. data/lib/right_scraper/scrapers/base.rb +262 -0
  34. data/lib/right_scraper/scrapers/cookbook.rb +73 -0
  35. data/lib/right_scraper/scrapers/workflow.rb +88 -0
  36. data/lib/right_scraper/svn_client.rb +101 -0
  37. data/lib/right_scraper/version.rb +28 -0
  38. data/lib/right_scraper.rb +35 -11
  39. data/right_scraper.gemspec +26 -13
  40. data/right_scraper.rconf +13 -0
  41. data/spec/builder_spec.rb +50 -0
  42. data/spec/cookbook_helper.rb +73 -0
  43. data/spec/cookbook_manifest_spec.rb +55 -0
  44. data/spec/cookbook_s3_upload_spec.rb +152 -0
  45. data/spec/download/download_retriever_spec.rb +118 -0
  46. data/spec/download/download_retriever_spec_helper.rb +72 -0
  47. data/spec/download/download_spec.rb +130 -0
  48. data/spec/download/multi_dir_spec.rb +106 -0
  49. data/spec/download/multi_dir_spec_helper.rb +40 -0
  50. data/spec/git/cookbook_spec.rb +166 -0
  51. data/spec/git/demokey +27 -0
  52. data/spec/git/demokey.pub +1 -0
  53. data/spec/git/password_key +30 -0
  54. data/spec/git/password_key.pub +1 -0
  55. data/spec/git/repository_spec.rb +110 -0
  56. data/spec/git/retriever_spec.rb +505 -0
  57. data/spec/git/retriever_spec_helper.rb +112 -0
  58. data/spec/git/scraper_spec.rb +136 -0
  59. data/spec/git/ssh_spec.rb +170 -0
  60. data/spec/git/url_spec.rb +103 -0
  61. data/spec/logger_spec.rb +185 -0
  62. data/spec/repository_spec.rb +89 -23
  63. data/spec/{scraper_spec_helper_base.rb → retriever_spec_helper.rb} +41 -27
  64. data/spec/scanner_spec.rb +61 -0
  65. data/spec/scraper_helper.rb +96 -0
  66. data/spec/scraper_spec.rb +123 -45
  67. data/spec/spec_helper.rb +87 -14
  68. data/spec/svn/cookbook_spec.rb +97 -0
  69. data/spec/svn/multi_svn_spec.rb +64 -0
  70. data/spec/svn/multi_svn_spec_helper.rb +40 -0
  71. data/spec/svn/repository_spec.rb +72 -0
  72. data/spec/svn/retriever_spec.rb +261 -0
  73. data/spec/svn/scraper_spec.rb +90 -0
  74. data/spec/svn/{svn_scraper_spec_helper.rb → svn_retriever_spec_helper.rb} +46 -27
  75. data/spec/svn/url_spec.rb +47 -0
  76. data/spec/url_spec.rb +164 -0
  77. metadata +203 -31
  78. data/lib/right_scraper/linux/process_monitor.rb +0 -84
  79. data/lib/right_scraper/repository.rb +0 -78
  80. data/lib/right_scraper/scraper_base.rb +0 -175
  81. data/lib/right_scraper/scrapers/download_scraper.rb +0 -67
  82. data/lib/right_scraper/scrapers/git_scraper.rb +0 -283
  83. data/lib/right_scraper/scrapers/svn_scraper.rb +0 -119
  84. data/lib/right_scraper/watcher.rb +0 -158
  85. data/lib/right_scraper/win32/process_monitor.rb +0 -98
  86. data/spec/download/download_scraper_spec.rb +0 -94
  87. data/spec/git/git_scraper_spec.rb +0 -165
  88. data/spec/git/git_scraper_spec_helper.rb +0 -72
  89. data/spec/rcov.opts +0 -1
  90. data/spec/spec.opts +0 -2
  91. data/spec/svn/svn_scraper_spec.rb +0 -148
  92. data/spec/watcher_spec.rb +0 -74
@@ -0,0 +1,505 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'retriever_spec_helper'))
25
+ require 'set'
26
+ require 'libarchive_ruby'
27
+
28
+ describe RightScraper::Retrievers::Git do
29
+ include RightScraper::SpecHelpers::DevelopmentModeEnvironment
30
+
31
+ include RightScraper::ScraperHelper
32
+
33
+ def secondary_cookbook(where)
34
+ FileUtils.mkdir_p(where)
35
+ @helper.create_cookbook(where, @helper.repo_content)
36
+ end
37
+
38
+ def secondary_workflow(where, name=nil, definition=nil, metadata=nil)
39
+ FileUtils.mkdir_p(where)
40
+ @helper.create_workflow(where, name || 'workflow',
41
+ definition || "sequence\n a\n b",
42
+ metadata || {"random" => 42 })
43
+ end
44
+
45
+ def get_scraper(repo, basedir)
46
+ @retriever = @retriever_class.new(repo,
47
+ :basedir => basedir,
48
+ :max_bytes => 1024**2,
49
+ :max_seconds => 20)
50
+ @retriever.retrieve
51
+ @scraper = RightScraper::Scrapers::Base.scraper(:repo_dir => @retriever.repo_dir,
52
+ :kind => :cookbook,
53
+ :repository => @retriever.repository,
54
+ :ignorable_paths => @retriever.ignorable_paths)
55
+ end
56
+
57
+ before(:all) do
58
+ @ignore = ['.git']
59
+ @retriever_class = RightScraper::Retrievers::Git
60
+ end
61
+
62
+ context 'given a git repository' do
63
+ before(:each) do
64
+ @helper = RightScraper::GitRetrieverSpecHelper.new
65
+ @repo = RightScraper::Repositories::Base.from_hash(
66
+ :display_name => 'test repo',
67
+ :repo_type => :git,
68
+ :url => @helper.repo_path)
69
+ end
70
+
71
+ after(:each) do
72
+ @helper.close unless @helper.nil?
73
+ @helper = nil
74
+ end
75
+
76
+ context 'of workflows' do
77
+
78
+ before(:each) do
79
+ @helper.setup_workflows
80
+ end
81
+
82
+ context 'with one workflow' do
83
+ include RightScraper::SpecHelpers::FromScratchScraping
84
+ include RightScraper::SpecHelpers::WorkflowScraping
85
+
86
+ it 'should scrape the master branch' do
87
+ check_resource @scraper.next_resource,
88
+ :position => 'workflow.def',
89
+ :metadata => {},
90
+ :manifest => {"workflow.def"=>"15ce480ea6c94b51056e028b0e0bd7da8024d924",
91
+ "workflow.meta"=>"5f36b2ea290645ee34d943220a14b54ee5ea5be5"}
92
+ end
93
+
94
+ it 'should only see one workflow' do
95
+ @scraper.next_resource.should_not == nil
96
+ @scraper.next_resource.should == nil
97
+ end
98
+
99
+ it 'should record the head SHA' do
100
+ tag = @scraper.next_resource.repository.tag
101
+ tag.should_not == "master"
102
+ tag.should =~ /^[A-Fa-f0-9]+$/
103
+ end
104
+ end
105
+
106
+ context 'with a subworkflow' do
107
+ before(:each) do
108
+ subdir = File.join(@helper.repo_path, "workflow")
109
+ secondary_workflow(subdir)
110
+ @helper.commit_content("subworkflow added")
111
+ end
112
+
113
+ include RightScraper::SpecHelpers::FromScratchScraping
114
+ include RightScraper::SpecHelpers::WorkflowScraping
115
+
116
+ it 'should still see only one workflow' do
117
+ @scraper.next_resource.should_not == nil
118
+ @scraper.next_resource.should == nil
119
+ end
120
+
121
+ it 'should have the subworkflow in the manifest' do
122
+ workflow = @scraper.next_resource
123
+ workflow.manifest["workflow.def"].should == "15ce480ea6c94b51056e028b0e0bd7da8024d924"
124
+ workflow.manifest["workflow.meta"].should == "5f36b2ea290645ee34d943220a14b54ee5ea5be5"
125
+ end
126
+ end
127
+
128
+ context 'with multiple workflows' do
129
+ before(:each) do
130
+ FileUtils.rm(File.join(@helper.repo_path, "workflow.meta"))
131
+ @workflow_places = [File.join(@helper.repo_path, "workflows", "first"),
132
+ File.join(@helper.repo_path, "workflows", "second"),
133
+ File.join(@helper.repo_path, "other_random_place")]
134
+ @workflow_places.each {|place| secondary_workflow(place)}
135
+ @helper.commit_content("secondary workflows added")
136
+ end
137
+
138
+ include RightScraper::SpecHelpers::FromScratchScraping
139
+ include RightScraper::SpecHelpers::WorkflowScraping
140
+
141
+ it 'should scrape' do
142
+ scraped = []
143
+ while scrape = @scraper.next_resource
144
+ place = (@workflow_places - scraped).detect {|place| File.join(@helper.repo_path, scrape.pos) == place}
145
+ scraped << place
146
+ check_resource scrape, :position => scrape.pos,
147
+ :metadata => {"random" => 42 },
148
+ :manifest => {"workflow.def" =>"e687ad52d8fba8010a255e3c2a9e891264a24910",
149
+ "workflow.meta"=>"58060413e90f84add5b2dace3ba7e30d2689336f"}
150
+ end
151
+ scraped.should have(@workflow_places.size).repositories
152
+ end
153
+
154
+ end
155
+ end
156
+
157
+ context 'of cookbooks' do
158
+
159
+ before(:each) do
160
+ @helper.setup_cookbooks
161
+ end
162
+
163
+ context 'with one cookbook' do
164
+ include RightScraper::SpecHelpers::FromScratchScraping
165
+ include RightScraper::SpecHelpers::CookbookScraping
166
+
167
+ it 'should scrape the master branch' do
168
+ check_resource @scraper.next_resource
169
+ end
170
+
171
+ it 'should only see one cookbook' do
172
+ @scraper.next_resource.should_not == nil
173
+ @scraper.next_resource.should == nil
174
+ end
175
+
176
+ it 'should record the head SHA' do
177
+ tag = @scraper.next_resource.repository.tag
178
+ tag.should_not == "master"
179
+ tag.should =~ /^[A-Fa-f0-9]+$/
180
+ end
181
+ end
182
+
183
+ context 'with a subcookbook' do
184
+ before(:each) do
185
+ subdir = File.join(@helper.repo_path, "cookbook")
186
+ secondary_cookbook(subdir)
187
+ @helper.commit_content("subcookbook added")
188
+ end
189
+
190
+ include RightScraper::SpecHelpers::FromScratchScraping
191
+ include RightScraper::SpecHelpers::CookbookScraping
192
+
193
+ it 'should still see only one cookbook' do
194
+ @scraper.next_resource.should_not == nil
195
+ @scraper.next_resource.should == nil
196
+ end
197
+
198
+ it 'should have the subcookbook in the manifest' do
199
+ cookbook = @scraper.next_resource
200
+ cookbook.manifest["cookbook/metadata.json"].should == "c2901d21c81ba5a152a37a5cfae35a8e092f7b39"
201
+ end
202
+ end
203
+
204
+ context 'with multiple cookbooks' do
205
+ before(:each) do
206
+ FileUtils.rm(File.join(@helper.repo_path, "metadata.json"))
207
+ @cookbook_places = [File.join(@helper.repo_path, "cookbooks", "first"),
208
+ File.join(@helper.repo_path, "cookbooks", "second"),
209
+ File.join(@helper.repo_path, "other_random_place")]
210
+ @cookbook_places.each {|place| secondary_cookbook(place)}
211
+ @helper.commit_content("secondary cookbooks added")
212
+ end
213
+
214
+ include RightScraper::SpecHelpers::FromScratchScraping
215
+ include RightScraper::SpecHelpers::CookbookScraping
216
+
217
+ it 'should scrape' do
218
+ scraped = []
219
+ while scrape = @scraper.next_resource
220
+ place = (@cookbook_places - scraped).detect {|place| File.join(@helper.repo_path, scrape.pos) == place}
221
+ scraped << place
222
+ check_resource scrape, :position => scrape.pos
223
+ end
224
+ scraped.should have(@cookbook_places.size).repositories
225
+ end
226
+
227
+ end
228
+
229
+ context 'and a branch' do
230
+ before(:each) do
231
+ @helper.setup_branch('test_branch', @helper.branch_content)
232
+ @repo = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
233
+ :repo_type => :git,
234
+ :url => @helper.repo_path,
235
+ :tag => 'test_branch')
236
+ end
237
+
238
+ include RightScraper::SpecHelpers::FromScratchScraping
239
+ include RightScraper::SpecHelpers::CookbookScraping
240
+
241
+ it 'should scrape a branch' do
242
+ check_resource @scraper.next_resource
243
+ end
244
+ end
245
+
246
+ context 'and a branch and a tag that are named the same' do
247
+ before(:each) do
248
+ @helper.setup_branch('test_branch')
249
+ @helper.setup_tag('test_branch')
250
+ @repo = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
251
+ :repo_type => :git,
252
+ :url => @helper.repo_path,
253
+ :tag => 'test_branch')
254
+ end
255
+
256
+ it 'should fail to scrape' do
257
+ lambda {
258
+ @scraper = get_scraper(@repo, @helper.scraper_path)
259
+ @scraper.next_resource
260
+ @scraper.close
261
+ }.should raise_exception(/Ambiguous reference/)
262
+ end
263
+ end
264
+
265
+ context 'and a tag' do
266
+ before(:each) do
267
+ @helper.setup_tag('test_tag')
268
+ @repo = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
269
+ :repo_type => :git,
270
+ :url => @helper.repo_path,
271
+ :tag => 'test_tag')
272
+ end
273
+
274
+ include RightScraper::SpecHelpers::FromScratchScraping
275
+ include RightScraper::SpecHelpers::CookbookScraping
276
+
277
+ it 'should scrape a tag' do
278
+ check_resource @scraper.next_resource
279
+ end
280
+ end
281
+
282
+ context 'and a sha ref' do
283
+ before(:each) do
284
+ @oldmetadata = @helper.repo_content
285
+ @helper.create_file_layout(@helper.repo_path, @helper.branch_content)
286
+ @helper.commit_content
287
+ @repo = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
288
+ :repo_type => :git,
289
+ :url => @helper.repo_path,
290
+ :tag => @helper.commit_id(1))
291
+ end
292
+
293
+ include RightScraper::SpecHelpers::FromScratchScraping
294
+ include RightScraper::SpecHelpers::CookbookScraping
295
+
296
+ it 'should scrape a sha' do
297
+ check_resource @scraper.next_resource, :metadata => @oldmetadata, :rootdir => @scraper.send(:repo_dir)
298
+ end
299
+ end
300
+
301
+ context 'and an incremental scraper' do
302
+
303
+ def reset_scraper
304
+ @olddir = @scraper.send(:repo_dir)
305
+ @scraper.close
306
+ @scraper = get_scraper(@repo, @helper.scraper_path)
307
+ end
308
+
309
+ before(:each) do
310
+ @scraper = get_scraper(@repo, @helper.scraper_path)
311
+ end
312
+
313
+ after(:each) do
314
+ @scraper.close
315
+ @scraper = nil
316
+ end
317
+
318
+ it 'the scraper should store intermediate versions where we expect' do
319
+ @scraper.send(:repo_dir).should begin_with @helper.scraper_path
320
+ end
321
+
322
+ it 'the scraper should scrape' do
323
+ check_resource @scraper.next_resource
324
+ end
325
+
326
+ it 'the scraper should only see one cookbook' do
327
+ @scraper.next_resource.should_not == nil
328
+ @scraper.next_resource.should == nil
329
+ end
330
+
331
+ context 'after the scraper runs once' do
332
+ before(:each) do
333
+ check_resource @scraper.next_resource
334
+ end
335
+
336
+ context 'and a branch is made on the master repo' do
337
+ before(:each) do
338
+ @helper.setup_branch("foo")
339
+ @helper.create_file_layout(@helper.repo_path, ['fredbarney'])
340
+ @helper.commit_content("branch")
341
+ @helper.setup_branch("master")
342
+ end
343
+
344
+ it 'should be able to check the new branch out' do
345
+ @repo.tag = "foo"
346
+ reset_scraper
347
+ @scraper.next_resource
348
+ File.exists?(File.join(@retriever.repo_dir, 'fredbarney')).should be_true
349
+ end
350
+ end
351
+ end
352
+
353
+ context 'when a change is made to the master repo' do
354
+ before(:each) do
355
+ @helper.create_file_layout(@helper.repo_path, @helper.branch_content)
356
+ @helper.commit_content("change to master")
357
+ @helper.create_file_layout(@helper.repo_path, ['frob'])
358
+ @helper.commit_content("alpha")
359
+ @helper.create_file_layout(@helper.repo_path, ['botz'])
360
+ @helper.commit_content("beta")
361
+ @helper.create_file_layout(@helper.repo_path, ['fred'])
362
+ @helper.commit_content("delta")
363
+ @helper.create_file_layout(@helper.repo_path, ['barney'])
364
+ @helper.commit_content("gamma")
365
+ end
366
+
367
+ context 'when a branch is made on the master repo' do
368
+ before(:each) do
369
+ @helper.setup_branch("foo")
370
+ @helper.create_file_layout(@helper.repo_path, ['fredbarney'])
371
+ @helper.commit_content("branch")
372
+ @helper.setup_branch("master")
373
+ end
374
+
375
+ context 'and a scrape happens' do
376
+ before(:each) do
377
+ reset_scraper
378
+ @scraper.next_resource
379
+ end
380
+
381
+ context 'and the branch is deleted' do
382
+ before(:each) do
383
+ @helper.delete_branch("foo")
384
+ end
385
+
386
+ context 'a new scraper' do
387
+ before(:each) do
388
+ reset_scraper
389
+ end
390
+
391
+ it 'should not see any such branch exists' do
392
+ @helper.branch?("foo").should be_false
393
+ end
394
+ end
395
+ end
396
+ end
397
+
398
+ context 'a new scraper' do
399
+ before(:each) do
400
+ reset_scraper
401
+ end
402
+
403
+ it 'should not see the new change' do
404
+ File.exists?(File.join(@olddir, 'fredbarney')).should be_false
405
+ end
406
+
407
+ it 'should note that the branch exists' do
408
+ @helper.branch?("foo").should be_true
409
+ end
410
+ end
411
+ end
412
+
413
+ context 'a new scraper' do
414
+ before(:each) do
415
+ reset_scraper
416
+ end
417
+
418
+ context 'when an incompatible change is made to the master repo' do
419
+ before(:each) do
420
+ @scraper.next_resource
421
+ end
422
+
423
+ before(:each) do
424
+ @helper.create_file_layout(@helper.repo_path, [{'other_branch_folder' => ['file7']}])
425
+ @helper.commit_content("2nd change to master")
426
+ @helper.force_rebase('master^', 'master^^^^^')
427
+ end
428
+
429
+ context 'a new scraper' do
430
+ before(:each) do
431
+ reset_scraper
432
+ end
433
+
434
+ it 'should use the same directory for files' do
435
+ @olddir.should == @scraper.send(:repo_dir)
436
+ end
437
+
438
+ it 'should see the new change' do
439
+ File.exists?(File.join(@olddir, 'other_branch_folder', 'file7')).should be_true
440
+ end
441
+
442
+ it 'should not see the middle change' do
443
+ File.exists?(File.join(@olddir, 'frob')).should_not be_true
444
+ end
445
+ end
446
+ end
447
+
448
+ it 'should use the same directory for files' do
449
+ @olddir.should == @scraper.send(:repo_dir)
450
+ end
451
+
452
+ it 'should see the new change' do
453
+ File.exists?(File.join(@olddir, 'branch_folder', 'bfile1')).should be_true
454
+ end
455
+ end
456
+
457
+ context 'with tag being an empty string' do
458
+ before(:each) do
459
+ @repo.tag = ""
460
+ end
461
+
462
+ before(:each) do
463
+ reset_scraper
464
+ end
465
+
466
+ it 'should use the same directory for files' do
467
+ @olddir.should == @scraper.send(:repo_dir)
468
+ end
469
+
470
+ it 'should see the new change' do
471
+ File.exists?(File.join(@olddir, 'branch_folder', 'bfile1')).should be_true
472
+ end
473
+ end
474
+ end
475
+ end
476
+ end
477
+ end
478
+
479
+ context 'given a remote git repository requiring a credential' do
480
+ before(:each) do
481
+ @helper = RightScraper::GitRetrieverSpecHelper.new
482
+ credential_file = File.expand_path(File.join(File.dirname(__FILE__), 'demokey'))
483
+ credential = File.open(credential_file) { |f| f.read }
484
+ @repo = RightScraper::Repositories::Base.from_hash(
485
+ :display_name => 'test repo',
486
+ :repo_type => :git,
487
+ :url => 'git@github.com:rightscale-test-account/cookbooks.git',
488
+ :first_credential => credential)
489
+ @helper.setup_cookbooks
490
+ end
491
+
492
+ after(:each) do
493
+ @helper.close unless @helper.nil?
494
+ @helper = nil
495
+ end
496
+
497
+ include RightScraper::SpecHelpers::FromScratchScraping
498
+ include RightScraper::SpecHelpers::CookbookScraping
499
+
500
+ it 'should see a cookbook' do
501
+ pending "Don't annoy GitHub unless ANNOY_GITHUB is set" unless ENV['ANNOY_GITHUB']
502
+ @scraper.next_resource.should_not be_nil
503
+ end
504
+ end
505
+ end
@@ -0,0 +1,112 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'retriever_spec_helper'))
26
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'scraper_helper'))
27
+ require 'git'
28
+
29
+ module Git
30
+ class Lib
31
+ def public_command(*args, &block)
32
+ command(*args, &block)
33
+ end
34
+ end
35
+ end
36
+ module RightScraper
37
+
38
+ # Git implementation of scraper spec helper
39
+ # See parent class for methods headers comments
40
+ class GitRetrieverSpecHelper < RetrieverSpecHelper
41
+ def initialize
42
+ super()
43
+ FileUtils.mkdir(scraper_path)
44
+ @git = Git.init(repo_path)
45
+ end
46
+
47
+ def repo
48
+ RightScraper::Repositories::Base.from_hash(:display_name => "test git repo",
49
+ :repo_type => :git,
50
+ :url => repo_path)
51
+ end
52
+
53
+ def setup_cookbooks
54
+ create_cookbook(repo_path, repo_content)
55
+ commit_content(repo_path)
56
+ end
57
+
58
+ def setup_workflows
59
+ create_workflow(repo_path, 'workflow', "sequence\na\nb", {})
60
+ commit_content(repo_path)
61
+ end
62
+
63
+ def scraper_path
64
+ File.join(@tmpdir, "scraper")
65
+ end
66
+
67
+ def commit_content(commit_message='commit')
68
+ @git.add('.')
69
+ @git.commit_all(commit_message)
70
+ end
71
+
72
+ def setup_branch(branch, new_content=nil)
73
+ @git.branch(branch).checkout
74
+ unless new_content.nil?
75
+ create_file_layout(repo_path, new_content)
76
+ @repo_content += new_content
77
+ File.open(File.join(repo_path, 'metadata.json'), 'w') { |f|
78
+ f.puts @repo_content.to_json
79
+ }
80
+ commit_content("Branch #{branch}")
81
+ end
82
+ end
83
+
84
+ def setup_tag(tag)
85
+ @git.add_tag(tag)
86
+ end
87
+
88
+ def delete_tag(tag)
89
+ @git.lib.tag(['-d', tag])
90
+ end
91
+
92
+ def branch?(branch)
93
+ Git.open(RightScraper::Retrievers::Base.repo_dir(scraper_path, repo)).branches.find {|b| b.name == branch}
94
+ end
95
+
96
+ def tag?(tag)
97
+ Git.open(RightScraper::Retrievers::Base.repo_dir(scraper_path, repo)).tags.find {|t| t.name == tag}
98
+ end
99
+
100
+ def delete_branch(branch)
101
+ @git.branch(branch).delete
102
+ end
103
+
104
+ def force_rebase(upstream, newbase)
105
+ @git.lib.public_command("rebase", ["--onto", newbase, upstream])
106
+ end
107
+
108
+ def commit_id(index_from_last=0)
109
+ @git.log.skip(1).first.sha
110
+ end
111
+ end
112
+ end