berkshelf 0.3.3 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/Guardfile +1 -1
  2. data/features/install.feature +129 -2
  3. data/features/lockfile.feature +1 -1
  4. data/features/step_definitions/filesystem_steps.rb +12 -0
  5. data/features/update.feature +1 -1
  6. data/features/upload_command.feature +1 -1
  7. data/lib/berkshelf/berksfile.rb +4 -1
  8. data/lib/berkshelf/cached_cookbook.rb +36 -9
  9. data/lib/berkshelf/cli.rb +2 -2
  10. data/lib/berkshelf/cookbook_source.rb +26 -63
  11. data/lib/berkshelf/cookbook_source/git_location.rb +21 -10
  12. data/lib/berkshelf/cookbook_source/location.rb +50 -0
  13. data/lib/berkshelf/cookbook_source/path_location.rb +13 -5
  14. data/lib/berkshelf/cookbook_source/site_location.rb +14 -4
  15. data/lib/berkshelf/cookbook_store.rb +34 -16
  16. data/lib/berkshelf/core_ext/string.rb +12 -0
  17. data/lib/berkshelf/downloader.rb +0 -4
  18. data/lib/berkshelf/errors.rb +41 -1
  19. data/lib/berkshelf/git.rb +83 -14
  20. data/lib/berkshelf/resolver.rb +85 -66
  21. data/lib/berkshelf/version.rb +1 -1
  22. data/spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb +1 -0
  23. data/spec/fixtures/cookbooks/example_metadata_name/metadata.rb +2 -0
  24. data/spec/fixtures/cookbooks/example_metadata_no_name/metadata.rb +1 -0
  25. data/spec/fixtures/cookbooks/example_no_metadata/recipes/default.rb +1 -0
  26. data/spec/support/chef_api.rb +42 -0
  27. data/spec/unit/berkshelf/cached_cookbook_spec.rb +55 -11
  28. data/spec/unit/berkshelf/cookbook_source/git_location_spec.rb +65 -15
  29. data/spec/unit/berkshelf/cookbook_source/location_spec.rb +42 -0
  30. data/spec/unit/berkshelf/cookbook_source/path_location_spec.rb +22 -5
  31. data/spec/unit/berkshelf/cookbook_source/site_location_spec.rb +32 -13
  32. data/spec/unit/berkshelf/cookbook_source_spec.rb +24 -33
  33. data/spec/unit/berkshelf/cookbook_store_spec.rb +47 -7
  34. data/spec/unit/berkshelf/git_spec.rb +97 -12
  35. data/spec/unit/berkshelf/resolver_spec.rb +72 -48
  36. data/spec/unit/berkshelf/uploader_spec.rb +12 -4
  37. metadata +13 -7
  38. data/spec/fixtures/cookbooks/invalid_ruby_files-1.0.0/recipes/default.rb +0 -1
  39. data/spec/fixtures/cookbooks/invalid_template_files-1.0.0/templates/default/broken.erb +0 -1
@@ -2,59 +2,83 @@ require 'spec_helper'
2
2
 
3
3
  module Berkshelf
4
4
  describe Resolver do
5
+ let(:source) do
6
+ double('source',
7
+ name: 'mysql',
8
+ version_constraint: DepSelector::VersionConstraint.new('= 1.2.4'),
9
+ downloaded?: true,
10
+ cached_cookbook: double('mysql-cookbook',
11
+ name: 'mysql-1.2.4',
12
+ cookbook_name: 'mysql',
13
+ version: '1.2.4',
14
+ dependencies: { "nginx" => ">= 0.1.0", "artifact" => "~> 0.10.0" }
15
+ ),
16
+ location: double('location', validate_cached: true)
17
+ )
18
+ end
19
+
20
+ let(:source_two) do
21
+ double('source-two',
22
+ name: 'nginx',
23
+ version_constraint: DepSelector::VersionConstraint.new('= 0.101.2'),
24
+ downloaded?: true,
25
+ cached_cookbook: double('nginx-cookbook',
26
+ name: 'nginx-0.101.2',
27
+ cookbook_name: 'nginx',
28
+ version: '0.101.2',
29
+ dependencies: Hash.new
30
+ ),
31
+ location: double('location', validate_cached: true)
32
+ )
33
+ end
34
+
5
35
  describe "ClassMethods" do
6
36
  subject { Resolver }
7
37
 
