vanagon 0.11.3 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,8 +43,8 @@ class Vanagon
43
43
  # flatten all the results in to one array and set project.components to that.
44
44
  @project.components = only_build.flat_map { |comp| @project.filter_component(comp) }.uniq
45
45
  if @verbose
46
- puts "Only building:"
47
- @project.components.each { |comp| puts comp.name }
46
+ $stderr.puts "Only building:"
47
+ @project.components.each { |comp| $stderr.puts comp.name }
48
48
  end
49
49
  end
50
50
 
@@ -117,7 +117,7 @@ class Vanagon
117
117
 
118
118
  @engine.startup(@workdir)
119
119
 
120
- puts "Target is #{@engine.target}"
120
+ $stderr.puts "Target is #{@engine.target}"
121
121
  retry_task { install_build_dependencies }
122
122
  retry_task { @project.fetch_sources(@workdir) }
123
123
 
@@ -133,8 +133,8 @@ class Vanagon
133
133
  cleanup_workdir
134
134
  end
135
135
  rescue => e
136
- puts e
137
- puts e.backtrace.join("\n")
136
+ $stderr.puts e
137
+ $stderr.puts e.backtrace.join("\n")
138
138
  raise e
139
139
  ensure
140
140
  if ["hardware", "ec2"].include?(@engine.name)
@@ -148,7 +148,7 @@ class Vanagon
148
148
  raise Vanagon::Error, "Project requires a version set, all is lost."
149
149
  end
150
150
 
151
- puts "rendering Makefile"
151
+ $stderr.puts "rendering Makefile"
152
152
  retry_task { @project.fetch_sources(@workdir) }
153
153
  @project.make_bill_of_materials(@workdir)
154
154
  @project.generate_packaging_artifacts(@workdir)
@@ -159,7 +159,7 @@ class Vanagon
159
159
  @workdir = workdir ? FileUtils.mkdir_p(workdir).first : Dir.mktmpdir
160
160
  @engine.startup(@workdir)
161
161
 
162
- puts "Devkit on #{@engine.target}"
162
+ $stderr.puts "Devkit on #{@engine.target}"
163
163
 
164
164
  install_build_dependencies
165
165
  @project.fetch_sources(@workdir)
@@ -169,8 +169,8 @@ class Vanagon
169
169
  @engine.ship_workdir(@workdir)
170
170
  @engine.dispatch("(cd #{@engine.remote_workdir}; #{@platform.make} #{@project.name}-project)")
171
171
  rescue => e
172
- puts e
173
- puts e.backtrace.join("\n")
172
+ $stderr.puts e
173
+ $stderr.puts e.backtrace.join("\n")
174
174
  raise e
175
175
  end
176
176
 
@@ -57,17 +57,17 @@ class Vanagon
57
57
  end
58
58
 
59
59
  def select_target
60
- puts "Instance created id: #{instance.id}"
61
- puts "Created instance waiting for status ok"
60
+ $stderr.puts "Instance created id: #{instance.id}"
61
+ $stderr.puts "Created instance waiting for status ok"
62
62
  @ec2.wait_until(:instance_status_ok, instance_ids: [instance.id])
63
- puts "Instance running"
63
+ $stderr.puts "Instance running"
64
64
  @target = instance.private_ip_address
65
65
  rescue ::Aws::Waiters::Errors::WaiterFailed => error
66
66
  fail "Failed to wait for ec2 instance to start got error #{error}"
67
67
  end
68
68
 
69
69
  def teardown
70
- puts "Destroying instance on AWS id: #{instance.id}"
70
+ $stderr.puts "Destroying instance on AWS id: #{instance.id}"
71
71
  instances.batch_terminate!
72
72
  end
73
73
  end
@@ -23,7 +23,7 @@ class Vanagon
23
23
  Vanagon::Driver.logger.info "Polling for a lock on #{host}."
24
24
  @lockman.polling_lock(host, VANAGON_LOCK_USER, "Vanagon automated lock")
25
25
  Vanagon::Driver.logger.info "Lock acquired on #{host}."
26
- puts "Lock acquired on #{host} for #{VANAGON_LOCK_USER}."
26
+ $stderr.puts "Lock acquired on #{host} for #{VANAGON_LOCK_USER}."
27
27
  host
28
28
  end
29
29
 
@@ -33,7 +33,7 @@ class Vanagon
33
33
  Vanagon::Driver.logger.info "Attempting to lock #{h}."
34
34
  if @lockman.lock(h, VANAGON_LOCK_USER, "Vanagon automated lock")
