right_scraper 3.2.6 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/right_scraper.rb +16 -34
- data/lib/right_scraper/builders.rb +32 -0
- data/lib/right_scraper/builders/base.rb +19 -20
- data/lib/right_scraper/builders/filesystem.rb +8 -6
- data/lib/right_scraper/builders/union.rb +4 -1
- data/lib/right_scraper/loggers.rb +31 -0
- data/lib/right_scraper/loggers/base.rb +113 -0
- data/lib/right_scraper/loggers/default.rb +98 -0
- data/lib/right_scraper/{scraper.rb → main.rb} +53 -9
- data/lib/right_scraper/processes.rb +33 -0
- data/lib/right_scraper/processes/shell.rb +227 -0
- data/lib/right_scraper/processes/{ssh.rb → ssh_agent.rb} +4 -0
- data/lib/right_scraper/processes/svn_client.rb +117 -0
- data/lib/right_scraper/processes/warden.rb +358 -0
- data/lib/right_scraper/registered_base.rb +154 -0
- data/lib/right_scraper/repositories.rb +33 -0
- data/lib/right_scraper/repositories/base.rb +271 -232
- data/lib/right_scraper/repositories/download.rb +8 -6
- data/lib/right_scraper/repositories/git.rb +8 -9
- data/lib/right_scraper/repositories/svn.rb +8 -8
- data/lib/right_scraper/resources.rb +32 -0
- data/lib/right_scraper/resources/base.rb +5 -1
- data/lib/right_scraper/resources/cookbook.rb +34 -27
- data/lib/right_scraper/resources/workflow.rb +27 -28
- data/lib/right_scraper/retrievers.rb +34 -0
- data/lib/right_scraper/retrievers/base.rb +80 -84
- data/lib/right_scraper/retrievers/checkout_base.rb +178 -0
- data/lib/right_scraper/retrievers/download.rb +125 -117
- data/lib/right_scraper/retrievers/git.rb +377 -223
- data/lib/right_scraper/retrievers/svn.rb +102 -62
- data/lib/right_scraper/scanners.rb +37 -0
- data/lib/right_scraper/scanners/base.rb +77 -80
- data/lib/right_scraper/scanners/cookbook_manifest.rb +31 -30
- data/lib/right_scraper/scanners/cookbook_metadata.rb +380 -35
- data/lib/right_scraper/scanners/cookbook_s3_upload.rb +56 -53
- data/lib/right_scraper/scanners/union.rb +61 -58
- data/lib/right_scraper/scanners/workflow_manifest.rb +55 -54
- data/lib/right_scraper/scanners/workflow_metadata.rb +41 -39
- data/lib/right_scraper/scanners/workflow_s3_upload.rb +59 -55
- data/lib/right_scraper/scrapers.rb +32 -0
- data/lib/right_scraper/scrapers/base.rb +217 -205
- data/lib/right_scraper/scrapers/cookbook.rb +42 -40
- data/lib/right_scraper/scrapers/workflow.rb +57 -58
- data/lib/right_scraper/version.rb +3 -0
- data/right_scraper.gemspec +12 -16
- metadata +57 -163
- data/Gemfile +0 -15
- data/Rakefile +0 -89
- data/lib/right_scraper/logger.rb +0 -107
- data/lib/right_scraper/loggers/noisy.rb +0 -85
- data/lib/right_scraper/repositories/mock.rb +0 -70
- data/lib/right_scraper/retrievers/checkout.rb +0 -79
- data/lib/right_scraper/scraper_logger.rb +0 -66
- data/lib/right_scraper/svn_client.rb +0 -164
- data/right_scraper.rconf +0 -13
- data/spec/builder_spec.rb +0 -50
- data/spec/cookbook_helper.rb +0 -73
- data/spec/cookbook_manifest_spec.rb +0 -93
- data/spec/cookbook_s3_upload_spec.rb +0 -159
- data/spec/download/download_retriever_spec.rb +0 -118
- data/spec/download/download_retriever_spec_helper.rb +0 -72
- data/spec/download/download_spec.rb +0 -128
- data/spec/download/multi_dir_spec.rb +0 -106
- data/spec/download/multi_dir_spec_helper.rb +0 -40
- data/spec/git/cookbook_spec.rb +0 -165
- data/spec/git/demokey +0 -27
- data/spec/git/demokey.pub +0 -1
- data/spec/git/password_key +0 -30
- data/spec/git/password_key.pub +0 -1
- data/spec/git/repository_spec.rb +0 -110
- data/spec/git/retriever_spec.rb +0 -553
- data/spec/git/retriever_spec_helper.rb +0 -112
- data/spec/git/scraper_spec.rb +0 -151
- data/spec/git/ssh_spec.rb +0 -174
- data/spec/git/url_spec.rb +0 -103
- data/spec/logger_spec.rb +0 -185
- data/spec/repository_spec.rb +0 -111
- data/spec/retriever_spec_helper.rb +0 -146
- data/spec/scanner_spec.rb +0 -61
- data/spec/scraper_helper.rb +0 -88
- data/spec/scraper_spec.rb +0 -147
- data/spec/spec_helper.rb +0 -185
- data/spec/svn/cookbook_spec.rb +0 -96
- data/spec/svn/multi_svn_spec.rb +0 -64
- data/spec/svn/multi_svn_spec_helper.rb +0 -40
- data/spec/svn/repository_spec.rb +0 -72
- data/spec/svn/retriever_spec.rb +0 -266
- data/spec/svn/scraper_spec.rb +0 -90
- data/spec/svn/svn_retriever_spec_helper.rb +0 -90
- data/spec/svn/url_spec.rb +0 -47
- data/spec/url_spec.rb +0 -164
data/spec/logger_spec.rb
DELETED
@@ -1,185 +0,0 @@
|
|
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 'stringio'
|
25
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
26
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'right_scraper', 'loggers', 'noisy'))
|
27
|
-
|
28
|
-
describe RightScraper::Logger do
|
29
|
-
before(:each) do
|
30
|
-
@stream = StringIO.new()
|
31
|
-
@logger = RightScraper::Logger.new(@stream)
|
32
|
-
@logger.level = Logger::WARN
|
33
|
-
end
|
34
|
-
|
35
|
-
after(:each) do
|
36
|
-
@logger.close
|
37
|
-
end
|
38
|
-
|
39
|
-
def match_log_entry(entry, type, message)
|
40
|
-
shortform, longform = case type
|
41
|
-
when Logger::DEBUG then ["D", "DEBUG"]
|
42
|
-
when Logger::INFO then ["I", "INFO"]
|
43
|
-
when Logger::WARN then ["W", "WARN"]
|
44
|
-
when Logger::ERROR then ["E", "ERROR"]
|
45
|
-
when Logger::FATAL then ["F", "FATAL"]
|
46
|
-
when Logger::FATAL then ["U", "UNKNOWN"]
|
47
|
-
end
|
48
|
-
datestamp = /[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}/
|
49
|
-
timestamp = /[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}.[[:digit:]]+/
|
50
|
-
datetimestamp = /#{datestamp}T#{timestamp}/
|
51
|
-
entry.should =~ %r{^#{shortform}, \[#{datetimestamp} \#[[:digit:]]+\] #{longform} -- : #{message}\n$}
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'should log to the stream' do
|
55
|
-
@logger.debug("foo")
|
56
|
-
@logger.info("first")
|
57
|
-
@logger.error("baz")
|
58
|
-
@logger.fatal("quux")
|
59
|
-
@stream.rewind
|
60
|
-
match_log_entry(@stream.readline, Logger::ERROR, "baz")
|
61
|
-
match_log_entry(@stream.readline, Logger::FATAL, "quux")
|
62
|
-
@stream.eof?.should be_true
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should note errors properly' do
|
66
|
-
@logger.note_error(Exception.new("foo!"), :baz)
|
67
|
-
match_log_entry(@stream.string, Logger::ERROR, "Saw foo! during baz")
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should note errors with an explanation properly' do
|
71
|
-
@logger.note_error(Exception.new("foo!"), :baz, "an explanation")
|
72
|
-
match_log_entry(@stream.string, Logger::ERROR, "Saw foo! during baz: an explanation")
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'should pass values through the block' do
|
76
|
-
result = @logger.operation(:passthrough) { 4 }
|
77
|
-
result.should == 4
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe RightScraper::Loggers::NoisyLogger do
|
82
|
-
before(:each) do
|
83
|
-
@stream = StringIO.new()
|
84
|
-
@logger = RightScraper::Loggers::NoisyLogger.new(@stream)
|
85
|
-
end
|
86
|
-
|
87
|
-
after(:each) do
|
88
|
-
@logger.close
|
89
|
-
end
|
90
|
-
|
91
|
-
def match_log_entry(entry, type, message)
|
92
|
-
shortform, longform = case type
|
93
|
-
when Logger::DEBUG then ["D", "DEBUG"]
|
94
|
-
when Logger::INFO then ["I", "INFO"]
|
95
|
-
when Logger::WARN then ["W", "WARN"]
|
96
|
-
when Logger::ERROR then ["E", "ERROR"]
|
97
|
-
when Logger::FATAL then ["F", "FATAL"]
|
98
|
-
when Logger::FATAL then ["U", "UNKNOWN"]
|
99
|
-
end
|
100
|
-
datestamp = /[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}/
|
101
|
-
timestamp = /[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}.[[:digit:]]+/
|
102
|
-
datetimestamp = /#{datestamp}T#{timestamp}/
|
103
|
-
entry.should =~ %r{^#{shortform}, \[#{datetimestamp} \#[[:digit:]]+\] #{longform} -- : #{message}\n$}
|
104
|
-
end
|
105
|
-
|
106
|
-
context 'with the level set to WARN' do
|
107
|
-
before(:each) do
|
108
|
-
@logger.level = Logger::WARN
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'should not log operations' do
|
112
|
-
@logger.operation(:foo) do
|
113
|
-
@logger.operation(:bar) do
|
114
|
-
end
|
115
|
-
end
|
116
|
-
@stream.string.should == ""
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'should note errors with context' do
|
120
|
-
begin
|
121
|
-
@logger.operation(:foo) do
|
122
|
-
@logger.operation(:bar, "blah") do
|
123
|
-
@logger.note_error("an exception", :note, "bar")
|
124
|
-
end
|
125
|
-
end
|
126
|
-
rescue
|
127
|
-
end
|
128
|
-
@stream.rewind
|
129
|
-
match_log_entry(@stream.readline, Logger::ERROR, "Saw an exception during note: bar in bar: blah in foo")
|
130
|
-
@stream.eof?.should be_true
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'should note errors when the level is set to WARN and an exception occurs' do
|
134
|
-
begin
|
135
|
-
@logger.operation(:foo) do
|
136
|
-
@logger.operation(:bar, "blah") do
|
137
|
-
raise "foo"
|
138
|
-
end
|
139
|
-
end
|
140
|
-
rescue
|
141
|
-
end
|
142
|
-
@stream.rewind
|
143
|
-
match_log_entry(@stream.readline, Logger::ERROR, "Saw foo during bar: blah in foo")
|
144
|
-
@stream.eof?.should be_true
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
context 'with the level set to DEBUG' do
|
149
|
-
before(:each) do
|
150
|
-
@logger.level = Logger::DEBUG
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'should log begin/commit' do
|
154
|
-
@logger.operation(:foo) do
|
155
|
-
@logger.operation(:bar, "blah") do
|
156
|
-
end
|
157
|
-
end
|
158
|
-
@stream.rewind
|
159
|
-
match_log_entry(@stream.readline, Logger::DEBUG, "> begin foo")
|
160
|
-
match_log_entry(@stream.readline, Logger::DEBUG, ">> begin bar: blah")
|
161
|
-
match_log_entry(@stream.readline, Logger::DEBUG, ">> commit bar: blah")
|
162
|
-
match_log_entry(@stream.readline, Logger::DEBUG, "> commit foo")
|
163
|
-
@stream.eof?.should be_true
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'should log begin/abort when an exception occurs' do
|
167
|
-
@logger.level = Logger::DEBUG
|
168
|
-
begin
|
169
|
-
@logger.operation(:foo) do
|
170
|
-
@logger.operation(:bar, "blah") do
|
171
|
-
raise "foo"
|
172
|
-
end
|
173
|
-
end
|
174
|
-
rescue
|
175
|
-
end
|
176
|
-
@stream.rewind
|
177
|
-
match_log_entry(@stream.readline, Logger::DEBUG, "> begin foo")
|
178
|
-
match_log_entry(@stream.readline, Logger::DEBUG, ">> begin bar: blah")
|
179
|
-
match_log_entry(@stream.readline, Logger::ERROR, "Saw foo during bar: blah in foo")
|
180
|
-
match_log_entry(@stream.readline, Logger::DEBUG, ">> abort bar: blah")
|
181
|
-
match_log_entry(@stream.readline, Logger::DEBUG, "> abort foo")
|
182
|
-
@stream.eof?.should be_true
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
data/spec/repository_spec.rb
DELETED
@@ -1,111 +0,0 @@
|
|
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__), '..', 'lib', 'right_scraper', 'repositories', 'mock'))
|
26
|
-
|
27
|
-
describe RightScraper::Repositories::Base do
|
28
|
-
include RightScraper::SpecHelpers::DevelopmentModeEnvironment
|
29
|
-
|
30
|
-
context 'with a repository type that doesn\'t exist' do
|
31
|
-
it 'should throw a comprehensible error when you try to create it' do
|
32
|
-
lambda {
|
33
|
-
RightScraper::Repositories::Base.from_hash(:display_name => 'display_name',
|
34
|
-
:repo_type => :nonexistent,
|
35
|
-
:url => 'url',
|
36
|
-
:tag => 'tag',
|
37
|
-
:first_credential => 'first_credential',
|
38
|
-
:second_credential => 'second_credential')
|
39
|
-
}.should raise_error(/Can't understand how to make nonexistent repos/)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'with a mock repository' do
|
44
|
-
before(:each) do
|
45
|
-
@repo = RightScraper::Repositories::Base.from_hash(:display_name => 'display_name',
|
46
|
-
:repo_type => :mock,
|
47
|
-
:url => 'url',
|
48
|
-
:tag => 'tag',
|
49
|
-
:first_credential => 'first_credential',
|
50
|
-
:second_credential => 'second_credential')
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should be initializable from a hash' do
|
54
|
-
@repo.should be_kind_of(RightScraper::Repositories::Base)
|
55
|
-
@repo.display_name.should == 'display_name'
|
56
|
-
@repo.repo_type.should == :mock
|
57
|
-
@repo.url.should == 'url'
|
58
|
-
@repo.tag.should == 'tag'
|
59
|
-
@repo.first_credential.should == 'first_credential'
|
60
|
-
@repo.second_credential.should == 'second_credential'
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should know the SHA-1 of its root location' do
|
64
|
-
@repo.repository_hash.should ==
|
65
|
-
Digest::SHA1.hexdigest("1\000mock\000url")
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should know the SHA-1 of the identifier for this specific checkout' do
|
69
|
-
@repo.checkout_hash.should ==
|
70
|
-
Digest::SHA1.hexdigest("1\000mock\000url")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe RightScraper::Repositories::Download do
|
76
|
-
include RightScraper::SpecHelpers::DevelopmentModeEnvironment
|
77
|
-
|
78
|
-
before(:each) do
|
79
|
-
@repo = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
|
80
|
-
:repo_type => :download,
|
81
|
-
:url => "http://foo.bar.baz.quux/%20CBLAH",
|
82
|
-
:tag => "412530982323",
|
83
|
-
:first_credential => "foo:b/ar",
|
84
|
-
:second_credential => "foo@bar")
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'should have a tag' do
|
88
|
-
@repo.tag.should == '412530982323'
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should include the tag in the checkout hash' do
|
92
|
-
@repo.checkout_hash.should_not == @repo.repository_hash
|
93
|
-
oldhash = @repo.checkout_hash
|
94
|
-
@repo.tag = "42398"
|
95
|
-
@repo.checkout_hash.should_not == oldhash
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should have the same repository hash with or without credentials' do
|
99
|
-
initial_hash = @repo.repository_hash
|
100
|
-
@repo.first_credential = nil
|
101
|
-
@repo.second_credential = nil
|
102
|
-
@repo.repository_hash.should == initial_hash
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'should have the same checkout hash with or without credentials' do
|
106
|
-
initial_hash = @repo.checkout_hash
|
107
|
-
@repo.first_credential = nil
|
108
|
-
@repo.second_credential = nil
|
109
|
-
@repo.checkout_hash.should == initial_hash
|
110
|
-
end
|
111
|
-
end
|
@@ -1,146 +0,0 @@
|
|
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 'digest/sha1'
|
25
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
26
|
-
require 'tmpdir'
|
27
|
-
|
28
|
-
module RightScraper
|
29
|
-
|
30
|
-
# Base class for all scrapers spec helpers
|
31
|
-
# Define helper methods used to manage repositories using each
|
32
|
-
# source control software
|
33
|
-
class RetrieverSpecHelper
|
34
|
-
|
35
|
-
include SpecHelpers
|
36
|
-
|
37
|
-
def initialize
|
38
|
-
@tmpdir = Dir.mktmpdir
|
39
|
-
FileUtils.mkdir(repo_path)
|
40
|
-
@repo_content = [ { 'folder1' => [ 'file2', 'file3' ] },
|
41
|
-
{ 'folder2' => [ { 'folder3' => [ 'file4' ] } ] },
|
42
|
-
'file1' ]
|
43
|
-
end
|
44
|
-
|
45
|
-
def close
|
46
|
-
FileUtils.remove_entry_secure @tmpdir
|
47
|
-
end
|
48
|
-
|
49
|
-
# Path to test repository
|
50
|
-
#
|
51
|
-
# === Return
|
52
|
-
# repo_path(String):: Path to test repository
|
53
|
-
def repo_path
|
54
|
-
File.join(@tmpdir, "repository")
|
55
|
-
end
|
56
|
-
|
57
|
-
# Default test repo content
|
58
|
-
#
|
59
|
-
# === Return
|
60
|
-
# content(String):: Default test repo content
|
61
|
-
attr_reader :repo_content
|
62
|
-
|
63
|
-
def manifest
|
64
|
-
hash = {}
|
65
|
-
scan(@repo_content, hash, nil)
|
66
|
-
hash['metadata.json'] = Digest::MD5.hexdigest(@repo_content.to_json + "\n")
|
67
|
-
hash
|
68
|
-
end
|
69
|
-
|
70
|
-
def scan(contents, hash, position)
|
71
|
-
contents.each do |object|
|
72
|
-
if object.instance_of?(Hash)
|
73
|
-
object.each do |key, value|
|
74
|
-
relative_position = position ? File.join(position, key) : key
|
75
|
-
scan(value, hash, relative_position)
|
76
|
-
end
|
77
|
-
else
|
78
|
-
relative_position = position ? File.join(position, object) : object
|
79
|
-
hash[relative_position] = Digest::MD5.hexdigest(object + "\n")
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
private :scan
|
84
|
-
|
85
|
-
# Test branch content
|
86
|
-
#
|
87
|
-
# === Return
|
88
|
-
# content(String):: Branch content
|
89
|
-
def branch_content
|
90
|
-
content = [ { 'branch_folder' => [ 'bfile1', 'bfile2' ] }, 'bfile3' ]
|
91
|
-
end
|
92
|
-
|
93
|
-
# Additional content used to test incremental updates
|
94
|
-
#
|
95
|
-
# === Return
|
96
|
-
# content(String):: Additional content
|
97
|
-
def additional_content
|
98
|
-
content = [ { 'additional_folder' => [ 'afile1', 'afile2' ] }, 'afile3' ]
|
99
|
-
end
|
100
|
-
|
101
|
-
# Commit any non-commited changes of given directory
|
102
|
-
#
|
103
|
-
# === Parameters
|
104
|
-
# repo_path(String):: Path to directory where commit should be created
|
105
|
-
# commit_message(String):: Optional, commit message
|
106
|
-
#
|
107
|
-
# === Raise
|
108
|
-
# Exception:: If commit command fails
|
109
|
-
def commit_content(repo_path, commit_message='Initial commit')
|
110
|
-
raise 'Not implemented'
|
111
|
-
end
|
112
|
-
|
113
|
-
# Create a branch in given repository
|
114
|
-
# Optionally adds a new commit with given file layout
|
115
|
-
# Switch to branch so that next call to 'create_file_layout' will act
|
116
|
-
# on given branch
|
117
|
-
#
|
118
|
-
# === Parameters
|
119
|
-
# branch(String):: Name of branch that should be created
|
120
|
-
# new_content(Hash):: Layout of files to be added to branch as a single commit
|
121
|
-
#
|
122
|
-
# === Return
|
123
|
-
# true:: Always return true
|
124
|
-
#
|
125
|
-
# === Raise
|
126
|
-
# Exception:: If branch command fails
|
127
|
-
def setup_branch(branch, new_content=nil)
|
128
|
-
raise 'Not implemented'
|
129
|
-
end
|
130
|
-
|
131
|
-
# Commit id for commit in test repo
|
132
|
-
# i.e. git sha or svn rev
|
133
|
-
#
|
134
|
-
# === Parameters
|
135
|
-
# index_from_last(Integer):: Commit whose id should be returned:
|
136
|
-
# - 0 means last commit
|
137
|
-
# - 1 means 1 before last
|
138
|
-
# - etc.
|
139
|
-
#
|
140
|
-
# === Return
|
141
|
-
# commit_id(String):: Corresponding commit id
|
142
|
-
def commit_id(index_from_last=0)
|
143
|
-
raise 'Not implemented'
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
data/spec/scanner_spec.rb
DELETED
@@ -1,61 +0,0 @@
|
|
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__), 'download', 'download_retriever_spec_helper'))
|
26
|
-
|
27
|
-
describe RightScraper::Scanners::Base do
|
28
|
-
include RightScraper::SpecHelpers::DevelopmentModeEnvironment
|
29
|
-
|
30
|
-
before(:each) do
|
31
|
-
@helper = RightScraper::DownloadRetrieverSpecHelper.new
|
32
|
-
@repo = @helper.repo
|
33
|
-
end
|
34
|
-
|
35
|
-
after(:each) do
|
36
|
-
@helper.close
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should be called correctly' do
|
40
|
-
scanner = flexmock("scanner")
|
41
|
-
scanner.should_receive(:new).with(Hash).once.and_return(scanner)
|
42
|
-
scanner.should_receive(:begin).with(RightScraper::Resources::Cookbook).once
|
43
|
-
scanner.should_receive(:notice_dir).with(nil).once.and_return(true)
|
44
|
-
scanner.should_receive(:notice).with("file1", Proc).once
|
45
|
-
scanner.should_receive(:notice_dir).with("folder1").once.and_return(true)
|
46
|
-
scanner.should_receive(:notice).with("folder1/file2", Proc).once
|
47
|
-
scanner.should_receive(:notice).with("folder1/file3", Proc).once
|
48
|
-
scanner.should_receive(:notice_dir).with("folder2").once.and_return(false)
|
49
|
-
scanner.should_receive(:notice).with("metadata.json", Proc).once
|
50
|
-
scanner.should_receive(:end).with(RightScraper::Resources::Cookbook).once
|
51
|
-
scanner.should_receive(:finish).with().once
|
52
|
-
|
53
|
-
@scraper = RightScraper::Scrapers::Base.scraper(:repo_dir => @helper.download_repo_path,
|
54
|
-
:kind => :cookbook,
|
55
|
-
:scanners => [scanner],
|
56
|
-
:repository => @repo)
|
57
|
-
@scraper.next_resource.should_not be_nil
|
58
|
-
@scraper.next_resource.should be_nil
|
59
|
-
@scraper.close
|
60
|
-
end
|
61
|
-
end
|