polisher 0.9.1 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
- # Polisher Git Spec
2
1
  #
3
2
  # Licensed under the MIT license
4
3
  # Copyright (C) 2013-2014 Red Hat, Inc.
5
4
 
6
5
  require 'polisher/git'
6
+ require 'polisher/gem'
7
7
  require 'pathname'
8
8
 
9
9
  module Polisher
@@ -28,7 +28,7 @@ module Polisher
28
28
  describe "#clone" do
29
29
  it "runs git clone" do
30
30
  expected = "/usr/bin/git clone repo_url repo_path"
31
- AwesomeSpawn.should_receive(:run).with(expected)
31
+ AwesomeSpawn.should_receive(:run!).with(expected)
32
32
 
33
33
  repo = described_class.new :url => 'repo_url'
34
34
  repo.should_receive(:path).and_return('repo_path')
@@ -91,7 +91,7 @@ module Polisher
91
91
  expected = "/usr/bin/git reset HEAD~ --hard"
92
92
  repo = described_class.new
93
93
  repo.should_receive(:in_repo).and_yield
94
- AwesomeSpawn.should_receive(:run).with(expected)
94
+ AwesomeSpawn.should_receive(:run!).with(expected)
95
95
  repo.reset!
96
96
  end
97
97
  end
@@ -101,7 +101,7 @@ module Polisher
101
101
  expected = "/usr/bin/git pull"
102
102
  repo = described_class.new
103
103
  repo.should_receive(:in_repo).and_yield
104
- AwesomeSpawn.should_receive(:run).with(expected)
104
+ AwesomeSpawn.should_receive(:run!).with(expected)
105
105
  repo.pull
106
106
  end
107
107
  end
@@ -111,7 +111,7 @@ module Polisher
111
111
  expected = "/usr/bin/git checkout master"
112
112
  repo = described_class.new
113
113
  repo.should_receive(:in_repo).and_yield
114
- AwesomeSpawn.should_receive(:run).with(expected)
114
+ AwesomeSpawn.should_receive(:run!).with(expected)
115
115
  repo.checkout('master')
116
116
  end
117
117
  end
@@ -121,7 +121,7 @@ module Polisher
121
121
  expected = "/usr/bin/git commit -m 'msg'"
122
122
  repo = described_class.new
123
123
  repo.should_receive(:in_repo).and_yield
124
- AwesomeSpawn.should_receive(:run).with(expected)
124
+ AwesomeSpawn.should_receive(:run!).with(expected)
125
125
  repo.commit('msg')
126
126
  end
127
127
  end
@@ -185,6 +185,7 @@ module Polisher
185
185
 
186
186
  pkg = described_class.new :name => 'rails'
187
187
  pkg.should_receive(:in_repo).and_yield
188
+ pkg.should_receive(:require_cmd!).with('/usr/bin/fedpkg').and_return(true)
188
189
 
189
190
  expected = '/usr/bin/fedpkg clone rubygem-rails'
190
191
  result = AwesomeSpawn::CommandResult.new '', '', '', 0
@@ -204,14 +205,14 @@ module Polisher
204
205
 
205
206
  context "dead.package exists" do
206
207
  it "returns true" do
207
- File.should_receive(:exists?).with('dead.package').and_return(true)
208
+ File.should_receive(:exist?).with('dead.package').and_return(true)
208
209
  @pkg.should be_dead
209
210
  end
210
211
  end
211
212
 
212
213
  context "dead.package does not exist" do
213
214
  it "returns false" do
214
- File.should_receive(:exists?).with('dead.package').and_return(false)
215
+ File.should_receive(:exist?).with('dead.package').and_return(false)
215
216
  @pkg.should_not be_dead
216
217
  end
217
218
  end
@@ -290,7 +291,16 @@ module Polisher
290
291
  end
291
292
  end
292
293
 
294
+ describe "#update_metadata" do
295
+ it "sets pkg version" do
296
+ pkg = described_class.new
297
+ pkg.update_metadata(Polisher::Gem.new(:version => '5.0'))
298
+ pkg.version.should == '5.0'
299
+ end
300
+ end
301
+
293
302
  describe "#update_spec_to" do
303
+ it "updates spec metadata"
294
304
  it "updates spec version"
295
305
  it "updates spec release"
296
306
  end
@@ -317,6 +327,7 @@ module Polisher
317
327
  expected = "/usr/bin/git add pkg_files"