35
35
  Vanagon::Driver.logger.info "Lock acquired on #{h}."
36
- puts "Lock acquired on #{h} for #{VANAGON_LOCK_USER}."
36
+ $stderr.puts "Lock acquired on #{h} for #{VANAGON_LOCK_USER}."
37
37
  return h
38
38
  end
39
39
  end
@@ -45,7 +45,7 @@ class Vanagon
45
45
  # complete. In this case, we'll attempt to unlock the hardware
46
46
  def teardown
47
47
  Vanagon::Driver.logger.info "Removing lock on #{@target}."
48
- puts "Removing lock on #{@target}."
48
+ $stderr.puts "Removing lock on #{@target}."
49
49
  @lockman.unlock(@target, VANAGON_LOCK_USER)
50
50
  end
51
51
 
@@ -56,7 +56,7 @@ class Vanagon
56
56
  absolute_path = File.expand_path(path)
57
57
  return nil unless File.exist?(absolute_path)
58
58
 
59
- puts "Reading vmpooler token from: #{path}"
59
+ $stderr.puts "Reading vmpooler token from: #{path}"
60
60
  File.read(absolute_path).chomp
61
61
  end
62
62
  private :read_vanagon_token
@@ -70,7 +70,7 @@ class Vanagon
70
70
  absolute_path = File.expand_path(path)
71
71
  return nil unless File.exist?(absolute_path)
72
72
 
73
- puts "Reading vmpooler token from: #{path}"
73
+ $stderr.puts "Reading vmpooler token from: #{path}"
74
74
  YAML.load_file(absolute_path)['token']
75
75
  end
76
76
  private :read_vmfloaty_token
@@ -119,7 +119,7 @@ class Vanagon
119
119
  )
120
120
  if response and response["ok"]
121
121
  Vanagon::Driver.logger.info "#{@target} has been destroyed"
122
- puts "#{@target} has been destroyed"
122
+ $stderr.puts "#{@target} has been destroyed"
123
123
  else
124
124
  Vanagon::Driver.logger.info "#{@target} could not be destroyed"
125
125
  warn "#{@target} could not be destroyed"
@@ -28,7 +28,7 @@ class Vanagon
28
28
  end
29
29
 
30
30
  opts.on('-h', '--help', 'Display help') do
31
- puts opts
31
+ $stdout.puts opts
32
32
  exit 1
33
33
  end
34
34
  end
@@ -60,6 +60,9 @@ class Vanagon
60
60
  # Stores the local path where retrieved artifacts will be saved.
61
61
  attr_accessor :output_dir
62
62
 
63
+ # Stores the local path where source artifacts will be saved.
64
+ attr_accessor :source_output_dir
65
+
63
66
  # Username to use when connecting to a build target
64
67
  attr_accessor :target_user
65
68
 
@@ -126,14 +129,13 @@ class Vanagon
126
129
  # @raise if the instance_eval on Platform fails, the exception is reraised
127
130
  def self.load_platform(name, configdir)
128
131
  platfile = File.join(configdir, "#{name}.rb")
129
- code = File.read(platfile)
130
132
  dsl = Vanagon::Platform::DSL.new(name)
131
- dsl.instance_eval(code, __FILE__, __LINE__)
133
+ dsl.instance_eval(File.read(platfile), platfile, 1)
132
134
  dsl._platform
133
135
  rescue => e
134
- puts "Error loading platform '#{name}' using '#{platfile}':"
135
- puts e
136
- puts e.backtrace.join("\n")
136
+ $stderr.puts "Error loading platform '#{name}' using '#{platfile}':"
137
+ $stderr.puts e
138
+ $stderr.puts e.backtrace.join("\n")
137
139
  raise e
138
140
  end
139
141
 
@@ -239,6 +241,17 @@ class Vanagon
239
241
  @output_dir ||= File.join(@os_name, @os_version, target_repo, @architecture)
240
242
  end
241
243
 
244
+ # Get the source dir for packages. Don't change it if it was already defined
245
+ # by the platform config. Defaults to output_dir unless specified otherwise
246
+ # (RPM specifies this)
247
+ #
248
+ # @param target_repo [String] optional repo target for built source packages
249
+ # defined at the project level
250
+ # @return [String] relative path to where source packages should be output to
251
+ def source_output_dir(target_repo = "")
252
+ @source_output_dir ||= output_dir(target_repo)
253
+ end
254
+
242
255
  # Get the value of @dist, or derive it from the value of @os_name and @os_version.