8
- describe "#initialize" do
38
+ describe "::initialize" do
9
39
  let(:downloader) { Berkshelf.downloader }
10
40
 
11
41
  it "adds the specified sources to the sources hash" do
12
- source = CookbookSource.new("mysql", "= 1.2.4")
13
42
  resolver = subject.new(downloader, source)
14
43
 
15
- resolver.should have_source(source)
44
+ resolver.should have_source(source.name)
16
45
  end
17
46
 
18
- it "adds the dependencies of the source as packages of the graph" do
19
- source = CookbookSource.new("mysql", "= 1.2.4")
47
+ it "adds the dependencies of the source as sources" do
20
48
  resolver = subject.new(downloader, source)
21
49
 
22
- source.dependencies.each do |name, constraint|
50
+ source.cached_cookbook.dependencies.each do |name, constraint|
23
51
  resolver.package(name).should_not be_nil
24
52
  end
25
53
  end
26
54
 
27
55
  it "adds the version_constraints of the dependencies to the graph" do
28
- source = CookbookSource.new("mysql", "= 1.2.4")
29
56
  resolver = subject.new(downloader, source)
30
57
 
31
- source.dependencies.each do |name, constraint|
58
+ source.cached_cookbook.dependencies.each do |name, constraint|
32
59
  resolver.package(name).versions.should_not be_empty
33
60
  end
34
61
  end
35
62
 
36
63
  context "given an array of sources" do
37
- it "adds the sources to the sources hash" do
38
- sources = [CookbookSource.new("mysql", "= 1.2.4")]
64
+ it "adds each source to the sources hash" do
65
+ sources = [source]
39
66
  resolver = subject.new(downloader, sources)
40
67
 
41
- resolver.should have_source(sources[0])
68
+ resolver.should have_source(sources[0].name)
42
69
  end
43
70
  end
44
71
  end
45
72
  end
46
73
 
47
- let(:source) { CookbookSource.new("mysql", "= 1.2.4") }
48
-
49
- subject do
50
- downloader = Berkshelf.downloader
51
- Resolver.new(downloader)
52
- end
74
+ subject { Resolver.new(Berkshelf.downloader) }
53
75
 
54
76
  describe "#add_source" do
55
- before(:each) { subject.add_source(source) }
77
+ let(:package_version) { double('package-version', dependencies: Array.new) }
56
78
 
57
79
  it "adds the source to the instance of resolver" do
80
+ subject.add_source(source)
81
+
58
82
  subject.sources.should include(source)
59
83
  end
60
84
 
@@ -63,46 +87,50 @@ module Berkshelf
63
87
  end
64
88
 
65
89
  it "adds a version constraint specified by the source to the package of the same name" do
90
+ subject.add_source(source)
91
+
66
92
  subject.package(source.name).versions.collect(&:version).should include(source.version_constraint.version)
67
93
  end
68
94
 
69
95
  it "adds the dependencies of the source as packages to the graph" do
70
- source.dependencies.each do |name, constraint|
71
- subject.package(name).should_not be_nil
72
- end
96
+ subject.should_receive(:add_source_dependencies).with(source)
97
+
98
+ subject.add_source(source)
73
99
  end
74
100
 
75
101
  it "raises a DuplicateSourceDefined exception if a source of the same name is added" do
76
- dup_source = CookbookSource.new(source.name)
102
+ subject.should_receive(:has_source?).with(source).and_return(true)
77
103
 
78
104
  lambda {
79
- subject.add_source(dup_source)
105
+ subject.add_source(source)
80
106
  }.should raise_error(DuplicateSourceDefined)
81
107
  end
82
- end
83
108
 
84
- describe "#add_dependencies" do
85
- it "adds a package for each dependency to the graph" do
86
- pkg_ver = subject.add_source(source)
87
- subject.add_dependencies(pkg_ver, source.dependencies)
109
+ it "adds a package for each dependency to the packages attribute" do
110
+ subject.add_source(source)
88
111
 
89
- subject.package(source.name).should_not be_nil
112
+ source.cached_cookbook.dependencies.each do |name, constraint|
113
+ subject.package(name).should_not be_nil
114
+ end
90
115
  end
91
116
 
92
- it "adds a version constraint to the graph for each dependency" do
93
- pkg_ver = subject.add_source(source)
94
- subject.add_dependencies(pkg_ver, source.dependencies)
117
+ context "when include_dependencies is false" do
118
+ it "does not try to include_dependencies" do
119
+ subject.should_not_receive(:add_source_dependencies)
95
120
 