318
328
  AwesomeSpawn.should_receive(:run).with(expected)
319
329
  AwesomeSpawn.should_receive(:run).at_least(:once)
330
+ .and_return(AwesomeSpawn::CommandResult.new('', '', '', 0))
320
331
  pkg.commit
321
332
  end
322
333
 
@@ -324,27 +335,53 @@ module Polisher
324
335
  pkg = described_class.new(:name => 'rails', :version => '1.0.0')
325
336
  pkg.should_receive(:in_repo).at_least(:once).and_yield
326
337
  expected = "/usr/bin/git commit -m 'updated to 1.0.0'"
327
- AwesomeSpawn.should_receive(:run).with(expected)
338
+ AwesomeSpawn.should_receive(:run!).with(expected)
328
339
  AwesomeSpawn.should_receive(:run).at_least(:once)
340
+ .and_return(AwesomeSpawn::CommandResult.new('', '', '', 0))
329
341
  pkg.commit
330
342
  end
331
343
  end
332
344
 
333
345
  describe "#build_srpm" do
334
346
  it "uses package command to build srpm" do
335
- pkg = described_class.new
347
+ gem = Polisher::Gem.new
348
+ spec = RPM::Spec.new
349
+ pkg = described_class.new
336
350
  pkg.should_receive(:in_repo).and_yield
337
- AwesomeSpawn.should_receive(:run).with("/usr/bin/fedpkg srpm")
351
+ pkg.should_receive(:require_cmd!).with('/usr/bin/fedpkg').and_return(true)
352
+ pkg.should_receive(:spec).and_return(spec)
353
+ spec.should_receive(:upstream_gem).and_return(gem)
354
+ FileUtils.stub(:ln_s) # stub out ln
355
+ result = AwesomeSpawn::CommandResult.new "", "", "", 0
356
+ AwesomeSpawn.should_receive(:run)
357
+ .with("/usr/bin/fedpkg srpm")
358
+ .and_return(result)
338
359
  pkg.build_srpm
339
360
  end
361
+
362
+ context "package command fails" do
363
+ it "raises RuntimeError with the command stderr" do
364
+ gem = Polisher::Gem.new
365
+ spec = RPM::Spec.new
366
+ pkg = described_class.new
367
+ pkg.should_receive(:in_repo).and_yield
368
+ pkg.should_receive(:require_cmd!).with('/usr/bin/fedpkg').and_return(true)
369
+ pkg.should_receive(:spec).and_return(spec)
370
+ spec.should_receive(:upstream_gem).and_return(gem)
371
+ FileUtils.stub(:ln_s) # stub out ln
372
+ result = AwesomeSpawn::CommandResult.new "", "", "cmd_error", 1
373
+ AwesomeSpawn.should_receive(:run)
374
+ .and_return(result)
375
+ expect { pkg.build_srpm }.to raise_error(RuntimeError, "cmd_error")
376
+ end
377
+ end
340
378
  end
341
379
 
342
380
  describe "#scratch_build" do
343
- it "uses build command to build srpm" do
381
+ it "uses koji to build srpm" do
344
382
  pkg = described_class.new(:name => 'rails', :version => '1.0.0')
345
383
  pkg.should_receive(:in_repo).and_yield
346
- expected = "/usr/bin/koji build --scratch rawhide rubygem-rails-1.0.0-1.*.src.rpm"
347
- AwesomeSpawn.should_receive(:run).with(expected)
384
+ Koji.should_receive(:build).with(:srpm => pkg.srpm, :scratch => true)
348
385
  pkg.scratch_build
349
386
  end
350
387
  end
@@ -358,37 +395,36 @@ module Polisher
358
395
  end
359
396
  end
360
397
 
361
- describe "#version_for" do
362
- it "uses git to retrieve the package" do
363
- pkg = "#{described_class.dist_git_url}rubygem-rails.git"
364
- dir = Polisher::GitCache.path_for('rubygem-rails')
365
- expected = "/usr/bin/git clone #{pkg} #{dir}"
366
- AwesomeSpawn.should_receive(:run).with(expected)
367
- described_class.version_for 'rails'
398
+ describe "#versions_for" do
399
+ it "git fetches the package" do
400
+ pkg = described_class.new
401
+ described_class.should_receive(:new)
402
+ .with(:name => 'rails')
403
+ .and_return(pkg)
404
+ pkg.should_receive(:fetch).with(described_class.fetch_tgt)
405
+ described_class.versions_for 'rails'
368
406
  end