243
256
  # This is relatively RPM specific but '#codename' is defined in Platform, and that's
244
257
  # just as Deb/Ubuntu specific. All of the accessors in the top-level Platform
@@ -7,6 +7,11 @@ class Vanagon
7
7
  # @return [Array] list of commands required to build a debian package for the given project from a tarball
8
8
  def generate_package(project) # rubocop:disable Metrics/AbcSize
9
9
  target_dir = project.repo ? output_dir(project.repo) : output_dir
10
+ if project.source_artifacts
11
+ copy_extensions = '*.{deb,build,tar.gz,changes,dsc}'
12
+ else
13
+ copy_extensions = '*.deb'
14
+ end
10
15
  pkg_arch_opt = project.noarch ? "" : "-a#{@architecture}"
11
16
  ["mkdir -p output/#{target_dir}",
12
17
  "mkdir -p $(tempdir)/#{project.name}-#{project.version}",
@@ -16,7 +21,7 @@ class Vanagon
16
21
  "gunzip -c #{project.name}-#{project.version}.tar.gz | '#{@tar}' -C '$(tempdir)/#{project.name}-#{project.version}' --strip-components 1 -xf -",
17
22
  "sed -i 's/\ /?/g' $(tempdir)/#{project.name}-#{project.version}/debian/install",
18
23
  "(cd $(tempdir)/#{project.name}-#{project.version}; debuild --no-lintian #{pkg_arch_opt} -uc -us)",
19
- "cp $(tempdir)/*.deb ./output/#{target_dir}"]
24
+ "cp $(tempdir)/#{copy_extensions} ./output/#{target_dir}"]
20
25
  end
21
26
 
22
27
  # Method to generate the files required to build a debian package for the project
@@ -348,6 +348,10 @@ class Vanagon
348
348
  @platform.output_dir = directory
349
349
  end
350
350
 
351
+ def source_output_dir(directory)
352
+ @platform.source_output_dir = directory
353
+ end
354
+
351
355
  # Helper to setup a apt repository on a target system
352
356
  #
353
357
  # @param definition [String] the repo setup file, must be a valid uri, fetched with curl
@@ -8,15 +8,24 @@ class Vanagon
8
8
  #
9
9
  # @param project [Vanagon::Project] project to build an rpm package of
10
10
  # @return [Array] list of commands required to build an rpm package for the given project from a tarball
11
- def generate_package(project)
11
+ def generate_package(project) # rubocop:disable Metrics/AbcSize
12
12
  target_dir = project.repo ? output_dir(project.repo) : output_dir
13
+ target_source_output_dir = project.repo ? source_output_dir(project.repo) : source_output_dir
14
+ if project.source_artifacts
15
+ rpmbuild = "#{@rpmbuild} -ba"
16
+ artifact_copy = "mkdir -p output/#{target_source_output_dir}; cp $(tempdir)/rpmbuild/RPMS/**/*.rpm ./output/#{target_dir}; cp $(tempdir)/rpmbuild/SRPMS/*.rpm ./output/#{target_source_output_dir}"
17
+ else
18
+ rpmbuild = "#{@rpmbuild} -bb"
19
+ artifact_copy = "cp $(tempdir)/rpmbuild/*RPMS/**/*.rpm ./output/#{target_dir}"
20
+ end
21
+
13
22
  ["bash -c 'mkdir -p $(tempdir)/rpmbuild/{SOURCES,SPECS,BUILD,RPMS,SRPMS}'",
14
23
  "cp #{project.name}-#{project.version}.tar.gz $(tempdir)/rpmbuild/SOURCES",
15
24
  "cp file-list-for-rpm $(tempdir)/rpmbuild/SOURCES",
16
25
  "cp #{project.name}.spec $(tempdir)/rpmbuild/SPECS",
17
- "PATH=/opt/freeware/bin:$$PATH #{@rpmbuild} -bb --target #{@architecture} #{rpm_defines} $(tempdir)/rpmbuild/SPECS/#{project.name}.spec",
26
+ "PATH=/opt/freeware/bin:$$PATH #{rpmbuild} --target #{@architecture} #{rpm_defines} $(tempdir)/rpmbuild/SPECS/#{project.name}.spec",
18
27
  "mkdir -p output/#{target_dir}",
19
- "cp $(tempdir)/rpmbuild/*RPMS/**/*.rpm ./output/#{target_dir}"]
28
+ artifact_copy]
20
29
  end
21
30
 