96
- subject.package(source.name).versions.collect(&:version).should include(source.version_constraint.version)
121
+ subject.add_source(source, false)
122
+ end
97
123
  end
98
124
  end
99
125
 
100
- describe "#[]" do
126
+ describe "#get_source" do
101
127
  before(:each) { subject.add_source(source) }
102
128
 
103
- it "returns the source of the given name" do
104
- subject[source.name].should eql(source)
105
- end
129
+ context "given a string representation of the source to retrieve" do
130
+ it "returns the source of the same name" do
131
+ subject.get_source(source.name).should eql(source)
132
+ end
133
+ end
106
134
  end
107
135
 
108
136
  describe "#has_source?" do
@@ -116,24 +144,20 @@ module Berkshelf
116
144
  describe "#resolve" do
117
145
  before(:each) do
118
146
  subject.add_source(source)
147
+ subject.add_source(source_two)
119
148
  @solution = subject.resolve
120
149
  end
121
150
 
122
- it "returns an array of CachedCookbooks" do
123
- @solution.each do |item|
124
- item.should be_a(CachedCookbook)
125
- end
151
+ it "returns an array of the CachedCookbooks which make up the solution" do
152
+ @solution.should include(source.cached_cookbook)
153
+ @solution.should include(source_two.cached_cookbook)
126
154
  end
127
-
128
- it "returns a CachedCookbook for each resolved source" do
129
- @solution.should have(2).items
130
- end
131
-
155
+
132
156
  it "resolves the given mysql source" do
133
157
  @solution[0].cookbook_name.should eql("mysql")
134
158
  @solution[0].version.should eql("1.2.4")
135
- @solution[1].cookbook_name.should eql("openssl")
136
- @solution[1].version.should eql("1.0.0")
159
+ @solution[1].cookbook_name.should eql("nginx")
160
+ @solution[1].version.should eql("0.101.2")
137
161
  end
138
162
  end
139
163
  end
@@ -2,9 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  module Berkshelf
4
4
  describe Uploader do
5
- let(:server_url) { "https://api.opscode.com/organizations/vialstudios" }
6
- let(:client_key) { '/Users/reset/.chef/reset.pem' }
7
- let(:node_name) { 'reset' }
5
+
6
+ unless config = YAML.load_file('features/config.yml')
7
+ raise "Could not load features/config.yml -- please generate it from features/config.sample.yml"
8
+ end
9
+
10
+ let(:server_url) { config["chef_server_url"] }
11
+ let(:client_key) { config["client_key"] }
12
+ let(:node_name) { config["node_name"] }
8
13
 
9
14
  subject { Uploader.new(server_url, client_key: client_key, node_name: node_name) }
10
15
 
@@ -14,7 +19,10 @@ module Berkshelf
14
19
  context "when cookbook is valid" do
15
20
  before(:each) do
16
21
  cookbook.should_receive(:validate!).and_return(true)
17
- cookbook.should_receive(:checksums).and_return("da97c94bb6acb2b7900cbf951654fea3"=>"/Users/reset/code/berkshelf/spec/fixtures/cookbooks/example_cookbook-0.5.0/recipes/default.rb")
22
+ cookbook.should_receive(:checksums).and_return(
23
+ "da97c94bb6acb2b7900cbf951654fea3" =>
24
+ File.expand_path("spec/fixtures/cookbooks/example_cookbook-0.5.0/recipes/default.rb")
25
+ )
18
26
  subject.should_receive(:create_sandbox)
19
27
  subject.should_receive(:upload_checksums_to_sandbox)
20
28
  subject.should_receive(:commit_sandbox)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkshelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-06-27 00:00:00.000000000 Z
15
+ date: 2012-07-04 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: dep_selector
@@ -388,6 +388,7 @@ files:
388
388
  - lib/berkshelf/cli.rb
389
389
  - lib/berkshelf/cookbook_source.rb
390
390
  - lib/berkshelf/cookbook_source/git_location.rb
391
+ - lib/berkshelf/cookbook_source/location.rb
391
392
  - lib/berkshelf/cookbook_source/path_location.rb
392
393
  - lib/berkshelf/cookbook_source/site_location.rb
393
394
  - lib/berkshelf/cookbook_store.rb
