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.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/lib/right_scraper.rb +16 -34
  3. data/lib/right_scraper/builders.rb +32 -0
  4. data/lib/right_scraper/builders/base.rb +19 -20
  5. data/lib/right_scraper/builders/filesystem.rb +8 -6
  6. data/lib/right_scraper/builders/union.rb +4 -1
  7. data/lib/right_scraper/loggers.rb +31 -0
  8. data/lib/right_scraper/loggers/base.rb +113 -0
  9. data/lib/right_scraper/loggers/default.rb +98 -0
  10. data/lib/right_scraper/{scraper.rb → main.rb} +53 -9
  11. data/lib/right_scraper/processes.rb +33 -0
  12. data/lib/right_scraper/processes/shell.rb +227 -0
  13. data/lib/right_scraper/processes/{ssh.rb → ssh_agent.rb} +4 -0
  14. data/lib/right_scraper/processes/svn_client.rb +117 -0
  15. data/lib/right_scraper/processes/warden.rb +358 -0
  16. data/lib/right_scraper/registered_base.rb +154 -0
  17. data/lib/right_scraper/repositories.rb +33 -0
  18. data/lib/right_scraper/repositories/base.rb +271 -232
  19. data/lib/right_scraper/repositories/download.rb +8 -6
  20. data/lib/right_scraper/repositories/git.rb +8 -9
  21. data/lib/right_scraper/repositories/svn.rb +8 -8
  22. data/lib/right_scraper/resources.rb +32 -0
  23. data/lib/right_scraper/resources/base.rb +5 -1
  24. data/lib/right_scraper/resources/cookbook.rb +34 -27
  25. data/lib/right_scraper/resources/workflow.rb +27 -28
  26. data/lib/right_scraper/retrievers.rb +34 -0
  27. data/lib/right_scraper/retrievers/base.rb +80 -84
  28. data/lib/right_scraper/retrievers/checkout_base.rb +178 -0
  29. data/lib/right_scraper/retrievers/download.rb +125 -117
  30. data/lib/right_scraper/retrievers/git.rb +377 -223
  31. data/lib/right_scraper/retrievers/svn.rb +102 -62
  32. data/lib/right_scraper/scanners.rb +37 -0
  33. data/lib/right_scraper/scanners/base.rb +77 -80
  34. data/lib/right_scraper/scanners/cookbook_manifest.rb +31 -30
  35. data/lib/right_scraper/scanners/cookbook_metadata.rb +380 -35
  36. data/lib/right_scraper/scanners/cookbook_s3_upload.rb +56 -53
  37. data/lib/right_scraper/scanners/union.rb +61 -58
  38. data/lib/right_scraper/scanners/workflow_manifest.rb +55 -54
  39. data/lib/right_scraper/scanners/workflow_metadata.rb +41 -39
  40. data/lib/right_scraper/scanners/workflow_s3_upload.rb +59 -55
  41. data/lib/right_scraper/scrapers.rb +32 -0
  42. data/lib/right_scraper/scrapers/base.rb +217 -205
  43. data/lib/right_scraper/scrapers/cookbook.rb +42 -40
  44. data/lib/right_scraper/scrapers/workflow.rb +57 -58
  45. data/lib/right_scraper/version.rb +3 -0
  46. data/right_scraper.gemspec +12 -16
  47. metadata +57 -163
  48. data/Gemfile +0 -15
  49. data/Rakefile +0 -89
  50. data/lib/right_scraper/logger.rb +0 -107
  51. data/lib/right_scraper/loggers/noisy.rb +0 -85
  52. data/lib/right_scraper/repositories/mock.rb +0 -70
  53. data/lib/right_scraper/retrievers/checkout.rb +0 -79
  54. data/lib/right_scraper/scraper_logger.rb +0 -66
  55. data/lib/right_scraper/svn_client.rb +0 -164
  56. data/right_scraper.rconf +0 -13
  57. data/spec/builder_spec.rb +0 -50
  58. data/spec/cookbook_helper.rb +0 -73
  59. data/spec/cookbook_manifest_spec.rb +0 -93
  60. data/spec/cookbook_s3_upload_spec.rb +0 -159
  61. data/spec/download/download_retriever_spec.rb +0 -118
  62. data/spec/download/download_retriever_spec_helper.rb +0 -72
  63. data/spec/download/download_spec.rb +0 -128
  64. data/spec/download/multi_dir_spec.rb +0 -106
  65. data/spec/download/multi_dir_spec_helper.rb +0 -40
  66. data/spec/git/cookbook_spec.rb +0 -165
  67. data/spec/git/demokey +0 -27
  68. data/spec/git/demokey.pub +0 -1
  69. data/spec/git/password_key +0 -30
  70. data/spec/git/password_key.pub +0 -1
  71. data/spec/git/repository_spec.rb +0 -110
  72. data/spec/git/retriever_spec.rb +0 -553
  73. data/spec/git/retriever_spec_helper.rb +0 -112
  74. data/spec/git/scraper_spec.rb +0 -151
  75. data/spec/git/ssh_spec.rb +0 -174
  76. data/spec/git/url_spec.rb +0 -103
  77. data/spec/logger_spec.rb +0 -185
  78. data/spec/repository_spec.rb +0 -111
  79. data/spec/retriever_spec_helper.rb +0 -146
  80. data/spec/scanner_spec.rb +0 -61
  81. data/spec/scraper_helper.rb +0 -88
  82. data/spec/scraper_spec.rb +0 -147
  83. data/spec/spec_helper.rb +0 -185
  84. data/spec/svn/cookbook_spec.rb +0 -96
  85. data/spec/svn/multi_svn_spec.rb +0 -64
  86. data/spec/svn/multi_svn_spec_helper.rb +0 -40
  87. data/spec/svn/repository_spec.rb +0 -72
  88. data/spec/svn/retriever_spec.rb +0 -266
  89. data/spec/svn/scraper_spec.rb +0 -90
  90. data/spec/svn/svn_retriever_spec_helper.rb +0 -90
  91. data/spec/svn/url_spec.rb +0 -47
  92. data/spec/url_spec.rb +0 -164