22
31
  # Method to generate the files required to build an rpm package for the project
@@ -40,6 +49,13 @@ class Vanagon
40
49
  super
41
50
  end
42
51
 
52
+ # Method to derive the directory for source artifacts
53
+ #
54
+ # @param target_repo [String] repo the source artifacts are targeting
55
+ def source_output_dir(target_repo = "products")
56
+ @source_output_dir ||= File.join(@os_name, @os_version, target_repo, 'SRPMS')
57
+ end
58
+
43
59
  def rpm_defines
44
60
  defines = %(--define '_topdir $(tempdir)/rpmbuild' )
45
61
  # RPM doesn't allow dashes in the os_name. This was added to
@@ -80,6 +80,9 @@ class Vanagon
80
80
  # them to appear in your spec/rules files!
81
81
  attr_accessor :package_overrides
82
82
 
83
+ # Should we include source packages?
84
+ attr_accessor :source_artifacts
85
+
83
86
  # Loads a given project from the configdir
84
87
  #
85
88
  # @param name [String] the name of the project
@@ -90,14 +93,13 @@ class Vanagon
90
93
  # @raise if the instance_eval on Project fails, the exception is reraised
91
94
  def self.load_project(name, configdir, platform, include_components = [])
92
95
  projfile = File.join(configdir, "#{name}.rb")
93
- code = File.read(projfile)
94
96
  dsl = Vanagon::Project::DSL.new(name, platform, include_components)
95
- dsl.instance_eval(code, __FILE__, __LINE__)
97
+ dsl.instance_eval(File.read(projfile), projfile, 1)
96
98
  dsl._project
97
99
  rescue => e
98
- puts "Error loading project '#{name}' using '#{projfile}':"
99
- puts e
100
- puts e.backtrace.join("\n")
100
+ $stderr.puts "Error loading project '#{name}' using '#{projfile}':"
101
+ $stderr.puts e
102
+ $stderr.puts e.backtrace.join("\n")
101
103
  raise e
102
104
  end
103
105
 
@@ -122,6 +124,7 @@ class Vanagon
122
124
  @provides = []
123
125
  @conflicts = []
124
126
  @package_overrides = []
127
+ @source_artifacts = false
125
128
  end
126
129
 
127
130
  # Magic getter to retrieve settings in the project
@@ -148,6 +148,15 @@ class Vanagon
148
148
  @project.release = rel
149
149
  end
150
150
 
151
+ # Generate source packages in addition to binary packages.
152
+ # Currently only implemented for rpm/deb packages.
153
+ #
154
+ # @param source_artifacts [Boolean] whether or not to output
155
+ # source packages
156
+ def generate_source_artifacts(source_artifacts)
157
+ @project.source_artifacts = source_artifacts
158
+ end
159
+
151
160
  # Sets the version for the project based on a git describe of the
152
161
  # directory that holds the configs. Requires that a git tag be present
153
162
  # and reachable from the current commit in that repository.
@@ -228,7 +237,7 @@ class Vanagon
228
237
  #
229
238
  # @param name [String] name of component to add. must be present in configdir/components and named $name.rb currently
230
239
  def component(name)
231
- puts "Loading #{name}" if @project.settings[:verbose]
240
+ $stderr.puts "Loading #{name}" if @project.settings[:verbose]
232
241
  if @include_components.empty? or @include_components.include?(name)
233
242
  component = Vanagon::Component.load_component(name, File.join(Vanagon::Driver.configdir, "components"), @project.settings, @project.platform)
234
243
  @project.components << component
@@ -252,7 +261,7 @@ class Vanagon
252
261
  # @param protocol [String] a supported component source type (Http, Git, ...)
253
262
  # @param rule [String, Proc] a rule used to rewrite component source urls
254
263
  def register_rewrite_rule(protocol, rule)
255
- Vanagon::Component::Source.register_rewrite_rule(protocol, rule)
264
+ Vanagon::Component::Source::Rewrite.register_rewrite_rule(protocol, rule)
256
265
  end
257
266
 
258
267
  # Toggle to apply additional cleanup during the build for space constrained systems
@@ -210,7 +210,7 @@ class Vanagon
210
210
  # output of the command if return_command_output is true
211
211
  # @raise [RuntimeError] If there is no target given or the command fails an exception is raised
212
212
  def remote_ssh_command(target, command, port = 22, return_command_output: false)
213
- puts "Executing '#{command}' on '#{target}'"
213
+ $stderr.puts "Executing '#{command}' on '#{target}'"
214
214
  if return_command_output
