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
@@ -1,119 +0,0 @@
1
- #--
2
- # Copyright: Copyright (c) 2010 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
- module RightScale
25
-
26
- class SvnScraper < ScraperBase
27
-
28
- # Check whether it is possible to perform an incremental update of the repo
29
- #
30
- # === Return
31
- # true:: Scrape directory contains files belonging to the scraped repo and protocol supports
32
- # incremental updates
33
- # false:: Otherwise
34
- def incremental_update?
35
- return false unless File.directory?(@current_repo_dir)
36
- inc = false
37
- cookbooks_path = repo.cookbooks_path || []
38
- cookbooks_path = [ cookbooks_path ] unless cookbooks_path.is_a?(Array)
39
- if cookbooks_path.empty?
40
- Dir.chdir(@current_repo_dir) do
41
- info = run('svn', 'info')
42
- inc = $?.success? && info =~ (/^URL: (.*)$/) && $1 == @repo.url
43
- end
44
- else
45
- cookbooks_path.each do |path|
46
- Dir.chdir(File.join(@current_repo_dir, path)) do
47
- info = run('svn', 'info')
48
- inc = $?.success? && info =~ (/^URL: (.*)$/) && $1 == File.join(@repo.url, path)
49
- break unless inc
50
- end
51
- end
52
- end
53
- inc
54
- end
55
-
56
- # Scrape SVN repository, see RightScale::Scraper#scrape
57
- #
58
- # === Return
59
- # true:: Always return true
60
- def scrape_imp
61
- msg = @incremental ? "Updating " : "Checking out "
62
- msg += "SVN repository '#{@repo.display_name}'"
63
- @callback.call(msg, is_step=true) if @callback
64
- cookbooks_path = repo.cookbooks_path || []
65
- cookbooks_path = [ cookbooks_path ] unless cookbooks_path.is_a?(Array)
66
- if @incremental
67
- args = ['update', '--no-auth-cache', '--non-interactive', '--quiet']
68
- args += ['--revision', @repo.tag] if (!@repo.tag.nil? && !@repo.tag.empty?)
69
- args += ['--username', @repo.first_credential] if @repo.first_credential
70
- args += ['--password', @repo.second_credential] if @repo.second_credential
71
-
72
- if cookbooks_path.empty?
73
- Dir.chdir(@current_repo_dir) do
74
- res = @watcher.launch_and_watch('svn', args, @current_repo_dir)
75
- handle_watcher_result(res, 'SVN update')
76
- end
77
- else
78
- cookbooks_path.each do |path|
79
- break unless succeeded?
80
- full_path = File.join(@current_repo_dir, path)
81
- Dir.chdir(full_path) do
82
- res = @watcher.launch_and_watch('svn', args, @current_repo_dir)
83
- handle_watcher_result(res, 'SVN update')
84
- end
85
- end
86
- end
87
- end
88
- if !@incremental && succeeded?
89
- if cookbooks_path.empty?
90
- res = @watcher.launch_and_watch('svn', svn_checkout_args, @current_repo_dir)
91
- handle_watcher_result(res, 'SVN checkout')
92
- else
93
- cookbooks_path.each do |path|
94
- break unless succeeded?
95
- res = @watcher.launch_and_watch('svn', svn_checkout_args(path), @current_repo_dir)
96
- handle_watcher_result(res, 'SVN checkout')
97
- end
98
- end
99
- end
100
- true
101
- end
102
-
103
- # SVN checkout command using current repo definition and given path into it
104
- #
105
- # === Parameters
106
- # path(String):: Relative path inside repo that should be checked out
107
- #
108
- # === Return
109
- # svn_cmd(String):: Corresponding SVN command line
110
- def svn_checkout_args(path='')
111
- args = ['checkout', File.join(@repo.url, path), File.join(@current_repo_dir, path),
112
- '--no-auth-cache', '--non-interactive', '--quiet']
113
- args += ['--revision', @repo.tag] if !@repo.tag.nil? && !@repo.tag.empty?
114
- args += ['--username', @repo.first_credential] if @repo.first_credential
115
- args += ['--password', @repo.second_credential] if @repo.second_credential
116
- return args
117
- end
118
- end
119
- end
@@ -1,158 +0,0 @@
1
- #--
2
- # Copyright: Copyright (c) 2010 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 'find'
25
- if RUBY_PLATFORM =~ /mswin/
26
- require File.join(File.dirname(__FILE__), 'win32', 'process_monitor')
27
- else
28
- require File.join(File.dirname(__FILE__), 'linux', 'process_monitor')
29
- end
30
-
31
- module RightScale
32
-
33
- # Encapsulate information returned by watcher
34
- class WatchStatus
35
-
36
- # Potential outcome of watcher
37
- VALID_STATUSES = [ :success, :timeout, :size_exceeded ]
38
-
39
- attr_reader :status # One of VALID_STATUSES
40
- attr_reader :exit_code # Watched process exit code or -1 if process was killed
41
- attr_reader :output # Watched process combined output
42
-
43
- # Initialize attibutes
44
- def initialize(status, exit_code, output)
45
- @status = status
46
- @exit_code = exit_code
47
- @output = output
48
- end
49
-
50
- end
51
-
52
- class Watcher
53
-
54
- attr_reader :max_bytes # Maximum size in bytes of watched directory before process is killed
55
- attr_reader :max_seconds # Maximum number of elapased seconds before external process is killed
56
-
57
- # Initialize attributes
58
- #
59
- # max_bytes(Integer):: Maximum size in bytes of watched directory before process is killed
60
- # max_seconds(Integer):: Maximum number of elapased seconds before external process is killed
61
- def initialize(max_bytes, max_seconds)
62
- @max_bytes = max_bytes
63
- @max_seconds = max_seconds
64
- end
65
-
66
- # Launch given command as external process and watch given directory
67
- # so it doesn't exceed given size. Also watch time elapsed and kill
68
- # external process if either the size of the watched directory exceed
69
- # @max_bytes or the time elapsed exceeds @max_seconds.
70
- # Note: This method is not thread-safe, instantiate one watcher per thread
71
- #
72
- # === Parameters
73
- # cmd(String):: Command line to be launched
74
- # dest_dir(String):: Watched directory
75
- #
76
- # === Return
77
- # res(RightScale::WatchStatus):: Outcome of watch, see RightScale::WatchStatus
78
- def launch_and_watch(cmd, args, dest_dir)
79
- exit_code = nil
80
- output = ''
81
- monitor = ProcessMonitor.new
82
-
83
- # Run external process and monitor it in a new thread, platform specific
84
- pid = monitor.spawn(cmd, *args) do |data|
85
- output << data[:output] if data[:output]
86
- exit_code = data[:exit_code] if data.include?(:exit_code)
87
- end
88
-
89
- # Loop until process is done or times out or takes too much space
90
- timed_out = repeat(1, @max_seconds) do
91
- if @max_bytes < 0
92
- exit_code
93
- else
94
- size = 0
95
- Find.find(dest_dir) { |f| size += File.stat(f).size rescue 0 if File.file?(f) } if File.directory?(dest_dir)
96
- size > @max_bytes || exit_code
97
- end
98
- end
99
-
100
- # Cleanup and report status
101
- # Note: We need to store the exit status before we kill the underlying process so that
102
- # if it finished in the mean time we still report -1 as exit code
103
- if exit_code
104
- exit_status = exit_code
105
- outcome = :success
106
- else
107
- exit_status = -1
108
- outcome = (timed_out ? :timeout : :size_exceeded)
109
- Process.kill('INT', pid)
110
- end
111
-
112
- # Cleanup any open handle etc., platform specific
113
- monitor.cleanup
114
-
115
- res = WatchStatus.new(outcome, exit_status, output)
116
- end
117
-
118
- protected
119
-
120
- # Run given block in thread and time execution
121
- #
122
- # === Block
123
- # Block whose execution is timed
124
- #
125
- # === Return
126
- # elapsed(Integer):: Number of seconds elapsed while running given block
127
- def timed
128
- start_at = Time.now
129
- yield
130
- elapsed = Time.now - start_at
131
- end
132
-
133
- # Repeat given block at regular intervals
134
- #
135
- # === Parameters
136
- # seconds(Integer):: Number of seconds between executions
137
- # timeout(Integer):: Timeout after which execution stops and method returns
138
- #
139
- # === Block
140
- # Given block gets executed every period seconds until timeout is reached
141
- # *or* block returns true
142
- #
143
- # === Return
144
- # res(TrueClass|FalseClass):: true if timeout is reached, false otherwise.
145
- def repeat(period, timeout)
146
- end_at = Time.now + timeout
147
- while res = (timeout < 0 || Time.now < end_at)
148
- exit = false
149
- elapsed = timed { exit = yield }
150
- break if exit
151
- sleep(period - elapsed) if elapsed < period
152
- end
153
- !res
154
- end
155
-
156
- end
157
-
158
- end
@@ -1,98 +0,0 @@
1
- #--
2
- # Copyright: Copyright (c) 2010 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 'win32/process'
25
-
26
- module RightScale
27
-
28
- # Windows specific watcher implementation
29
- class ProcessMonitor
30
-
31
- include ::Windows::Process
32
- include ::Windows::Synchronize
33
- include ::Windows::Handle
34
-
35
- # Spawn given process and callback given block with output and exit code
36
- #
37
- # === Parameters
38
- # cmd(String):: Name of the command to run
39
- # arg1(String):: Optional, first command-line argumument
40
- # arg2(String):: Optional, first command-line argumument
41
- # ...
42
- # argN(String):: Optional, Nth command-line argumument
43
- #
44
- # === Block
45
- # Given block should take one argument which is a hash which may contain
46
- # the keys :output and :exit_code. The value associated with :output is a chunk
47
- # of output while the value associated with :exit_code is the process exit code
48
- # This block won't be called anymore once the :exit_code key has associated value
49
- #
50
- # === Return
51
- # pid(Integer):: Spawned process pid
52
- def spawn(cmd, *args)
53
- args = args.map { |a| a.to_s }
54
- cmd = ([cmd] + args).join(' ')
55
-
56
- # Run external process and monitor it in a new thread
57
- @io = IO.popen(cmd)
58
- @handle = OpenProcess(PROCESS_ALL_ACCESS, 0, @io.pid)
59
- case @handle
60
- when INVALID_HANDLE_VALUE
61
- # Something bad happened
62
- yield(:exit_code => 1)
63
- when 0
64
- # Process already finished
65
- yield(:exit_code => 0)
66
- else
67
- # Start output read
68
- @reader = Thread.new do
69
- o = @io.read
70
- until o == ''
71
- yield(:output => o)
72
- o = @io.read
73
- end
74
- status = WaitForSingleObject(@handle, INFINITE)
75
- exit_code = [0].pack('L')
76
- if GetExitCodeProcess(@handle, exit_code)
77
- exit_code = exit_code.unpack('L').first
78
- else
79
- exit_code = 1
80
- end
81
- yield(:exit_code => exit_code)
82
- end
83
- end
84
- @io.pid
85
- end
86
-
87
- # Cleanup underlying handle
88
- #
89
- # === Return
90
- # true:: Always return true
91
- def cleanup
92
- @reader.join
93
- CloseHandle(@handle) if @handle > 0
94
- @io.close
95
- end
96
-
97
- end
98
- end
@@ -1,94 +0,0 @@
1
- #--
2
- # Copyright: Copyright (c) 2010 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
- # Not supported on Windows
25
- unless RUBY_PLATFORM=~/mswin/
26
-
27
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
28
- require 'scraper_base'
29
- require 'repository'
30
- require 'watcher'
31
- require File.join('scrapers', 'download_scraper')
32
-
33
- describe RightScale::DownloadScraper do
34
-
35
- include RightScale::SpecHelpers
36
-
37
- # Create download repository following given layout
38
- # Update @repo_path with path to repository
39
- # Delete any previously created repo
40
- def setup_download_repo
41
- @download_repo_path = File.expand_path(File.join(File.dirname(__FILE__), '__download_repo'))
42
- @repo_path = File.join(File.dirname(__FILE__), '__repo')
43
- @repo_content = [ { 'folder1' => [ 'file2', 'file3' ] }, { 'folder2' => [ { 'folder3' => [ 'file4' ] } ] }, 'file1' ]
44
- FileUtils.rm_rf(@download_repo_path)
45
- create_file_layout(@download_repo_path, @repo_content)
46
- @download_file = File.expand_path(File.join(File.dirname(__FILE__), '__download_file.tar'))
47
- Dir.chdir(@download_repo_path) do
48
- res, status = exec("tar cf \"#{@download_file}\" *")
49
- raise "Failed to create tarball: #{res}" unless status.success?
50
- end
51
- end
52
-
53
- # Cleanup after ourselves
54
- def delete_download_repo
55
- FileUtils.rm_rf(@download_repo_path) if @download_repo_path
56
- @download_repo_path = nil
57
- FileUtils.rm_rf(@repo_path) if @repo_path
58
- @repo_path = nil
59
- File.delete(@download_file) if File.exist?(@download_file)
60
- end
61
-
62
- context 'given a download repository' do
63
-
64
- before(:all) do
65
- setup_download_repo
66
- end
67
-
68
- before(:each) do
69
- @scraper = RightScale::DownloadScraper.new(@repo_path, max_bytes=1024**2, max_seconds=20)
70
- @repo = RightScale::Repository.from_hash(:display_name => 'test repo',
71
- :repo_type => :download,
72
- :url => "file:///#{@download_file}")
73
- FileUtils.rm_rf(RightScale::ScraperBase.repo_dir(@repo_path, @repo))
74
- end
75
-
76
- after(:all) do
77
- delete_download_repo
78
- end
79
-
80
- it 'should scrape' do
81
- messages = []
82
- @scraper.scrape(@repo) { |m, progress| messages << m if progress }
83
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
84
- @scraper.succeeded?.should be_true
85
- messages.size.should == 1
86
- File.directory?(@scraper.current_repo_dir).should be_true
87
- extract_file_layout(@scraper.current_repo_dir).should == @repo_content
88
- end
89
-
90
- end
91
-
92
- end
93
-
94
- end # unless RUBY_PLATFORM=~/mswin/
@@ -1,165 +0,0 @@
1
- #--
2
- # Copyright: Copyright (c) 2010 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__), 'git_scraper_spec_helper'))
25
- require 'scraper_base'
26
- require 'repository'
27
- require 'watcher'
28
- require File.join('scrapers', 'git_scraper')
29
- require 'set'
30
-
31
- describe RightScale::GitScraper do
32
-
33
- context 'given a git repository' do
34
-
35
- before(:each) do
36
- @helper = RightScale::GitScraperSpecHelper.new
37
- @helper.setup_test_repo
38
- @scrape_dir = File.expand_path(File.join(File.dirname(__FILE__), '__scrape'))
39
- @scraper = RightScale::GitScraper.new(@scrape_dir, max_bytes=1024**2, max_seconds=20)
40
- @repo = RightScale::Repository.from_hash(:display_name => 'test repo',
41
- :repo_type => :git,
42
- :url => @helper.repo_path)
43
- @current_repo_dir = RightScale::ScraperBase.repo_dir(@scrape_dir, @repo)
44
- FileUtils.rm_rf(@current_repo_dir)
45
- end
46
-
47
- after(:each) do
48
- @helper.delete_test_repo
49
- FileUtils.rm_rf(@scrape_dir)
50
- end
51
-
52
- it 'should scrape the master branch' do
53
- messages = []
54
- @scraper.instance_variable_set(:@current_repo_dir, @current_repo_dir)
55
- @scraper.incremental_update?.should be_false
56
- @scraper.scrape(@repo) { |m, progress| messages << m if progress }
57
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
58
- @scraper.succeeded?.should be_true
59
- messages.size.should == 1
60
- File.directory?(@scraper.current_repo_dir).should be_true
61
- Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ])).should ==
62
- Set.new(@helper.repo_content)
63
- end
64
-
65
- it 'should scrape the master branch incrementally' do
66
- @scraper.scrape(@repo)
67
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
68
- @scraper.incremental_update?.should be_true
69
- @helper.create_file_layout(@helper.repo_path, @helper.additional_content)
70
- @helper.commit_content
71
- messages = []
72
- @scraper.scrape(@repo) { |m, progress| messages << m if progress }
73
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
74
- @scraper.succeeded?.should be_true
75
- messages.size.should == 1
76
- @scraper.instance_variable_get(:@incremental).should == true
77
- File.directory?(@scraper.current_repo_dir).should be_true
78
- Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ])).should ==
79
- Set.new(@helper.repo_content + @helper.additional_content)
80
- end
81
-
82
- context 'and a branch' do
83
-
84
- before(:each) do
85
- @helper.setup_branch('test_branch', @helper.branch_content)
86
- @branch_repo = RightScale::Repository.from_hash(:display_name => 'test repo',
87
- :repo_type => :git,
88
- :url => @helper.repo_path,
89
- :tag => 'test_branch')
90
- end
91
-
92
- it 'should scrape a branch' do
93
- messages = []
94
- @scraper.scrape(@branch_repo) { |m, progress| messages << m if progress }
95
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
96
- @scraper.succeeded?.should be_true
97
- messages.size.should == 1
98
- File.directory?(@scraper.current_repo_dir).should be_true
99
- Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ])).should ==
100
- Set.new((@helper.repo_content + @helper.branch_content))
101
- end
102
-
103
- it 'should scrape a branch incrementally' do
104
- @scraper.scrape(@branch_repo)
105
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
106
- @scraper.incremental_update?.should be_true
107
- @helper.create_file_layout(@helper.repo_path, @helper.additional_content)
108
- @helper.commit_content
109
- messages = []
110
- @scraper.scrape(@branch_repo) { |m, progress| messages << m if progress }
111
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
112
- @scraper.succeeded?.should be_true
113
- messages.size.should == 1
114
- @scraper.instance_variable_get(:@incremental).should == true
115
- File.directory?(@scraper.current_repo_dir).should be_true
116
- Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ])).should ==
117
- Set.new((@helper.repo_content + @helper.branch_content + @helper.additional_content))
118
- end
119
-
120
- end
121
-
122
- context 'and a sha ref' do
123
-
124
- before(:each) do
125
- @helper.create_file_layout(@helper.repo_path, @helper.branch_content)
126
- @helper.commit_content
127
- @sha_repo = RightScale::Repository.from_hash(:display_name => 'test repo',
128
- :repo_type => :git,
129
- :url => @helper.repo_path,
130
- :tag => @helper.commit_id(1))
131
- end
132
-
133
- it 'should scrape a sha' do
134
- messages = []
135
- @scraper.scrape(@sha_repo) { |m, progress| messages << m if progress }
136
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
137
- @scraper.succeeded?.should be_true
138
- messages.size.should == 1
139
- File.directory?(@scraper.current_repo_dir).should be_true
140
- Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ])).should ==
141
- Set.new(@helper.repo_content)
142
- end
143
-
144
- it 'should scrape a sha incrementally' do
145
- @scraper.scrape(@sha_repo)
146
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
147
- @scraper.incremental_update?.should be_true
148
- @helper.create_file_layout(@helper.repo_path, @helper.additional_content)
149
- @helper.commit_content
150
- messages = []
151
- @scraper.scrape(@sha_repo) { |m, progress| messages << m if progress }
152
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
153
- @scraper.succeeded?.should be_true
154
- messages.size.should == 1
155
- @scraper.instance_variable_get(:@incremental).should == true
156
- File.directory?(@scraper.current_repo_dir).should be_true
157
- Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ])).should ==
158
- Set.new(@helper.repo_content)
159
- end
160
-
161
- end
162
-
163
- end
164
-
165
- end