Navigation Menu

Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Commit

Permalink
Use node, not @node in Chef::Mixin::Language fix CHEF-1273
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Falcon authored and danielsdeleo committed Jun 5, 2010
1 parent 5520eda commit f904589
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
12 changes: 6 additions & 6 deletions chef/lib/chef/mixin/language.rb
Expand Up @@ -42,11 +42,11 @@ def value_for_platform(platform_hash)
platform_hash.delete(key)
end
end
if platform_hash.has_key?(@node[:platform])
if platform_hash[@node[:platform]].has_key?(@node[:platform_version])
result = platform_hash[@node[:platform]][@node[:platform_version]]
elsif platform_hash[@node[:platform]].has_key?("default")
result = platform_hash[@node[:platform]]["default"]
if platform_hash.has_key?(node[:platform])
if platform_hash[node[:platform]].has_key?(node[:platform_version])
result = platform_hash[node[:platform]][node[:platform_version]]
elsif platform_hash[node[:platform]].has_key?("default")
result = platform_hash[node[:platform]]["default"]
end
end

Expand All @@ -72,7 +72,7 @@ def platform?(*args)
has_platform = false

args.flatten.each do |platform|
has_platform = true if platform == @node[:platform]
has_platform = true if platform == node[:platform]
end

has_platform
Expand Down
69 changes: 69 additions & 0 deletions chef/spec/unit/mixin/language_spec.rb
@@ -0,0 +1,69 @@
#
# Author:: Seth Falcon (<seth@opscode.com>)
# Copyright:: Copyright (c) 2010 Opscode, Inc.
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
#

require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
require 'chef/mixin/language'

class LanguageTester
include Chef::Mixin::Language
end

describe Chef::Mixin::Language do
before(:each) do
@language = LanguageTester.new
@node = Hash.new
@language.stub!(:node).and_return(@node)
@platform_hash = {}
%w{openbsd freebsd}.each do |x|
@platform_hash[x] = {
"default" => x,
"1.2.3" => "#{x}-1.2.3"
}
end
@platform_hash["default"] = "default"
end

it "returns a default value when there is no known platform" do
@node = Hash.new
@language.value_for_platform(@platform_hash).should == "default"
end

it "returns a default value when the current platform doesn't match" do
@node[:platform] = "not-a-known-platform"
@language.value_for_platform(@platform_hash).should == "default"
end

it "returns a value based on the current platform" do
@node[:platform] = "openbsd"
@language.value_for_platform(@platform_hash).should == "openbsd"
end

it "returns a version-specific value based on the current platform" do
@node[:platform] = "openbsd"
@node[:platform_version] = "1.2.3"
@language.value_for_platform(@platform_hash).should == "openbsd-1.2.3"
end

it "returns a value based on the current platform if version not found" do
@node[:platform] = "openbsd"
@node[:platform_version] = "0.0.0"
@language.value_for_platform(@platform_hash).should == "openbsd"
end

end

0 comments on commit f904589

Please sign in to comment.