369
407
 
370
408
  it "returns version of the package" do
371
- AwesomeSpawn.should_receive(:run) # stub out run
372
-
373
409
  spec = Polisher::RPM::Spec.new :version => '1.0.0'
374
410
  pkg = described_class.new
411
+ pkg.should_receive(:fetch) # stub out fetch
375
412
  described_class.should_receive(:new).and_return(pkg)
376
413
  pkg.should_receive(:spec).and_return(spec)
377
414
 
378
- described_class.version_for('rails').should == '1.0.0'
415
+ described_class.versions_for('rails').should == ['1.0.0']
379
416
  end
380
417
 
381
418
  it "invokes callback with version of package" do
382
- AwesomeSpawn.should_receive(:run) # stub out run
383
-
384
419
  spec = Polisher::RPM::Spec.new :version => '1.0.0'
385
420
  pkg = described_class.new
421
+ pkg.should_receive(:fetch) # stub out fetch
386
422
  described_class.should_receive(:new).and_return(pkg)
387
423
  pkg.should_receive(:spec).and_return(spec)
388
424
 
389
425
  cb = proc {}
390
426
  cb.should_receive(:call).with(:git, 'rails', ['1.0.0'])
391
- described_class.version_for('rails', &cb)
427
+ described_class.versions_for('rails', &cb)
392
428
  end
393
429
  end
394
430
  end # describe Git::Pkg
@@ -65,7 +65,7 @@ module Polisher
65
65
  end
66
66
 
67
67
  it "uses xmlrpc client to retreive versions" do
