berkshelf 1.2.0.rc1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -1
- data/README.md +2 -0
- data/berkshelf.gemspec +4 -3
- data/features/step_definitions/filesystem_steps.rb +0 -1
- data/generator_files/Gemfile.erb +0 -3
- data/generator_files/Vagrantfile.erb +13 -1
- data/lib/berkshelf.rb +0 -1
- data/lib/berkshelf/berksfile.rb +11 -4
- data/lib/berkshelf/cached_cookbook.rb +2 -257
- data/lib/berkshelf/chef.rb +0 -1
- data/lib/berkshelf/chef/config.rb +3 -0
- data/lib/berkshelf/chef/cookbook.rb +0 -2
- data/lib/berkshelf/community_rest.rb +31 -6
- data/lib/berkshelf/cookbook_source.rb +5 -1
- data/lib/berkshelf/errors.rb +24 -0
- data/lib/berkshelf/git.rb +49 -1
- data/lib/berkshelf/init_generator.rb +1 -1
- data/lib/berkshelf/locations/chef_api_location.rb +6 -3
- data/lib/berkshelf/locations/path_location.rb +2 -0
- data/lib/berkshelf/version.rb +1 -1
- data/spec/spec_helper.rb +9 -2
- data/spec/support/chef_api.rb +1 -10
- data/spec/unit/berkshelf/cached_cookbook_spec.rb +37 -458
- data/spec/unit/berkshelf/git_spec.rb +119 -9
- data/spec/unit/berkshelf/init_generator_spec.rb +0 -1
- metadata +30 -24
- data/lib/berkshelf/chef/cookbook/metadata.rb +0 -556
- data/lib/berkshelf/chef/cookbook/syntax_check.rb +0 -158
- data/lib/berkshelf/chef/digester.rb +0 -67
- data/lib/berkshelf/mixin/checksum.rb +0 -16
- data/lib/berkshelf/mixin/params_validate.rb +0 -218
- data/lib/berkshelf/mixin/shell_out.rb +0 -23
- data/lib/berkshelf/uploader.rb +0 -80
- data/spec/unit/berkshelf/uploader_spec.rb +0 -27
- data/spec/unit/chef/cookbook/metadata_spec.rb +0 -5
- data/spec/unit/chef/digester_spec.rb +0 -41
@@ -105,7 +105,11 @@ module Berkshelf
|
|
105
105
|
end
|
106
106
|
|
107
107
|
if @location.is_a?(PathLocation)
|
108
|
-
|
108
|
+
begin
|
109
|
+
@cached_cookbook = CachedCookbook.from_path(location.path)
|
110
|
+
rescue IOError
|
111
|
+
raise Berkshelf::CookbookNotFound
|
112
|
+
end
|
109
113
|
end
|
110
114
|
|
111
115
|
@locked_version = Solve::Version.new(options[:locked_version]) if options[:locked_version]
|
data/lib/berkshelf/errors.rb
CHANGED
@@ -37,6 +37,30 @@ module Berkshelf
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
class PrivateGitRepo < GitError; end
|
40
|
+
class AmbiguousGitRef < GitError
|
41
|
+
attr_reader :ref
|
42
|
+
|
43
|
+
def initialize(ref)
|
44
|
+
@ref = ref
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
out = "An error occurred during Git execution:\n"
|
49
|
+
out << "Ambiguous Git ref: #{ref}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
class InvalidGitRef < GitError
|
53
|
+
attr_reader :ref
|
54
|
+
|
55
|
+
def initialize(ref)
|
56
|
+
@ref = ref
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_s
|
60
|
+
out = "An error occurred during Git execution:\n"
|
61
|
+
out << "Invalid Git ref: #{ref}"
|
62
|
+
end
|
63
|
+
end
|
40
64
|
|
41
65
|
class DuplicateSourceDefined < BerkshelfError; status_code(105); end
|
42
66
|
class NoSolution < BerkshelfError; status_code(106); end
|
data/lib/berkshelf/git.rb
CHANGED
@@ -54,7 +54,7 @@ module Berkshelf
|
|
54
54
|
# reference to checkout
|
55
55
|
def checkout(repo_path, ref)
|
56
56
|
Dir.chdir repo_path do
|
57
|
-
git("checkout", "-
|
57
|
+
git("checkout", "-qf", revision_from_ref(repo_path, ref))
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -65,6 +65,54 @@ module Berkshelf
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
# Return the sha revision for the given reference in the given repository
|
69
|
+
#
|
70
|
+
# @param [String] repo_path
|
71
|
+
# path to a Git repo on disk
|
72
|
+
# @param [String] ref
|
73
|
+
# reference to show
|
74
|
+
#
|
75
|
+
# @return [String]
|
76
|
+
# the sha revision for the given ref
|
77
|
+
#
|
78
|
+
# @raise [AmbiguousGitRef] if the ref could refer to more than one revision
|
79
|
+
def show_ref(repo_path, ref)
|
80
|
+
Dir.chdir repo_path do
|
81
|
+
lines = git('show-ref', "'#{ref}'").lines.to_a
|
82
|
+
|
83
|
+
raise AmbiguousGitRef, ref if lines.size > 1
|
84
|
+
|
85
|
+
lines.first.chomp.split(/\s/).first
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Return the sha revision for the given reference or revision in the given repository
|
90
|
+
#
|
91
|
+
# This method is useful when you have either a sha revision, tag, or branch and
|
92
|
+
# you'd like to end up with a sha revision.
|
93
|
+
#
|
94
|
+
# @param [String] repo_path
|
95
|
+
# path to a Git repo on disk
|
96
|
+
# @param [String] ref
|
97
|
+
# reference to show
|
98
|
+
#
|
99
|
+
# @return [String]
|
100
|
+
# the sha revision for the given ref
|
101
|
+
#
|
102
|
+
# @raise [InvalidGitRef] if the ref could not be found
|
103
|
+
def revision_from_ref(repo_path, ref)
|
104
|
+
begin
|
105
|
+
show_ref(repo_path, ref)
|
106
|
+
rescue GitError
|
107
|
+
begin
|
108
|
+
git('rev-parse', ref)
|
109
|
+
ref
|
110
|
+
rescue GitError
|
111
|
+
raise InvalidGitRef, ref
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
68
116
|
# Return an absolute path to the Git executable on your system
|
69
117
|
#
|
70
118
|
# @return [String]
|
@@ -91,7 +91,7 @@ module Berkshelf
|
|
91
91
|
# name of the cookbook
|
92
92
|
def cookbook_name
|
93
93
|
@cookbook_name ||= begin
|
94
|
-
metadata =
|
94
|
+
metadata = Ridley::Chef::Cookbook::Metadata.from_file(target.join("metadata.rb").to_s)
|
95
95
|
metadata.name.empty? ? File.basename(target) : metadata.name
|
96
96
|
rescue CookbookNotFound, IOError
|
97
97
|
File.basename(target)
|
@@ -2,8 +2,9 @@ module Berkshelf
|
|
2
2
|
# @author Jamie Winsor <reset@riotgames.com>
|
3
3
|
class ChefAPILocation
|
4
4
|
class << self
|
5
|
-
|
6
|
-
|
5
|
+
# @return [Proc]
|
6
|
+
def finalizer
|
7
|
+
proc { conn.terminate if conn.alive? }
|
7
8
|
end
|
8
9
|
|
9
10
|
# @param [String] node_name
|
@@ -130,7 +131,9 @@ module Berkshelf
|
|
130
131
|
}
|
131
132
|
)
|
132
133
|
|
133
|
-
|
134
|
+
# Why do we use a class function for defining our finalizer?
|
135
|
+
# http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/
|
136
|
+
ObjectSpace.define_finalizer(self, self.class.finalizer)
|
134
137
|
end
|
135
138
|
|
136
139
|
# @param [#to_s] destination
|
data/lib/berkshelf/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -102,14 +102,21 @@ Spork.prefork do
|
|
102
102
|
run "git commit -am '#{tag} content'"
|
103
103
|
run "git tag '#{tag}' 2> /dev/null"
|
104
104
|
end if options.has_key? :tags
|
105
|
+
options[:branches].each do |branch|
|
106
|
+
run! "git checkout -b #{branch} master 2> /dev/null"
|
107
|
+
run! "echo '#{branch}' > content_file"
|
108
|
+
run! "git add content_file"
|
109
|
+
run "git commit -am '#{branch} content'"
|
110
|
+
run "git checkout master 2> /dev/null"
|
111
|
+
end if options.has_key? :branches
|
105
112
|
end
|
106
113
|
end
|
107
114
|
path
|
108
115
|
end
|
109
116
|
|
110
|
-
def
|
117
|
+
def git_sha_for_ref(repo, ref)
|
111
118
|
Dir.chdir local_git_origin_path_for(repo) do
|
112
|
-
run!("git show-ref '#{
|
119
|
+
run!("git show-ref '#{ref}'").chomp.split(/\s/).first
|
113
120
|
end
|
114
121
|
end
|
115
122
|
|
data/spec/support/chef_api.rb
CHANGED
@@ -10,7 +10,7 @@ module Berkshelf
|
|
10
10
|
|
11
11
|
def upload_cookbook(path)
|
12
12
|
cached = CachedCookbook.from_store_path(path)
|
13
|
-
|
13
|
+
ridley.cookbook.upload(cached.path, name: cached.cookbook_name)
|
14
14
|
end
|
15
15
|
|
16
16
|
# Remove the version of the given cookbook from the Chef Server defined
|
@@ -101,15 +101,6 @@ EOF
|
|
101
101
|
ssl: { verify: false }
|
102
102
|
)
|
103
103
|
end
|
104
|
-
|
105
|
-
def uploader
|
106
|
-
@uploader ||= Berkshelf::Uploader.new(
|
107
|
-
server_url: Berkshelf::Chef::Config[:chef_server_url],
|
108
|
-
client_name: Berkshelf::Chef::Config[:node_name],
|
109
|
-
client_key: Berkshelf::Chef::Config[:client_key],
|
110
|
-
ssl: { verify: false }
|
111
|
-
)
|
112
|
-
end
|
113
104
|
end
|
114
105
|
end
|
115
106
|
end
|
@@ -1,491 +1,70 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
describe
|
5
|
-
|
6
|
-
subject { CachedCookbook }
|
7
|
-
|
8
|
-
describe "#from_path" do
|
9
|
-
context "given a path that contains a cookbook with a metadata file that contains a name attribute" do
|
10
|
-
let(:cookbook_path) { fixtures_path.join("cookbooks", "example_metadata_name") }
|
11
|
-
|
12
|
-
it "returns an instance of CachedCookbook" do
|
13
|
-
subject.from_path(cookbook_path).should be_a(CachedCookbook)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "has a cookbook_name attribute set to what is found in the metadata" do
|
17
|
-
subject.from_path(cookbook_path).cookbook_name.should eql("has_metadata")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "given a path that contains a cookbook with a metadata file that does not contain a name attribute" do
|
22
|
-
let(:cookbook_path) { fixtures_path.join("cookbooks", "example_metadata_no_name") }
|
23
|
-
|
24
|
-
it "returns an instnace of CachedCookbook" do
|
25
|
-
subject.from_path(cookbook_path).should be_a(CachedCookbook)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "has a cookbook_name attribute set to the basename of the folder" do
|
29
|
-
subject.from_path(cookbook_path).cookbook_name.should eql("example_metadata_no_name")
|
30
|
-
end
|
31
|
-
|
32
|
-
it "sets value of metadata.name to the cookbook_name" do
|
33
|
-
subject.from_path(cookbook_path).metadata.name.should eql("example_metadata_no_name")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "given a path that does not contain a metadata file" do
|
38
|
-
let(:cookbook_path) { fixtures_path.join("cookbooks", "example_no_metadata") }
|
39
|
-
|
40
|
-
it "raises a CookbookNotFound error" do
|
41
|
-
lambda {
|
42
|
-
subject.from_path(cookbook_path)
|
43
|
-
}.should raise_error(Berkshelf::CookbookNotFound)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#from_store_path" do
|
49
|
-
before(:each) do
|
50
|
-
@cached_cb = subject.from_store_path(fixtures_path.join("cookbooks", "example_cookbook-0.5.0"))
|
51
|
-
end
|
52
|
-
|
53
|
-
it "returns an instance of CachedCookbook" do
|
54
|
-
@cached_cb.should be_a(CachedCookbook)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "sets a version number" do
|
58
|
-
@cached_cb.version.should eql("0.5.0")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "sets the metadata.name value to the cookbook_name" do
|
62
|
-
@cached_cb.metadata.name.should eql("example_cookbook")
|
63
|
-
end
|
64
|
-
|
65
|
-
context "given a path that does not contain a cookbook" do
|
66
|
-
it "returns nil" do
|
67
|
-
subject.from_store_path(tmp_path).should be_nil
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "given a path that does not match the CachedCookbook dirname format" do
|
72
|
-
it "returns nil" do
|
73
|
-
subject.from_store_path(fixtures_path.join("cookbooks", "example_cookbook")).should be_nil
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "#checksum" do
|
79
|
-
it "returns a checksum of the given filepath" do
|
80
|
-
subject.checksum(fixtures_path.join("cookbooks", "example_cookbook-0.5.0", "README.md")).should eql("6e21094b7a920e374e7261f50e9c4eef")
|
81
|
-
end
|
82
|
-
|
83
|
-
context "given path does not exist" do
|
84
|
-
it "raises an Errno::ENOENT error" do
|
85
|
-
lambda {
|
86
|
-
subject.checksum(fixtures_path.join("notexisting.file"))
|
87
|
-
}.should raise_error(Errno::ENOENT)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
let(:cb_path) { fixtures_path.join("cookbooks", "nginx-0.100.5") }
|
94
|
-
subject { CachedCookbook.from_store_path(cb_path) }
|
95
|
-
|
96
|
-
describe "#checksums" do
|
97
|
-
it "returns a Hash containing an entry for all matching cookbook files on disk" do
|
98
|
-
subject.checksums.should have(11).items
|
99
|
-
end
|
100
|
-
|
101
|
-
it "has a checksum for each key" do
|
102
|
-
subject.checksums.should have_key("fb1f925dcd5fc4ebf682c4442a21c619")
|
103
|
-
end
|
104
|
-
|
105
|
-
it "has a filepath for each value" do
|
106
|
-
subject.checksums.should have_value(cb_path.join("recipes/default.rb").to_s)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe "#manifest" do
|
111
|
-
it "returns a Mash with a key for each cookbook file category" do
|
112
|
-
[
|
113
|
-
:recipes,
|
114
|
-
:definitions,
|
115
|
-
:libraries,
|
116
|
-
:attributes,
|
117
|
-
:files,
|
118
|
-
:templates,
|
119
|
-
:resources,
|
120
|
-
:providers,
|
121
|
-
:root_files
|
122
|
-
].each do |category|
|
123
|
-
subject.manifest.should have_key(category)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "#validate!" do
|
129
|
-
let(:syntax_checker) { double('syntax_checker') }
|
3
|
+
describe Berkshelf::CachedCookbook do
|
4
|
+
describe "ClassMethods" do
|
5
|
+
subject { described_class }
|
130
6
|
|
7
|
+
describe "#from_store_path" do
|
131
8
|
before(:each) do
|
132
|
-
subject.
|
9
|
+
@cached_cb = subject.from_store_path(fixtures_path.join("cookbooks", "example_cookbook-0.5.0"))
|
133
10
|
end
|
134
11
|
|
135
|
-
it "
|
136
|
-
|
137
|
-
syntax_checker.should_receive(:validate_templates).and_return(true)
|
138
|
-
|
139
|
-
subject.validate!
|
12
|
+
it "returns an instance of CachedCookbook" do
|
13
|
+
@cached_cb.should be_a(described_class)
|
140
14
|
end
|
141
15
|
|
142
|
-
it "
|
143
|
-
|
144
|
-
|
145
|
-
lambda {
|
146
|
-
subject.validate!
|
147
|
-
}.should raise_error(CookbookSyntaxError)
|
148
|
-
end
|
149
|
-
|
150
|
-
it "raises CookbookSyntaxError if the cookbook contains invalid template files" do
|
151
|
-
syntax_checker.should_receive(:validate_ruby_files).and_return(true)
|
152
|
-
syntax_checker.should_receive(:validate_templates).and_return(false)
|
153
|
-
|
154
|
-
lambda {
|
155
|
-
subject.validate!
|
156
|
-
}.should raise_error(CookbookSyntaxError)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe "#file_metadata" do
|
161
|
-
let(:file) { subject.path.join("files", "default", "mime.types") }
|
162
|
-
|
163
|
-
before(:each) { @metadata = subject.file_metadata(:file, file) }
|
164
|
-
|
165
|
-
it "has a 'path' key whose value is a relative path from the CachedCookbook's path" do
|
166
|
-
@metadata.should have_key(:path)
|
167
|
-
@metadata[:path].should be_relative_path
|
168
|
-
@metadata[:path].should eql("files/default/mime.types")
|
16
|
+
it "sets a version number" do
|
17
|
+
@cached_cb.version.should eql("0.5.0")
|
169
18
|
end
|
170
19
|
|
171
|
-
it "
|
172
|
-
@metadata.should
|
173
|
-
@metadata[:name].should eql("mime.types")
|
20
|
+
it "sets the metadata.name value to the cookbook_name" do
|
21
|
+
@cached_cb.metadata.name.should eql("example_cookbook")
|
174
22
|
end
|
175
23
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
end
|
180
|
-
|
181
|
-
it "has a 'specificity' key" do
|
182
|
-
@metadata.should have_key(:specificity)
|
183
|
-
end
|
184
|
-
|
185
|
-
context "given a 'template' or 'file' berksfile type" do
|
186
|
-
let(:file) { subject.path.join("files", "ubuntu", "mime.types") }
|
187
|
-
before(:each) { @metadata = subject.file_metadata(:files, file) }
|
188
|
-
|
189
|
-
it "has a 'specificity' key whose value represents the specificity found in filepath" do
|
190
|
-
@metadata[:specificity].should eql("ubuntu")
|
24
|
+
context "given a path that does not contain a cookbook" do
|
25
|
+
it "returns nil" do
|
26
|
+
subject.from_store_path(tmp_path).should be_nil
|
191
27
|
end
|
192
28
|
end
|
193
29
|
|
194
|
-
context "given
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
it "has a 'specificity' key whose value is 'default'" do
|
199
|
-
@metadata[:specificity].should eql("default")
|
30
|
+
context "given a path that does not match the CachedCookbook dirname format" do
|
31
|
+
it "returns nil" do
|
32
|
+
subject.from_store_path(fixtures_path.join("cookbooks", "example_cookbook")).should be_nil
|
200
33
|
end
|
201
34
|
end
|
202
35
|
end
|
203
36
|
|
204
|
-
describe "#
|
205
|
-
|
206
|
-
|
207
|
-
end
|
208
|
-
|
209
|
-
let(:cookbook_name) { subject.cookbook_name }
|
210
|
-
let(:cookbook_version) { subject.version }
|
211
|
-
|
212
|
-
it "has a 'recipes' key with a value of an Array Hashes" do
|
213
|
-
@hash.should have_key('recipes')
|
214
|
-
@hash['recipes'].should be_a(Array)
|
215
|
-
@hash['recipes'].each do |item|
|
216
|
-
item.should be_a(Hash)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
it "has a 'name' key value pair in a Hash of the 'recipes' Array of Hashes" do
|
221
|
-
@hash['recipes'].first.should have_key('name')
|
222
|
-
end
|
223
|
-
|
224
|
-
it "has a 'path' key value pair in a Hash of the 'recipes' Array of Hashes" do
|
225
|
-
@hash['recipes'].first.should have_key('path')
|
226
|
-
end
|
227
|
-
|
228
|
-
it "has a 'checksum' key value pair in a Hash of the 'recipes' Array of Hashes" do
|
229
|
-
@hash['recipes'].first.should have_key('checksum')
|
230
|
-
end
|
231
|
-
|
232
|
-
it "has a 'specificity' key value pair in a Hash of the 'recipes' Array of Hashes" do
|
233
|
-
@hash['recipes'].first.should have_key('specificity')
|
234
|
-
end
|
235
|
-
|
236
|
-
it "has a 'definitions' key with a value of an Array Hashes" do
|
237
|
-
@hash.should have_key('definitions')
|
238
|
-
@hash['definitions'].should be_a(Array)
|
239
|
-
@hash['definitions'].each do |item|
|
240
|
-
item.should be_a(Hash)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
it "has a 'name' key value pair in a Hash of the 'definitions' Array of Hashes" do
|
245
|
-
@hash['definitions'].first.should have_key('name')
|
246
|
-
end
|
247
|
-
|
248
|
-
it "has a 'path' key value pair in a Hash of the 'definitions' Array of Hashes" do
|
249
|
-
@hash['definitions'].first.should have_key('path')
|
250
|
-
end
|
251
|
-
|
252
|
-
it "has a 'checksum' key value pair in a Hash of the 'definitions' Array of Hashes" do
|
253
|
-
@hash['definitions'].first.should have_key('checksum')
|
254
|
-
end
|
255
|
-
|
256
|
-
it "has a 'specificity' key value pair in a Hash of the 'definitions' Array of Hashes" do
|
257
|
-
@hash['definitions'].first.should have_key('specificity')
|
258
|
-
end
|
259
|
-
|
260
|
-
it "has a 'libraries' key with a value of an Array Hashes" do
|
261
|
-
@hash.should have_key('libraries')
|
262
|
-
@hash['libraries'].should be_a(Array)
|
263
|
-
@hash['libraries'].each do |item|
|
264
|
-
item.should be_a(Hash)
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
it "has a 'name' key value pair in a Hash of the 'libraries' Array of Hashes" do
|
269
|
-
@hash['libraries'].first.should have_key('name')
|
270
|
-
end
|
271
|
-
|
272
|
-
it "has a 'path' key value pair in a Hash of the 'libraries' Array of Hashes" do
|
273
|
-
@hash['libraries'].first.should have_key('path')
|
274
|
-
end
|
275
|
-
|
276
|
-
it "has a 'checksum' key value pair in a Hash of the 'libraries' Array of Hashes" do
|
277
|
-
@hash['libraries'].first.should have_key('checksum')
|
278
|
-
end
|
279
|
-
|
280
|
-
it "has a 'specificity' key value pair in a Hash of the 'libraries' Array of Hashes" do
|
281
|
-
@hash['libraries'].first.should have_key('specificity')
|
282
|
-
end
|
283
|
-
|
284
|
-
it "has a 'attributes' key with a value of an Array Hashes" do
|
285
|
-
@hash.should have_key('attributes')
|
286
|
-
@hash['attributes'].should be_a(Array)
|
287
|
-
@hash['attributes'].each do |item|
|
288
|
-
item.should be_a(Hash)
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
it "has a 'name' key value pair in a Hash of the 'attributes' Array of Hashes" do
|
293
|
-
@hash['attributes'].first.should have_key('name')
|
294
|
-
end
|
295
|
-
|
296
|
-
it "has a 'path' key value pair in a Hash of the 'attributes' Array of Hashes" do
|
297
|
-
@hash['attributes'].first.should have_key('path')
|
298
|
-
end
|
299
|
-
|
300
|
-
it "has a 'checksum' key value pair in a Hash of the 'attributes' Array of Hashes" do
|
301
|
-
@hash['attributes'].first.should have_key('checksum')
|
302
|
-
end
|
303
|
-
|
304
|
-
it "has a 'specificity' key value pair in a Hash of the 'attributes' Array of Hashes" do
|
305
|
-
@hash['attributes'].first.should have_key('specificity')
|
306
|
-
end
|
307
|
-
|
308
|
-
it "has a 'files' key with a value of an Array Hashes" do
|
309
|
-
@hash.should have_key('files')
|
310
|
-
@hash['files'].should be_a(Array)
|
311
|
-
@hash['files'].each do |item|
|
312
|
-
item.should be_a(Hash)
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
it "has a 'name' key value pair in a Hash of the 'files' Array of Hashes" do
|
317
|
-
@hash['files'].first.should have_key('name')
|
318
|
-
end
|
319
|
-
|
320
|
-
it "has a 'path' key value pair in a Hash of the 'files' Array of Hashes" do
|
321
|
-
@hash['files'].first.should have_key('path')
|
37
|
+
describe "#checksum" do
|
38
|
+
it "returns a checksum of the given filepath" do
|
39
|
+
subject.checksum(fixtures_path.join("cookbooks", "example_cookbook-0.5.0", "README.md")).should eql("6e21094b7a920e374e7261f50e9c4eef")
|
322
40
|
end
|
323
41
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
@hash['files'].first.should have_key('specificity')
|
330
|
-
end
|
331
|
-
|
332
|
-
it "has a 'templates' key with a value of an Array Hashes" do
|
333
|
-
@hash.should have_key('templates')
|
334
|
-
@hash['templates'].should be_a(Array)
|
335
|
-
@hash['templates'].each do |item|
|
336
|
-
item.should be_a(Hash)
|
42
|
+
context "given path does not exist" do
|
43
|
+
it "raises an Errno::ENOENT error" do
|
44
|
+
lambda {
|
45
|
+
subject.checksum(fixtures_path.join("notexisting.file"))
|
46
|
+
}.should raise_error(Errno::ENOENT)
|
337
47
|
end
|
338
48
|
end
|
339
|
-
|
340
|
-
it "has a 'name' key value pair in a Hash of the 'templates' Array of Hashes" do
|
341
|
-
@hash['templates'].first.should have_key('name')
|
342
|
-
end
|
343
|
-
|
344
|
-
it "has a 'path' key value pair in a Hash of the 'templates' Array of Hashes" do
|
345
|
-
@hash['templates'].first.should have_key('path')
|
346
|
-
end
|
347
|
-
|
348
|
-
it "has a 'checksum' key value pair in a Hash of the 'templates' Array of Hashes" do
|
349
|
-
@hash['templates'].first.should have_key('checksum')
|
350
|
-
end
|
351
|
-
|
352
|
-
it "has a 'specificity' key value pair in a Hash of the 'templates' Array of Hashes" do
|
353
|
-
@hash['templates'].first.should have_key('specificity')
|
354
|
-
end
|
355
|
-
|
356
|
-
it "has a 'resources' key with a value of an Array Hashes" do
|
357
|
-
@hash.should have_key('resources')
|
358
|
-
@hash['resources'].should be_a(Array)
|
359
|
-
@hash['resources'].each do |item|
|
360
|
-
item.should be_a(Hash)
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
it "has a 'name' key value pair in a Hash of the 'resources' Array of Hashes" do
|
365
|
-
@hash['resources'].first.should have_key('name')
|
366
|
-
end
|
367
|
-
|
368
|
-
it "has a 'path' key value pair in a Hash of the 'resources' Array of Hashes" do
|
369
|
-
@hash['resources'].first.should have_key('path')
|
370
|
-
end
|
371
|
-
|
372
|
-
it "has a 'checksum' key value pair in a Hash of the 'resources' Array of Hashes" do
|
373
|
-
@hash['resources'].first.should have_key('checksum')
|
374
|
-
end
|
375
|
-
|
376
|
-
it "has a 'specificity' key value pair in a Hash of the 'resources' Array of Hashes" do
|
377
|
-
@hash['resources'].first.should have_key('specificity')
|
378
|
-
end
|
379
|
-
|
380
|
-
it "has a 'providers' key with a value of an Array Hashes" do
|
381
|
-
@hash.should have_key('providers')
|
382
|
-
@hash['providers'].should be_a(Array)
|
383
|
-
@hash['providers'].each do |item|
|
384
|
-
item.should be_a(Hash)
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
it "has a 'name' key value pair in a Hash of the 'providers' Array of Hashes" do
|
389
|
-
@hash['providers'].first.should have_key('name')
|
390
|
-
end
|
391
|
-
|
392
|
-
it "has a 'path' key value pair in a Hash of the 'providers' Array of Hashes" do
|
393
|
-
@hash['providers'].first.should have_key('path')
|
394
|
-
end
|
395
|
-
|
396
|
-
it "has a 'checksum' key value pair in a Hash of the 'providers' Array of Hashes" do
|
397
|
-
@hash['providers'].first.should have_key('checksum')
|
398
|
-
end
|
399
|
-
|
400
|
-
it "has a 'specificity' key value pair in a Hash of the 'providers' Array of Hashes" do
|
401
|
-
@hash['providers'].first.should have_key('specificity')
|
402
|
-
end
|
403
|
-
|
404
|
-
it "has a 'root_files' key with a value of an Array Hashes" do
|
405
|
-
@hash.should have_key('root_files')
|
406
|
-
@hash['root_files'].should be_a(Array)
|
407
|
-
@hash['root_files'].each do |item|
|
408
|
-
item.should be_a(Hash)
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
it "has a 'name' key value pair in a Hash of the 'root_files' Array of Hashes" do
|
413
|
-
@hash['root_files'].first.should have_key('name')
|
414
|
-
end
|
415
|
-
|
416
|
-
it "has a 'path' key value pair in a Hash of the 'root_files' Array of Hashes" do
|
417
|
-
@hash['root_files'].first.should have_key('path')
|
418
|
-
end
|
419
|
-
|
420
|
-
it "has a 'checksum' key value pair in a Hash of the 'root_files' Array of Hashes" do
|
421
|
-
@hash['root_files'].first.should have_key('checksum')
|
422
|
-
end
|
423
|
-
|
424
|
-
it "has a 'specificity' key value pair in a Hash of the 'root_files' Array of Hashes" do
|
425
|
-
@hash['root_files'].first.should have_key('specificity')
|
426
|
-
end
|
427
|
-
|
428
|
-
it "has a 'cookbook_name' key with a String value" do
|
429
|
-
@hash.should have_key('cookbook_name')
|
430
|
-
@hash['cookbook_name'].should be_a(String)
|
431
|
-
end
|
432
|
-
|
433
|
-
it "has a 'metadata' key with a Cookbook::Metadata value" do
|
434
|
-
@hash.should have_key('metadata')
|
435
|
-
@hash['metadata'].should be_a(Berkshelf::Chef::Cookbook::Metadata)
|
436
|
-
end
|
437
|
-
|
438
|
-
it "has a 'version' key with a String value" do
|
439
|
-
@hash.should have_key('version')
|
440
|
-
@hash['version'].should be_a(String)
|
441
|
-
end
|
442
|
-
|
443
|
-
it "has a 'name' key with a String value" do
|
444
|
-
@hash.should have_key('name')
|
445
|
-
@hash['name'].should be_a(String)
|
446
|
-
end
|
447
|
-
|
448
|
-
it "has a value containing the cookbook name and version separated by a dash for 'name'" do
|
449
|
-
name, version = @hash['name'].split('-')
|
450
|
-
|
451
|
-
name.should eql(cookbook_name)
|
452
|
-
version.should eql(cookbook_version)
|
453
|
-
end
|
454
|
-
|
455
|
-
it "has a 'chef_type' key with 'cookbook_version' as the value" do
|
456
|
-
@hash.should have_key('chef_type')
|
457
|
-
@hash['chef_type'].should eql("cookbook_version")
|
458
|
-
end
|
459
49
|
end
|
50
|
+
end
|
460
51
|
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
end
|
52
|
+
describe "#dependencies" do
|
53
|
+
let(:dependencies) { { "mysql" => "= 1.2.0", "ntp" => ">= 0.0.0" } }
|
54
|
+
let(:recommendations) { { "database" => ">= 0.0.0" } }
|
465
55
|
|
466
|
-
|
467
|
-
|
468
|
-
parse_json(@json)['json_class'].should eql("Chef::CookbookVersion")
|
469
|
-
end
|
56
|
+
let(:cb_path) do
|
57
|
+
generate_cookbook(Berkshelf.cookbook_store.storage_path, "sparkle", "0.1.0", dependencies: dependencies, recommendations: recommendations)
|
470
58
|
end
|
471
59
|
|
472
|
-
|
473
|
-
let(:dependencies) { { "mysql" => "= 1.2.0", "ntp" => ">= 0.0.0" } }
|
474
|
-
let(:recommendations) { { "database" => ">= 0.0.0" } }
|
60
|
+
subject { described_class.from_store_path(cb_path) }
|
475
61
|
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
subject { CachedCookbook.from_store_path(cb_path) }
|
481
|
-
|
482
|
-
it "contains depends from the cookbook metadata" do
|
483
|
-
subject.dependencies.should include(dependencies)
|
484
|
-
end
|
62
|
+
it "contains depends from the cookbook metadata" do
|
63
|
+
subject.dependencies.should include(dependencies)
|
64
|
+
end
|
485
65
|
|
486
|
-
|
487
|
-
|
488
|
-
end
|
66
|
+
it "contains recommendations from the cookbook metadata" do
|
67
|
+
subject.dependencies.should include(recommendations)
|
489
68
|
end
|
490
69
|
end
|
491
70
|
end
|