@@ -396,6 +397,7 @@ files:
396
397
  - lib/berkshelf/core_ext/fileutils.rb
397
398
  - lib/berkshelf/core_ext/kernel.rb
398
399
  - lib/berkshelf/core_ext/pathname.rb
400
+ - lib/berkshelf/core_ext/string.rb
399
401
  - lib/berkshelf/downloader.rb
400
402
  - lib/berkshelf/dsl.rb
401
403
  - lib/berkshelf/errors.rb
@@ -417,8 +419,9 @@ files:
417
419
  - spec/fixtures/cookbooks/example_cookbook/README.md
418
420
  - spec/fixtures/cookbooks/example_cookbook/metadata.rb
419
421
  - spec/fixtures/cookbooks/example_cookbook/recipes/default.rb
420
- - spec/fixtures/cookbooks/invalid_ruby_files-1.0.0/recipes/default.rb
421
- - spec/fixtures/cookbooks/invalid_template_files-1.0.0/templates/default/broken.erb
422
+ - spec/fixtures/cookbooks/example_metadata_name/metadata.rb
423
+ - spec/fixtures/cookbooks/example_metadata_no_name/metadata.rb
424
+ - spec/fixtures/cookbooks/example_no_metadata/recipes/default.rb
422
425
  - spec/fixtures/cookbooks/nginx-0.100.5/README.md
423
426
  - spec/fixtures/cookbooks/nginx-0.100.5/attributes/default.rb
424
427
  - spec/fixtures/cookbooks/nginx-0.100.5/definitions/nginx_site.rb
@@ -440,6 +443,7 @@ files:
440
443
  - spec/unit/berkshelf/berksfile_spec.rb
441
444
  - spec/unit/berkshelf/cached_cookbook_spec.rb
442
445
  - spec/unit/berkshelf/cookbook_source/git_location_spec.rb
446
+ - spec/unit/berkshelf/cookbook_source/location_spec.rb
443
447
  - spec/unit/berkshelf/cookbook_source/path_location_spec.rb
444
448
  - spec/unit/berkshelf/cookbook_source/site_location_spec.rb
445
449
  - spec/unit/berkshelf/cookbook_source_spec.rb
@@ -474,7 +478,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
474
478
  version: '0'
475
479
  segments:
476
480
  - 0
477
- hash: -3981898465681112327
481
+ hash: -4298839394573709666
478
482
  requirements: []
479
483
  rubyforge_project:
480
484
  rubygems_version: 1.8.23
@@ -501,8 +505,9 @@ test_files:
501
505
  - spec/fixtures/cookbooks/example_cookbook/README.md
502
506
  - spec/fixtures/cookbooks/example_cookbook/metadata.rb
503
507
  - spec/fixtures/cookbooks/example_cookbook/recipes/default.rb
504
- - spec/fixtures/cookbooks/invalid_ruby_files-1.0.0/recipes/default.rb
505
- - spec/fixtures/cookbooks/invalid_template_files-1.0.0/templates/default/broken.erb
508
+ - spec/fixtures/cookbooks/example_metadata_name/metadata.rb
509
+ - spec/fixtures/cookbooks/example_metadata_no_name/metadata.rb
510
+ - spec/fixtures/cookbooks/example_no_metadata/recipes/default.rb
506
511
  - spec/fixtures/cookbooks/nginx-0.100.5/README.md
507
512
  - spec/fixtures/cookbooks/nginx-0.100.5/attributes/default.rb
508
513
  - spec/fixtures/cookbooks/nginx-0.100.5/definitions/nginx_site.rb
@@ -524,6 +529,7 @@ test_files:
524
529
  - spec/unit/berkshelf/berksfile_spec.rb
525
530
  - spec/unit/berkshelf/cached_cookbook_spec.rb
526
531
  - spec/unit/berkshelf/cookbook_source/git_location_spec.rb
532
+ - spec/unit/berkshelf/cookbook_source/location_spec.rb
527
533
  - spec/unit/berkshelf/cookbook_source/path_location_spec.rb
528
534
  - spec/unit/berkshelf/cookbook_source/site_location_spec.rb
529
535
  - spec/unit/berkshelf/cookbook_source_spec.rb
@@ -1 +0,0 @@
1
- (*&)*^^^@(8123_)@(jkladsf}})end))) +++ /0
@@ -1 +0,0 @@
1
- <%= (*&)*^^^@(8123_)@(jkladsf}})end))) +++%>