@@ -1,88 +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 'tmpdir'
26
-
27
- module RightScraper
28
- module SpecHelpers
29
- module FromScratchScraping
30
- def FromScratchScraping.included(mod)
31
- mod.module_eval do
32
- before(:each) do
33
- @basedir = Dir.mktmpdir
34
- @retriever = @retriever_class.new(@repo,
35
- :basedir => @basedir,
36
- :max_bytes => 1024**2,
37
- :max_seconds => 20)
38
- @retriever.retrieve
39
- end
40
-
41
- after(:each) do
42
- if @basedir && File.directory?(@basedir)
43
- FileUtils.remove_entry_secure(@basedir)
44
- end
45
- @scraper = nil
46
- end
47
- end
48
- end
49
- end
50
-
51
- module CookbookScraping
52
- def CookbookScraping.included(mod)
53
- mod.module_eval do
54
- before(:each) do
55
- @scraper = RightScraper::Scrapers::Base.scraper(:repo_dir => @retriever.repo_dir,
56
- :kind => :cookbook,
57
- :repository => @retriever.repository,
58
- :ignorable_paths => @retriever.ignorable_paths)
59
- end
60
- end
61
- end
62
- end
63
-
64
- module WorkflowScraping
65
- def WorkflowScraping.included(mod)
66
- mod.module_eval do
67
- before(:each) do
68
- @scraper = RightScraper::Scrapers::Base.scraper(:repo_dir => @retriever.repo_dir,
69
- :kind => :workflow,
70
- :repository => @retriever.repository,
71
- :ignorable_paths => @retriever.ignorable_paths)
72
- end
73
- end
74
- end
75
- end
76
-
77
- end
78
- module ScraperHelper
79
- def check_resource(resource, params={})
80
- position = params[:position] || "."
81
- resource.should_not == nil
82
- resource.repository.should be_an_equal_repo @repo
83
- resource.pos.should == position
84
- resource.metadata.should == (params[:metadata] || @helper.repo_content)
85
- resource.manifest.should == (params[:manifest] || @helper.manifest)
86
- end
87
- end
88
- end
data/spec/scraper_spec.rb DELETED
@@ -1,147 +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
- require 'tmpdir'
27
- require 'flexmock'
28
-
29
- describe RightScraper::Scraper do
30
- include RightScraper::SpecHelpers::DevelopmentModeEnvironment
31
-
32
- include RightScraper::SharedExamples
33
-
34
- shared_examples_for 'scrapes to given base dir' do
35
- before(:each) do
36
- @scraper = RightScraper::Scraper.new(:basedir => @tmpdir, :kind => :cookbook)
37
- end
38
-
39
- after(:each) do
40
- FileUtils.remove_entry_secure @tmpdir unless @tmpdir.nil?
41
- end
42
-
43
- it 'starts out successful' do
44
- @scraper.succeeded?.should be_true
45
- @scraper.errors.should == []
46
- end
47
-
48
- context 'given a legal download repository' do
49
- before(:each) do
50
- @helper = RightScraper::DownloadRetrieverSpecHelper.new
51
- @repo = @helper.repo
52
- end
53
-
54
- after(:each) do
55
- @helper.close
56
- end
57
-
58
- it_should_behave_like "a normal repository"
59
-
60
- it 'should log correctly as it scrapes' do
61
- callback = flexmock("callback")
62
- callback.should_receive(:call).with(:begin, :retrieving, "from #{@repo}", nil).once.ordered
63
- callback.should_receive(:call).with(:begin, :initialize, String, nil).once.ordered
64
- callback.should_receive(:call).with(:commit, :initialize, String, nil).once.ordered
65
- callback.should_receive(:call).with(:begin, :downloading, "", nil).once.ordered
66
- callback.should_receive(:call).with(:begin, :running_command, String, nil).once.ordered
67
- callback.should_receive(:call).with(:commit, :running_command, String, nil).once.ordered
68
- callback.should_receive(:call).with(:commit, :downloading, "", nil).once.ordered
69
- callback.should_receive(:call).with(:begin, :unpacking, "", nil).once.ordered
70
- callback.should_receive(:call).with(:begin, :running_command, String, nil).once.ordered
71
- callback.should_receive(:call).with(:commit, :running_command, String, nil).once.ordered
72
- callback.should_receive(:call).with(:commit, :unpacking, "", nil).once.ordered
73
- callback.should_receive(:call).with(:commit, :retrieving, "from #{@repo}", nil).once.ordered
74
- callback.should_receive(:call).with(:begin, :scraping, String, nil).once.ordered
75
- callback.should_receive(:call).with(:begin, :finding_next_cookbook, String, nil).once.ordered
76
- callback.should_receive(:call).with(:begin, :reading_cookbook, String, nil).once.ordered
77
- callback.should_receive(:call).with(:begin, :scanning_filesystem, String, nil).once.ordered
78
- callback.should_receive(:call).with(:begin, :metadata_parsing, "", nil).once.ordered
79
- callback.should_receive(:call).with(:commit, :metadata_parsing, "", nil).once.ordered
80
- callback.should_receive(:call).with(:commit, :scanning_filesystem, String, nil).once.ordered
81
- callback.should_receive(:call).with(:commit, :reading_cookbook, String, nil).once.ordered
82
- callback.should_receive(:call).with(:commit, :finding_next_cookbook, String, nil).once.ordered
83
- callback.should_receive(:call).with(:begin, :next, "", nil).once.ordered
84
- callback.should_receive(:call).with(:begin, :searching, "", nil).once.ordered
85
- callback.should_receive(:call).with(:commit, :searching, "", nil).once.ordered
86
- callback.should_receive(:call).with(:commit, :next, "", nil).once.ordered
87
- callback.should_receive(:call).with(:begin, :next, "", nil).once.ordered
88
- callback.should_receive(:call).with(:commit, :next, "", nil).once.ordered
89
- callback.should_receive(:call).with(:commit, :scraping, String, nil).once.ordered
90
- @scraper.scrape(@repo) do |phase, operation, explanation, exception|
91
- callback.call(phase, operation, explanation, exception)
92
- end
93
- @scraper.errors.should == []
94
- @scraper.succeeded?.should be_true
95
- @scraper.resources.size.should == 1
96
- end
97
- end
98
-
99
- context 'given several repositories' do
100
- it 'should continue to scrape even if errors occur' do
101
- GC.start
102
- repo = RightScraper::Repositories::Base.from_hash(:display_name => 'illegal repo',
103
- :repo_type => :download,
104
- :url => "http://example.com/foo")
105
- @scraper.scrape(repo)
106
- helpers = [RightScraper::DownloadRetrieverSpecHelper,
107
- RightScraper::DownloadRetrieverSpecHelper,
108
- RightScraper::DownloadRetrieverSpecHelper]
109
- helpers.each do |klass|
110
- helper = klass.new
111
- @scraper.scrape(helper.repo)
112
- helper.close
113
- end
114
- @scraper.succeeded?.should be_false
115
- @scraper.resources.size.should == 3
116
- @scraper.errors.size.should == 1
117
- end
118
- end
119
-
120
- it 'catches normal logging behavior' do
121
- logger = @scraper.instance_variable_get(:@logger)
122
- logger.should_not be_nil
123
- logger.info("foo")
124
- logger.error("foo")
125
- @scraper.succeeded?.should be_false
126
- @scraper.errors.should == [[nil, :log, {:severity => Logger::ERROR,
127
- :message => "foo",
128
- :progname => nil}]]
129
- end
130
- end
131
-
132
- context 'when base dir is not provided' do
133
- before(:each) do
134
- @tmpdir = nil
135
- end
136
-
137
- it_should_behave_like 'scrapes to given base dir'
138
- end
139
-
140
- context 'when base dir is provided' do
141
- before(:each) do
142
- @tmpdir = Dir.mktmpdir
143
- end
144
-
145
- it_should_behave_like 'scrapes to given base dir'
146
- end
147
- end
data/spec/spec_helper.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 'rubygems'
25
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'right_scraper'))
26
-
27
- require 'flexmock'
28
- require 'rspec'
29
- require 'find'
30
- require 'json'
31
-
32
- RSpec.configure do |c|
33
- c.mock_with(:flexmock)
34
- end
35
-
36
- ENV["DEVELOPMENT"] ||= "yes"
37
-
38
- # Helper module
39
- module RightScraper
40
-
41
- module SpecHelpers
42
- module DevelopmentModeEnvironment
43
- def DevelopmentModeEnvironment.included(mod)
44
- mod.module_eval do
45
- before(:each) do
46
- @oldtest = ENV['DEVELOPMENT']
47
- ENV['DEVELOPMENT'] = "yes"
48
- end
49
- after(:each) do
50
- if @oldtest.nil?
51
- ENV.delete('DEVELOPMENT')
52
- else
53
- ENV['DEVELOPMENT'] = @oldtest
54
- end
55
- end
56
- end
57
- end
58
- end
59
- module ProductionModeEnvironment
60
- def ProductionModeEnvironment.included(mod)
61
- mod.module_eval do
62
- before(:each) do
63
- @oldtest = ENV['DEVELOPMENT']
64
- ENV.delete('DEVELOPMENT')
65
- end
66
- after(:each) do
67
- if @oldtest.nil?
68
- ENV.delete('DEVELOPMENT')
69
- else
70
- ENV['DEVELOPMENT'] = @oldtest
71
- end
72
- end
73
- end
74
- end
75
- end
76
-
77
- # Set the 'verbose' environment variable for debugging a failing spec
78
- VERBOSE='verbose'
79
-
80
- # Execute given shell command and return output and exit code
81
- # Allows centralizing logging/output
82
- #
83
- # === Parameters
84
- # cmd(String):: Command to be run
85
- #
86
- # === Return
87
- # res, process status(Array):: Pair whose first element is the output of the command
88
- # and second element is the process exit status
89
- def exec(cmd)
90
- puts "+ [#{Dir.pwd}] #{cmd}" if ENV[VERBOSE]
91
- res = `#{cmd} 2>&1`
92
- puts res unless res.empty? if ENV[VERBOSE]
93
- return res, $?
94
- end
95
-
96
- def create_cookbook(path, contents)
97
- create_file_layout(path, contents)
98
- File.open(File.join(path, 'metadata.json'), 'w') { |f| f.puts contents.to_json }
99
- end
100
-
101
- def create_workflow(path, name, definition, metadata)
102
- File.open(File.join(path, "#{name}#{RightScraper::Resources::Workflow::DEFINITION_EXT}"), 'w') { |f| f.puts definition }
103
- File.open(File.join(path, "#{name}#{RightScraper::Resources::Workflow::METADATA_EXT}"), 'w') { |f| f.puts metadata.to_json }
104
- end
105
-
106
- # Create file layout from given array
107
- # Strings in array correspond to files while Hashes correspond to folders
108
- # File content is equal to filename
109
- #
110
- # === Parameters
111
- # Path(String):: Path where layout should be created
112
- # layout(Array):: Describe the file layout to be created
113
- #
114
- # === Return
115
- # true:: Always return true
116
- def create_file_layout(path, layout)
117
- FileUtils.mkdir_p(path)
118
- layout.each do |elem|
119
- if elem.is_a?(Hash)
120
- elem.each do |k, v|
121
- full_path = File.join(path, k)
122
- FileUtils.mkdir_p(full_path)
123
- create_file_layout(full_path, v)
124
- end
125
- else
126
- File.open(File.join(path, elem.to_s), 'w') { |f| f.puts elem.to_s }
127
- end
128
- end
129
- true
130
- end
131
-
132
- # Extract array representing file layout for given directory
133
- #
134
- # === Parameters
135
- # path(String):: Path to directory whose layout is to be retrieved
136
- # layout(Array):: Array being updated with layout, same as return value, empty array by default
137
- # ignore(Array):: Optional: Name of files or directories that should be ignored
138
- #
139
- # === Return
140
- # layout(Array):: Corresponding layout as used by 'create_file_layout'
141
- def extract_file_layout(path, ignore=[])
142
- return [] unless File.directory?(path)
143
- dirs = []
144
- files = []
145
- ignore += [ '.', '..' ]
146
- Dir.foreach(path) do |f|
147
- next if ignore.include?(f)
148
- full_path = File.join(path, f)
149
- if File.directory?(full_path)
150
- dirs << { f => extract_file_layout(full_path, ignore) }
151
- else
152
- files << f
153
- end
154
- end
155
- dirs + files.sort
156
- end
157
-
158
- RSpec::Matchers.define :begin_with do |path|
159
- match do |directory|
160
- directory[0...path.length] == path
161
- end
162
- end
163
- end
164
-
165
- module SharedExamples
166
- shared_examples_for "a normal repository" do
167
- it 'should scrape' do
168
- @scraper.scrape(@repo)
169
- @scraper.succeeded?.should be_true
170
- @scraper.resources.should_not == []
171
- @scraper.resources.size.should == 1
172
- @scraper.resources[0].manifest.should == {
173
- "folder1/file3"=>"60b91f1875424d3b4322b0fdd0529d5d",
174
- "file1"=>"5149d403009a139c7e085405ef762e1a",
175
- "folder2/folder3/file4"=>"857c6673d7149465c8ced446769b523c",
176
- "metadata.json"=>"7c72b234162002a96f4ba60f0db38601",
177
- "folder1/file2"=>"3d709e89c8ce201e3c928eb917989aef"}
178
- @scraper.resources[0].metadata.should == [{"folder1"=>["file2", "file3"]},
179
- {"folder2"=>[{"folder3"=>["file4"]}]},
180
- "file1"]
181
- end
182
- end
183
- end
184
-
185
- end
@@ -1,96 +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__), '..', 'cookbook_helper'))
26
-
27
- describe RightScraper::Resources::Cookbook do
28
- include RightScraper::SpecHelpers::DevelopmentModeEnvironment
29
-
30
- include RightScraper::CookbookHelper
31
-
32
- shared_examples_for 'svn repositories' do
33
- it_should_behave_like 'a generic repository'
34
-
35
- it 'should have the appropriate credentials' do
36
- @repository.username.should == 'username'
37
- @repository.password.should == 'password'
38
- end
39
- end
40
-
41
- context 'with a SVN repository' do
42
- before(:each) do
43
- @repository = RightScraper::Repositories::Svn.from_hash(:display_name => 'test repo',
44
- :repo_type => :svn,
45
- :url => "http://a.site/foo/bar/baz",
46
- :first_credential => "username",
47
- :second_credential => "password")
48
- end
49
-
50
- it_should_behave_like 'svn repositories'
51
-
52
- it 'should have a tag' do
53
- @repository.tag.should == "HEAD"
54
- end
55
-
56
- it 'should have a cookbook hash' do
57
- example_cookbook(@repository).resource_hash.should ==
58
- Digest::MD5.hexdigest(RightScraper::Resources::Cookbook::EMPTY_MANIFEST_JSON)
59
- end
60
-
61
- it 'should have a cookbook hash invariant under credential changes' do
62
- old_hash = example_cookbook(@repository).resource_hash
63
- @repository.first_credential = "b-key"
64
- example_cookbook(@repository).resource_hash.should == old_hash
65
- end
66
-
67
- it 'should have a cookbook hash invariant under tag changes' do
68
- old_hash = example_cookbook(@repository).resource_hash
69
- @repository.tag = "tag"
70
- example_cookbook(@repository).resource_hash.should == old_hash
71
- end
72
-
73
- it 'should have a cookbook hash invariant under position changes' do
74
- example_cookbook(@repository, "foo").resource_hash.should ==
75
- example_cookbook(@repository, "bar").resource_hash
76
- end
77
- end
78
-
79
- context 'with a SVN repository with a tag' do
80
- before(:each) do
81
- @repository = RightScraper::Repositories::Svn.from_hash(:display_name => 'test repo',
82
- :repo_type => :svn,
83
- :url => "http://a.site/foo/bar/baz",
84
- :tag => "foo",
85
- :first_credential => "username",
86
- :second_credential => "password")
87
- end
88
-
89
- it_should_behave_like 'svn repositories'
90
-
91
- it 'should have a tag' do
92
- @repository.tag.should == "foo"
93
- end
94
- end
95
-
96
- end