|
| 1 | +# |
| 2 | +# Author:: Adam Jacob (<adam@opscode.com>) |
| 3 | +# Copyright:: Copyright (c) 2008 Opscode, Inc. |
| 4 | +# License:: Apache License, Version 2.0 |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | + |
| 19 | +require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) |
| 20 | + |
| 21 | +describe Chef::RunList do |
| 22 | + before(:each) do |
| 23 | + @run_list = Chef::RunList.new |
| 24 | + end |
| 25 | + |
| 26 | + describe "initialize" do |
| 27 | + it "should return a Chef::RunList" do |
| 28 | + @run_list.should be_a_kind_of(Chef::RunList) |
| 29 | + end |
| 30 | + end |
| 31 | + |
| 32 | + describe "<<" do |
| 33 | + it "should add a recipe to the run list and recipe list with the fully qualified name" do |
| 34 | + @run_list << 'recipe[needy]' |
| 35 | + @run_list.run_list.include?('recipe[needy]').should == true |
| 36 | + @run_list.recipes.include?('needy').should == true |
| 37 | + end |
| 38 | + |
| 39 | + it "should add a role to the run list and role list with the fully qualified name" do |
| 40 | + @run_list << "role[woot]" |
| 41 | + @run_list.run_list.include?('role[woot]').should == true |
| 42 | + @run_list.roles.include?('woot').should == true |
| 43 | + end |
| 44 | + |
| 45 | + it "should accept recipes that are unqualified" do |
| 46 | + @run_list << "needy" |
| 47 | + @run_list.run_list.include?('recipe[needy]').should == true |
| 48 | + @run_list.recipes.include?('needy').should == true |
| 49 | + end |
| 50 | + |
| 51 | + it "should not allow duplicates" do |
| 52 | + @run_list << "needy" |
| 53 | + @run_list << "needy" |
| 54 | + @run_list.run_list.length.should == 1 |
| 55 | + @run_list.recipes.length.should == 1 |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + describe "==" do |
| 60 | + it "should believe two RunLists are equal if they have the same members" do |
| 61 | + @run_list << "foo" |
| 62 | + r = Chef::RunList.new |
| 63 | + r << "foo" |
| 64 | + @run_list.should == r |
| 65 | + end |
| 66 | + |
| 67 | + it "should believe a RunList is equal to an array named after it's members" do |
| 68 | + @run_list << "foo" |
| 69 | + @run_list << "baz" |
| 70 | + @run_list.should == [ "foo", "baz" ] |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + describe "empty?" do |
| 75 | + it "should be emtpy if the run list has no members" do |
| 76 | + @run_list.empty?.should == true |
| 77 | + end |
| 78 | + |
| 79 | + it "should not be empty if the run list has members" do |
| 80 | + @run_list << "chromeo" |
| 81 | + @run_list.empty?.should == false |
| 82 | + end |
| 83 | + end |
| 84 | + |
| 85 | + describe "[]" do |
| 86 | + it "should let you look up a member in the run list by position" do |
| 87 | + @run_list << 'recipe[loulou]' |
| 88 | + @run_list[0].should == 'recipe[loulou]' |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + describe "[]=" do |
| 93 | + it "should let you set a member of the run list by position" do |
| 94 | + @run_list[0] = 'recipe[loulou]' |
| 95 | + @run_list[0].should == 'recipe[loulou]' |
| 96 | + end |
| 97 | + |
| 98 | + it "should properly expand a member of the run list given by position" do |
| 99 | + @run_list[0] = 'loulou' |
| 100 | + @run_list[0].should == 'recipe[loulou]' |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | + describe "each" do |
| 105 | + it "should yield each member to your block" do |
| 106 | + @run_list << "foo" |
| 107 | + @run_list << "bar" |
| 108 | + seen = Array.new |
| 109 | + @run_list.each { |r| seen << r } |
| 110 | + seen.should be_include("recipe[foo]") |
| 111 | + seen.should be_include("recipe[bar]") |
| 112 | + end |
| 113 | + end |
| 114 | + |
| 115 | + describe "each_index" do |
| 116 | + it "should yield each members index to your block" do |
| 117 | + to_add = [ "recipe[foo]", "recipe[bar]", "recipe[baz]" ] |
| 118 | + to_add.each { |i| @run_list << i } |
| 119 | + @run_list.each_index { |i| @run_list[i].should == to_add[i] } |
| 120 | + end |
| 121 | + end |
| 122 | + |
| 123 | + describe "include?" do |
| 124 | + it "should be true if the run list includes the item" do |
| 125 | + @run_list << "foo" |
| 126 | + @run_list.include?("foo") |
| 127 | + end |
| 128 | + end |
| 129 | + |
| 130 | + describe "reset" do |
| 131 | + it "should reset the run_list based on the array you pass" do |
| 132 | + @run_list << "chromeo" |
| 133 | + list = %w{camp chairs snakes clowns} |
| 134 | + @run_list.reset(list) |
| 135 | + list.each { |i| @run_list.should be_include(i) } |
| 136 | + @run_list.include?("chromeo").should == false |
| 137 | + end |
| 138 | + end |
| 139 | + |
| 140 | + describe "expand" do |
| 141 | + before(:each) do |
| 142 | + @role = Chef::Role.new |
| 143 | + @role.name "stubby" |
| 144 | + @role.recipes "one", "two" |
| 145 | + @role.default_attributes :one => :two |
| 146 | + @role.override_attributes :three => :four |
| 147 | + |
| 148 | + Chef::Role.stub!(:from_disk).and_return(@role) |
| 149 | + Chef::Role.stub!(:load).and_return(@role) |
| 150 | + @rest = mock("Chef::REST", { :get_rest => @role }) |
| 151 | + Chef::REST.stub!(:new).and_return(@rest) |
| 152 | + |
| 153 | + @run_list << "role[stubby]" |
| 154 | + @run_list << "kitty" |
| 155 | + end |
| 156 | + |
| 157 | + describe "from disk" do |
| 158 | + it "should load the role from disk" do |
| 159 | + Chef::Role.should_receive(:from_disk).with("stubby") |
| 160 | + @run_list.expand("disk") |
| 161 | + end |
| 162 | + end |
| 163 | + |
| 164 | + describe "from the chef server" do |
| 165 | + it "should load the role from the chef server" do |
| 166 | + @rest.should_receive(:get_rest).with("roles/stubby") |
| 167 | + @run_list.expand("server") |
| 168 | + end |
| 169 | + |
| 170 | + it "should default to expanding from the server" do |
| 171 | + @rest.should_receive(:get_rest).with("roles/stubby") |
| 172 | + @run_list.expand |
| 173 | + end |
| 174 | + end |
| 175 | + |
| 176 | + describe "from couchdb" do |
| 177 | + it "should load the role from couchdb" do |
| 178 | + Chef::Role.should_receive(:load).with("stubby") |
| 179 | + @run_list.expand("couchdb") |
| 180 | + end |
| 181 | + end |
| 182 | + |
| 183 | + it "should return the list of expanded recipes" do |
| 184 | + recipes, default, override = @run_list.expand |
| 185 | + recipes[0].should == "one" |
| 186 | + recipes[1].should == "two" |
| 187 | + end |
| 188 | + |
| 189 | + it "should return the list of default attributes" do |
| 190 | + recipes, default, override = @run_list.expand |
| 191 | + default[:one].should == :two |
| 192 | + end |
| 193 | + |
| 194 | + it "should return the list of override attributes" do |
| 195 | + recipes, default, override = @run_list.expand |
| 196 | + override[:three].should == :four |
| 197 | + end |
| 198 | + |
| 199 | + end |
| 200 | +end |
0 commit comments