knife_cookbook_dependencies 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/README.rdoc +41 -2
- data/Rakefile +42 -0
- data/features/lib/chef/knife/error_messages.feature +16 -0
- data/features/lib/chef/knife/lockfile.feature +25 -0
- data/features/lib/chef/knife/without.feature +27 -0
- data/features/support/env.rb +30 -0
- data/features/support/step_definitions.rb +22 -0
- data/knife_cookbook_dependencies.gemspec +6 -2
- data/lib/chef/knife/cookbook_dependencies_install.rb +12 -6
- data/lib/kcd.rb +1 -0
- data/lib/{knife_cookbook_dependencies → kcd}/cookbook.rb +72 -40
- data/lib/{knife_cookbook_dependencies → kcd}/cookbookfile.rb +12 -11
- data/lib/kcd/dsl.rb +13 -0
- data/lib/{knife_cookbook_dependencies → kcd}/error_messages.rb +1 -1
- data/lib/{knife_cookbook_dependencies → kcd}/git.rb +0 -0
- data/lib/{knife_cookbook_dependencies → kcd}/knife_utils.rb +1 -1
- data/lib/{knife_cookbook_dependencies → kcd}/lockfile.rb +8 -5
- data/lib/{knife_cookbook_dependencies → kcd}/metacookbook.rb +1 -1
- data/lib/{knife_cookbook_dependencies → kcd}/shelf.rb +30 -5
- data/lib/{knife_cookbook_dependencies → kcd}/version.rb +1 -1
- data/lib/knife_cookbook_dependencies.rb +20 -13
- data/spec/acceptance/knife_cookbook_dependencies_spec.rb +1 -11
- data/spec/fixtures/lockfile_spec/with_lock/Cookbookfile +1 -0
- data/spec/fixtures/lockfile_spec/without_lock/Cookbookfile.lock +5 -0
- data/spec/lib/{knife_cookbook_dependencies → kcd}/cookbook_spec.rb +43 -14
- data/spec/lib/{knife_cookbook_dependencies → kcd}/cookbookfile_spec.rb +3 -3
- data/spec/lib/kcd/dsl_spec.rb +56 -0
- data/spec/lib/{knife_cookbook_dependencies → kcd}/git_spec.rb +0 -0
- data/spec/lib/kcd/lockfile_spec.rb +54 -0
- data/spec/lib/kcd/shelf_spec.rb +81 -0
- data/spec/spec_helper.rb +22 -2
- data/todo.txt +8 -8
- metadata +98 -51
- data/lib/knife_cookbook_dependencies/dependency_reader.rb +0 -46
- data/lib/knife_cookbook_dependencies/dsl.rb +0 -7
- data/spec/lib/knife_cookbook_dependencies/dependency_reader_spec.rb +0 -42
- data/spec/lib/knife_cookbook_dependencies/dsl_spec.rb +0 -29
- data/spec/lib/knife_cookbook_dependencies/shelf_spec.rb +0 -37
@@ -1,46 +0,0 @@
|
|
1
|
-
module KnifeCookbookDependencies
|
2
|
-
class DependencyReader
|
3
|
-
attr_reader :dependency_list, :cookbook
|
4
|
-
|
5
|
-
def initialize(cookbook)
|
6
|
-
@cookbook = cookbook
|
7
|
-
@dependency_list = []
|
8
|
-
end
|
9
|
-
|
10
|
-
def read
|
11
|
-
Dir.chdir(@cookbook.full_path) do
|
12
|
-
# XXX this filename is required because it sets __FILE__, which is
|
13
|
-
# used for README.md parsing among other things in metadata.rb files
|
14
|
-
instance_eval(@cookbook.metadata_file, @cookbook.metadata_filename)
|
15
|
-
end
|
16
|
-
@dependency_list
|
17
|
-
end
|
18
|
-
|
19
|
-
def depends(*args)
|
20
|
-
name, constraint = args
|
21
|
-
|
22
|
-
dependency_cookbook = KnifeCookbookDependencies.shelf.get_cookbook(name) || get_dependency(name)
|
23
|
-
if dependency_cookbook
|
24
|
-
dependency_cookbook.add_version_constraint constraint
|
25
|
-
else
|
26
|
-
@dependency_list << Cookbook.new(*args)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def get_dependency(name)
|
31
|
-
@dependency_list.select { |c| c.name == name }.first
|
32
|
-
end
|
33
|
-
|
34
|
-
def method_missing(method, *args)
|
35
|
-
# Don't blow up when other metadata DSL methods are called, we
|
36
|
-
# only care about #depends.
|
37
|
-
end
|
38
|
-
|
39
|
-
def name(the_name)
|
40
|
-
# Module#name is defined, so method_missing won't catch it
|
41
|
-
# when running instance_eval on a metadata.rb that overrides
|
42
|
-
# the name
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module KnifeCookbookDependencies
|
4
|
-
describe DependencyReader do
|
5
|
-
subject { DependencyReader.new(Cookbook.new('mysql')) }
|
6
|
-
|
7
|
-
before do
|
8
|
-
@cookbook = Cookbook.new('mysql')
|
9
|
-
@cookbook.download # TODO: mock out
|
10
|
-
@cookbook.unpack
|
11
|
-
end
|
12
|
-
|
13
|
-
after do
|
14
|
-
@cookbook.clean
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should parse the metadata file for dependencies" do
|
18
|
-
subject.read.should == [Cookbook.new('openssl')]
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should not blow up when reading a metadata.rb that overrides the name" do
|
22
|
-
Cookbook.any_instance.stub(:metadata_file).and_return <<M
|
23
|
-
name 'dontblowupplease'
|
24
|
-
version '1.2.3'
|
25
|
-
M
|
26
|
-
-> { subject.read }.should_not raise_error
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should display a warning when no version is defined in the metadata.rb'
|
30
|
-
|
31
|
-
it "should add a constraint to the cookbook on the shelf instead of adding a new dependency" do
|
32
|
-
KnifeCookbookDependencies.shelf.shelve_cookbook example_cookbook_from_path
|
33
|
-
subject.depends('example_cookbook')
|
34
|
-
subject.dependency_list.should be_empty
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should create a new cookbook if the cookbook is not found on the shelf" do
|
38
|
-
subject.depends('example_cookbook')
|
39
|
-
subject.dependency_list.first.name.should == 'example_cookbook'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'knife_cookbook_dependencies/dsl'
|
3
|
-
|
4
|
-
module KnifeCookbookDependencies
|
5
|
-
describe DSL do
|
6
|
-
include DSL
|
7
|
-
|
8
|
-
describe "#cookbook" do
|
9
|
-
after do
|
10
|
-
KnifeCookbookDependencies.shelf.cookbooks.each(&:clean)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should add the cookbooks to the shelf' do
|
14
|
-
cookbook "ntp"
|
15
|
-
cookbook "nginx"
|
16
|
-
|
17
|
-
['ntp', 'nginx'].each do |cookbook|
|
18
|
-
KnifeCookbookDependencies.shelf.cookbooks.collect(&:name).should include cookbook
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should take version constraints' do
|
23
|
-
Cookbook.any_instance.stub(:clean)
|
24
|
-
cookbook 'ntp', '= 1.2.3'
|
25
|
-
KnifeCookbookDependencies.shelf.cookbooks.select {|c| c.name == 'ntp'}.first.version_constraints.first.should == DepSelector::VersionConstraint.new('= 1.2.3')
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module KnifeCookbookDependencies
|
4
|
-
describe Shelf do
|
5
|
-
describe '#get_cookbook' do
|
6
|
-
it "should return nil if a cookbook doesn't exist on the shelf" do
|
7
|
-
Shelf.new.get_cookbook('arbitrary').should be_nil
|
8
|
-
end
|
9
|
-
it "should return the cookbook if the cookbook exists on the shelf" do
|
10
|
-
s = Shelf.new
|
11
|
-
s.shelve_cookbook example_cookbook_from_path
|
12
|
-
s.get_cookbook(example_cookbook_from_path.name).should_not be_nil
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "#shelve_cookbook" do
|
17
|
-
subject { Shelf.new }
|
18
|
-
it 'should store shelved cookbooks' do
|
19
|
-
subject.shelve_cookbook 'acookbook'
|
20
|
-
subject.cookbooks.collect(&:name).should include 'acookbook'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should take version constraints' do
|
24
|
-
subject.shelve_cookbook 'acookbook', '= 1.2.3'
|
25
|
-
subject.cookbooks.last.version_constraints.should == [DepSelector::VersionConstraint.new('= 1.2.3')]
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should resolve the dependency graph of the cookbooks on the shelf" do
|
29
|
-
subject.shelve_cookbook 'mysql', "= 1.2.4"
|
30
|
-
|
31
|
-
subject.resolve_dependencies.should == ({"mysql" => DepSelector::Version.new("1.2.4"), "openssl" => DepSelector::Version.new("1.0.0")})
|
32
|
-
Cookbook.new('mysql').clean
|
33
|
-
Cookbook.new('openssl').clean
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|