68
- expected = ['listTagged', described_class.koji_tag, nil, false,
68
+ expected = ['listTagged', described_class.koji_tag, nil, true,
69
69
  nil, false, "rubygem-rails"]
70
70
  @client.should_receive(:call).with(*expected).and_return([])
71
71
  described_class.versions_for 'rails'
@@ -73,15 +73,34 @@ module Polisher
73
73
 
74
74
  it "handles multiple koji tags" do
75
75
  described_class.should_receive(:koji_tags).and_return(['tag1', 'tag2'])
76
- expected1 = ['listTagged', 'tag1', nil, false,
76
+ expected1 = ['listTagged', 'tag1', nil, true,
77
77
  nil, false, "rubygem-rails"]
78
- expected2 = ['listTagged', 'tag2', nil, false,
78
+ expected2 = ['listTagged', 'tag2', nil, true,
79
79
  nil, false, "rubygem-rails"]
80
80
  @client.should_receive(:call).with(*expected1).and_return([])
81
81
  @client.should_receive(:call).with(*expected2).and_return([])
82
82
  described_class.versions_for 'rails'
83
83
  end
84
84
 
85
+ it "handles multiple koji prefixes" do
86
+ @prefix = ['rubygem-', 'ruby193-rubygem-']
87
+ described_class.should_receive(:package_prefix).twice.and_return(['rubygem-', 'ruby193-rubygem-'])
88
+ described_class.should_receive(:koji_tags).and_return(['tag1', 'tag2'])
89
+ expected1 = ['listTagged', 'tag1', nil, true,
90
+ nil, false, "rubygem-rails"]
91
+ expected2 = ['listTagged', 'tag2', nil, true,
92
+ nil, false, "rubygem-rails"]
93
+ expected3 = ['listTagged', 'tag1', nil, true,
94
+ nil, false, "ruby193-rubygem-rails"]
95
+ expected4 = ['listTagged', 'tag2', nil, true,
96
+ nil, false, "ruby193-rubygem-rails"]
97
+ @client.should_receive(:call).with(*expected1).and_return([])
98
+ @client.should_receive(:call).with(*expected2).and_return([])
99
+ @client.should_receive(:call).with(*expected3).and_return([])
100
+ @client.should_receive(:call).with(*expected4).and_return([])
101
+ described_class.versions_for 'rails'
102
+ end
103
+
85
104
  it "returns versions" do
86
105
  versions = [{'version' => '1.0.0'}]
87
106
  @client.should_receive(:call).and_return(versions)
@@ -96,6 +115,44 @@ module Polisher
96
115
  cb.should_receive(:call).with(:koji, 'rails', ['1.0.0'])
97
116
  described_class.versions_for('rails', &cb)
98
117
  end
118
+ end # describe versions_for
119
+
120
+ describe "#build" do
121
+ it "runs build_cmd" do
122
+ result = AwesomeSpawn::CommandResult.new "", "", "", 0
123
+ expected = "#{described_class.build_cmd} build #{described_class.build_tgt} srpm"
124
+ AwesomeSpawn.should_receive(:run).with(expected).and_return(result)
125
+ described_class.should_receive(:require_cmd!)
126
+ .with(described_class.build_cmd).and_return(true)
127
+ described_class.build :srpm => 'srpm'
128
+ end
129
+
130
+ it "runs scratch build" do
131
+ described_class.should_receive(:require_cmd!)
132
+ .with(described_class.build_cmd).and_return(true)
133
+ result = AwesomeSpawn::CommandResult.new "", "", "", 0
134
+ expected = "#{described_class.build_cmd} build --scratch f20 srpm"
135
+ AwesomeSpawn.should_receive(:run).with(expected).and_return(result)
136
+ described_class.build :target => 'f20', :srpm => 'srpm', :scratch => true
137
+ end
138
+
139
+ it "parses & returns url from build output" do
140
+ described_class.should_receive(:require_cmd!).and_return(true)
141
+ result = AwesomeSpawn::CommandResult.new "", "output", "", 0
142
+ AwesomeSpawn.should_receive(:run).and_return(result)
143
+ described_class.should_receive(:parse_url).with('output').and_return('url')
144
+ described_class.build.should == 'url'
145
+ end
146
+
147
+ describe "non-zero build exit status" do
148
+ it "raises runtime error with build url" do
149
+ described_class.should_receive(:require_cmd!).and_return(true)
150
+ result = AwesomeSpawn::CommandResult.new "", "", "", 1
151
+ AwesomeSpawn.should_receive(:run).and_return(result)
152
+ described_class.should_receive(:parse_url).and_return('url')
153
+ lambda { described_class.build }.should raise_error(RuntimeError, 'url')
154
+ end
155
+ end
99
156
  end
100
157
  end # describe Koji
101
158
  end # module Polisher
@@ -116,12 +116,16 @@ module Polisher::RPM
116
116
  it "updates dependencies from gem" do
117
117
  spec = described_class.new :requires => [Requirement.parse('rubygem(rake)'),
118
118
  Requirement.parse('rubygem(activerecord)')],
119
- :build_requires => []
119
+ :build_requires => []
120
120
  gem = Polisher::Gem.new :deps => [::Gem::Dependency.new('rake'),
121
121
  ::Gem::Dependency.new('rails', '~> 10')],
122
122
  :dev_deps => [::Gem::Dependency.new('rspec', :development)]
123
123
 
124
- spec.should_receive(:update_files_from) # stub out files update
124
+ # stub out a few methods
125
+ spec.should_receive(:excluded_deps).at_least(:once).and_return([])
126
+ spec.should_receive(:excluded_dev_deps).at_least(:once).and_return([])
127
+ spec.should_receive(:update_files_from)
128
+
125
129
  spec.update_to(gem)
126
130
  spec.requires.should == [Requirement.parse('rubygem(activerecord)'),
127
131
  Requirement.parse('rubygem(rake) >= 0'),
@@ -136,7 +140,7 @@ module Polisher::RPM
136
140
  gem.should_receive(:file_paths).at_least(:once).
137
141
  and_return(['/foo', '/foo/bar', '/baz'])
138
142
  spec.update_to(gem)
139
- spec.new_files.should == ['/baz']
143
+ spec.new_files.should == ['%{gem_instdir}//baz']
140
144
  end
141
145
 
142
146
  it "updates metadata from gem" do
@@ -70,7 +70,8 @@ module Polisher
70
70
  GEMFILE = {
71
71
  :path => "#{SPEC_DIR}/data/Gemfile",
72
72
  :contents => File.read("#{SPEC_DIR}/data/Gemfile"),
73
- :deps => ['rubygems', 'cinch']
73
+ :deps => [::Gem::Dependency.new("rubygems", ::Gem::Requirement.new([">= 0"]), :runtime),
74
+ ::Gem::Dependency.new("cinch", ::Gem::Requirement.new([">= 0"]), :runtime)]
74
75
  }
75
76
 
76
77
  RPM_SPEC = {
@@ -0,0 +1,97 @@
1
+ # Polisher Version Checker Spec
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2013-2014 Red Hat, Inc.
5
+
6
+ require 'polisher/version_checker'
7
+
8
+ module Polisher
9
+ describe VersionChecker do
10
+ describe "#check" do
11
+ it "adds target to check to list"
12
+ end
13
+
14
+ describe "#should_check?" do
15
+ context "target is on check list" do
16
+ it "returns true"
17
+ end
18
+
19
+ context "target is not on check list" do
20
+ it "returns false"
21
+ end
22
+ end
23
+
24
+ describe "#versions_for" do
25
+ context "should check gem target" do
26
+ it "checks gem target"
27
+ it "invokes block w/ gem versions retrieved"
28
+ end
29
+
30
+ context "should check fedora target" do
31
+ it "checks fedora target"
32
+ it "invokes block w/ fedora versions retrieved"
33
+ context "error retrieving versions from fedora" do
34
+ it "invokes block w/ 'unknown' version"
35
+ it "returns 'unknown' fedora version"
36
+ end
37
+ end
38
+
39
+ context "should check koji target" do
40
+ it "checks koji target"
41
+ it "invokes block w/ koji versions retrieved"
42
+ context "error retrieving versions from koji" do
43
+ it "invokes block w/ 'unknown' version"
44
+ it "returns 'unknown' koji version"
45
+ end
46
+ end
47
+
48
+ context "should check git target" do
49
+ it "checks git target"
50
+ it "invokes block w/ git versions retrieved"
51
+ context "error retrieving versions from git" do
52
+ it "invokes block w/ 'unknown' version"
53
+ it "returns 'unknown' git version"
54
+ end
55
+ end
56
+
57
+ context "should check yum target" do
58
+ it "checks yum target"
59
+ it "invokes block w/ yum versions retrieved"
60
+ context "error retrieving versions from yum" do
61
+ it "invokes block w/ 'unknown' version"
62
+ it "returns 'unknown' yum version"
63
+ end
64
+ end
65
+
66
+ context "should check bodhi target" do
67
+ it "checks bodhi target"
68
+ it "invokes block w/ bodhi versions retrieved"
69
+ context "error retrieving versions from bodhi" do
70
+ it "invokes block w/ 'unknown' version"
71
+ it "returns 'unknown' bodhi version"
72
+ end
73
+ end
74
+
75
+ context "should check errata target" do
76
+ it "checks errata target"
77
+ it "checks errata target"
78
+ it "invokes block w/ errata versions retrieved"
79
+ context "error retrieving versions from errata" do
80
+ it "invokes block w/ 'unknown' version"
81
+ it "returns 'unknown' errata version"
82
+ end
83
+ end
84
+
85
+ it "returns all versions retrieved"
86
+ end
87
+
88
+ describe "version for" do
89
+ it "retrieves most relevant version of package in configured targets"
90
+ end
91
+ end # describe VersionChecker
92
+
93
+ describe VersionedDependencies do
94
+ it "retrieves versions of each dependency in configured targets"
95
+ it "invokes block with targets / versions"
96
+ end # described VersionedDependencies
97
+ end # module Polisher
@@ -12,6 +12,8 @@ module Polisher
12
12
  end
13
13
 
14
14
  it "uses yum to retreive versions" do
15
+ described_class.should_receive(:require_cmd!)
16
+ .with('/usr/bin/yum').and_return(true)
15
17
  expected = "/usr/bin/yum info rubygem-rails"
16
18
  result = AwesomeSpawn::CommandResult.new expected, "", "", 0
17
19
  AwesomeSpawn.should_receive(:run).with(expected).and_return(result)
@@ -19,12 +21,15 @@ module Polisher
19
21
  end
20
22
 
21
23
  it "returns versions" do
24
+ described_class.should_receive(:require_cmd!).and_return(true)
22
25
  result = AwesomeSpawn::CommandResult.new "", "Version: 1.0.0", "", 0
23
26
  AwesomeSpawn.should_receive(:run).and_return(result)
24
27
  described_class.version_for("rails") == '1.0.0'
25
28
  end
26
29
 
27
30
  it "invokes block with versions" do
31
+ described_class.should_receive(:require_cmd!).and_return(true)
32
+
28
33
  cb = proc {}
29
34
  cb.should_receive(:call).with(:yum, 'rails', ['1.0.0'])
30
35