215
215
  ret = %x(#{ssh_command(port)} -T #{target} '#{command.gsub("'", "'\\\\''")}').chomp
216
216
  if $CHILD_STATUS.success?
@@ -233,7 +233,7 @@ class Vanagon
233
233
  # @raise [RuntimeError] If the command fails an exception is raised
234
234
  def local_command(command, return_command_output: false)
235
235
  clean_environment do
236
- puts "Executing '#{command}' locally"
236
+ $stderr.puts "Executing '#{command}' locally"
237
237
  if return_command_output
238
238
  ret = %x(#{command}).chomp
239
239
  if $CHILD_STATUS.success?
@@ -277,7 +277,7 @@ class Vanagon
277
277
  outfile ||= File.join(Dir.mktmpdir, File.basename(erbfile).sub(File.extname(erbfile), ""))
278
278
  output = erb_string(erbfile, opts[:binding])
279
279
  File.open(outfile, 'w') { |f| f.write output }
280
- puts "Generated: #{outfile}"
280
+ $stderr.puts "Generated: #{outfile}"
281
281
  FileUtils.rm_rf erbfile if remove_orig
282
282
  outfile
283
283
  end
@@ -0,0 +1,55 @@
1
+ require 'vanagon/component/source'
2
+
3
+ describe "Vanagon::Component::Source::Rewrite" do
4
+ let(:klass) { Vanagon::Component::Source::Rewrite }
5
+ before(:each) { klass.rewrite_rules.clear }
6
+
7
+ describe ".parse_and_rewrite" do
8
+ let(:simple_rule) { Proc.new {|url| url.gsub('a', 'e') } }
9
+ let(:complex_rule) do
10
+ Proc.new do |url|
11
+ match = url.match(/github.com\/(.*)$/)
12
+ "git://github.delivery.puppetlabs.net/#{match[1].gsub('/', '-')}" if match
13
+ end
14
+ end
15
+
16
+ it 'replaces the first section of a url with a string if string is given' do
17
+ klass.register_rewrite_rule('http', 'http://buildsources.delivery.puppetlabs.net')
18
+
19
+ expect(klass.rewrite('http://things.and.stuff/foo.tar.gz', 'http'))
20
+ .to eq('http://buildsources.delivery.puppetlabs.net/foo.tar.gz')
21
+ end
22
+
23
+ it 'applies the rule to the url if a proc is given as the rule' do
24
+ klass.register_rewrite_rule('http', simple_rule)
25
+
26
+ expect(klass.rewrite('http://things.and.stuff/foo.tar.gz', 'http'))
27
+ .to eq('http://things.end.stuff/foo.ter.gz')
28
+ end
29
+
30
+ it 'applies the rule to the url if a proc is given as the rule' do
31
+ klass.register_rewrite_rule('git', complex_rule)
32
+
33
+ expect(klass.rewrite('git://github.com/puppetlabs/facter', 'git'))
34
+ .to eq('git://github.delivery.puppetlabs.net/puppetlabs-facter')
35
+ end
36
+ end
37
+
38
+ describe ".register_rewrite_rule" do
39
+ it 'only accepts Proc and String as rule types' do
40
+ expect { klass.register_rewrite_rule('http', 5) }
41
+ .to raise_error(Vanagon::Error)
42
+ end
43
+
44
+ it 'rejects invalid protocols' do
45
+ expect { klass.register_rewrite_rule('gopher', 'abcd') }
46
+ .to raise_error Vanagon::Error
47
+ end
48
+
49
+ before { klass.register_rewrite_rule('http', 'http://buildsources.delivery.puppetlabs.net') }
50
+ it 'registers the rule for the given protocol' do
51
+ expect(klass.rewrite_rules)
52
+ .to eq({'http' => 'http://buildsources.delivery.puppetlabs.net'})
53
+ end
54
+ end
55
+ end
@@ -2,7 +2,6 @@ require 'vanagon/component/source'
2
2
 
3
3
  describe "Vanagon::Component::Source" do
4
4
  let(:klass) { Vanagon::Component::Source }
5
- before(:each) { klass.rewrite_rules.clear }
6
5
 
7
6
  describe ".source" do
8
7
  let(:unrecognized_uri) { "abcd://things" }
@@ -24,10 +23,8 @@ describe "Vanagon::Component::Source" do
24
23
  let(:workdir) { Dir.mktmpdir }
25
24
 
26
25
  let(:original_git_url) { "git://things.and.stuff/foo-bar.git" }
27
- let(:rewritten_git_url) { "git://things.end.stuff/foo-ber.git" }
28
26
 
29
27
  let(:original_http_url) { "http://things.and.stuff/foo.tar.gz" }
30
- let(:rewritten_http_url) { "http://buildsources.delivery.puppetlabs.net/foo.tar.gz" }
31
28
 
32
29
  it "fails on unrecognized URI schemes" do
33
30
  expect { klass.source(unrecognized_uri, workdir: workdir) }
@@ -69,17 +66,6 @@ describe "Vanagon::Component::Source" do
69
66
  expect(klass.source(https_git, ref: ref, workdir: workdir).class)
70
67
  .to eq Vanagon::Component::Source::Git
71
68
  end
72
-
73
- it "rewrites git:// URLs" do
74
- proc_rule = Proc.new { |url| url.gsub('a', 'e') }
75
- klass.register_rewrite_rule('git', proc_rule)
76
- # Vanagon::Component::Source::Git#url returns a URI object
77
- # so to check its value, we cast it to a simple string. It's
78
- # hacky for sure, but seems less diagreeable than mangling the
79
- # return value in the class itself.
80
- expect(klass.source(original_git_url, ref: ref, workdir: workdir).url.to_s)
81
- .to eq rewritten_git_url
82
- end
83
69
  end
84
70
 
85
71
  context "takes a HTTP/HTTPS file" do
@@ -102,15 +88,6 @@ describe "Vanagon::Component::Source" do
102
88
  expect(klass.source(https_url, sum: sum, workdir: workdir, sum_type: "md5").class)
103
89
  .to equal(Vanagon::Component::Source::Http)
104
90
  end
105
-
106
- before do
107
- klass.register_rewrite_rule 'http',
108
- 'http://buildsources.delivery.puppetlabs.net'
109
- end
110
- it "applies rewrite rules to HTTP URLs" do
111
- expect(klass.source(original_http_url, sum: sum, workdir: workdir, sum_type: "md5").url)
112
- .to eq(rewritten_http_url)
113
- end
114
91
  end
115
92
 
116
93
  context "takes a local file" do
@@ -130,53 +107,4 @@ describe "Vanagon::Component::Source" do
130
107
  end
131
108
  end
132
109
  end
133
-
134
- describe ".rewrite" do
135
- let(:simple_rule) { Proc.new {|url| url.gsub('a', 'e') } }
136
- let(:complex_rule) do
137
- Proc.new do |url|
138
- match = url.match(/github.com\/(.*)$/)
139
- "git://github.delivery.puppetlabs.net/#{match[1].gsub('/', '-')}" if match
140
- end
141
- end
142
-
143
- it 'replaces the first section of a url with a string if string is given' do
144
- klass.register_rewrite_rule('http', 'http://buildsources.delivery.puppetlabs.net')
145
-
146
- expect(klass.rewrite('http://things.and.stuff/foo.tar.gz', 'http'))
147
- .to eq('http://buildsources.delivery.puppetlabs.net/foo.tar.gz')
148
- end
149
-
150
- it 'applies the rule to the url if a proc is given as the rule' do
151
- klass.register_rewrite_rule('http', simple_rule)
152
-
153
- expect(klass.rewrite('http://things.and.stuff/foo.tar.gz', 'http'))
154
- .to eq('http://things.end.stuff/foo.ter.gz')
155
- end
156
-
157
- it 'applies the rule to the url if a proc is given as the rule' do
158
- klass.register_rewrite_rule('git', complex_rule)
159
-
160
- expect(klass.rewrite('git://github.com/puppetlabs/facter', 'git'))
161
- .to eq('git://github.delivery.puppetlabs.net/puppetlabs-facter')
162
- end
163
- end
164
-
165
- describe ".register_rewrite_rule" do
166
- it 'only accepts Proc and String as rule types' do
167
- expect { klass.register_rewrite_rule('http', 5) }
168
- .to raise_error(Vanagon::Error)
169
- end
170
-
171
- it 'rejects invalid protocols' do
172
- expect { klass.register_rewrite_rule('gopher', 'abcd') }
173
- .to raise_error Vanagon::Error
174
- end
175
-
176
- before { klass.register_rewrite_rule('http', 'http://buildsources.delivery.puppetlabs.net') }
177
- it 'registers the rule for the given protocol' do
178
- expect(klass.rewrite_rules)
179
- .to eq({'http' => 'http://buildsources.delivery.puppetlabs.net'})
180
- end
181
- end
182
110
  end