cookbook_spec.rb 4.39 KB
Newer Older
1
#
2
# Author:: Adam Jacob (<adam@opscode.com>)
Adam Jacob's avatar
Adam Jacob committed
3
# Copyright:: Copyright (c) 2008 Opscode, Inc.
4
5
6
7
8
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
9
# 
10
#     http://www.apache.org/licenses/LICENSE-2.0
11
# 
12
13
14
15
16
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
17
18
#

19
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
20

21
describe Chef::CookbookVersion do
22
#  COOKBOOK_PATH = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks", "openldap"))
23
  before(:each) do
24
25
26
27
    Chef::Config.cookbook_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks"))
    @cookbook_collection = Chef::CookbookCollection.new(Chef::CookbookLoader.new)
    @cookbook = @cookbook_collection[:openldap]
    @node = Chef::Node.new
Nuo Yan's avatar
Nuo Yan committed
28
    @node.name "JuliaChild"
29
    @run_context = Chef::RunContext.new(@node, @cookbook_collection)
30
31
32
  end
  
  it "should have a name" do
33
    @cookbook.name.should == :openldap
34
35
  end
  
36
37
38
39
40
41
  it "should allow you to set the list of attribute files and create the mapping from short names to paths" do
    @cookbook.attribute_filenames = [ "attributes/one.rb", "attributes/two.rb" ]
    @cookbook.attribute_filenames.should == [ "attributes/one.rb", "attributes/two.rb" ]
    @cookbook.attribute_filenames_by_short_filename.keys.sort.should eql(["one", "two"])
    @cookbook.attribute_filenames_by_short_filename["one"].should == "attributes/one.rb"
    @cookbook.attribute_filenames_by_short_filename["two"].should == "attributes/two.rb"
42
43
  end
  
44
45
46
47
48
49
  it "should allow you to set the list of recipe files and create the mapping of recipe short name to filename" do
    @cookbook.recipe_filenames = [ "recipes/one.rb", "recipes/two.rb" ]
    @cookbook.recipe_filenames.should == [ "recipes/one.rb", "recipes/two.rb" ]
    @cookbook.recipe_filenames_by_name.keys.sort.should eql(["one", "two"])
    @cookbook.recipe_filenames_by_name["one"].should == "recipes/one.rb"
    @cookbook.recipe_filenames_by_name["two"].should == "recipes/two.rb"
50
51
  end

52
53
54
55
56
57
58
  it "should generate a list of recipes by fully-qualified name" do
    @cookbook.recipe_filenames = [ "recipes/one.rb", "/recipes/two.rb", "three.rb" ]
    @cookbook.fully_qualified_recipe_names.include?("openldap::one").should == true
    @cookbook.fully_qualified_recipe_names.include?("openldap::two").should == true
    @cookbook.fully_qualified_recipe_names.include?("openldap::three").should == true
  end
  
59
60
61
62
63
64
65
66
67
  it "should find a preferred file" do
    pending
  end
  
  it "should not return an unchanged preferred file" do
    pending
    @cookbook.preferred_filename(@node, :files, 'a-filename', 'the-checksum').should be_nil
  end
  
68
# TODO: timh, cw: 5/20/2010: removed CookbookVersion.recipe? as it's not used; see cookbook.rb
69
70
71
72
73
74
#   it "should allow you to test for a recipe with recipe?" do
#     @cookbook.recipe_filenames = [ "one", "two" ]
#     @cookbook.recipe?("one").should eql(true)
#     @cookbook.recipe?("shanghai").should eql(false)
#   end
  
75
# TODO: timh, cw: 5/20/2010: removed CookbookVersion.recipe? as it's not used; see cookbook.rb
76
77
78
79
80
81
82
83
84
85
86
87
88
#  it "should allow you to test for a recipe? with a fq recipe name" do
#    @cookbook.recipe_filenames = [ "one", "two" ]
#    @cookbook.recipe?("openldap::one").should eql(true)
#    @cookbook.recipe?("shanghai::city").should eql(false)
#  end
  
  it "should allow you to include a fully-qualified recipe using the DSL" do
    # DSL method include_recipe allows multiple arguments, so extract the first
    recipe = @run_context.include_recipe("openldap::gigantor").first

    recipe.recipe_name.should == "gigantor"
    recipe.cookbook_name.should == :openldap
    @run_context.resource_collection[0].name.should == "blanket"
89
90
91
  end
  
  it "should raise an ArgumentException if you try to load a bad recipe name" do
92
    lambda { @cookbook.load_recipe("doesnt_exist", @node) }.should raise_error(ArgumentError)
93
  end
94
95

  it "should allow you to load an attribute file by name via load_attribute" do
96
97
    @node.include_attribute("openldap::smokey")
    @node.smokey.should == "robinson"
98
  end
99
  
100
end