Commit 58951da0 authored by Nuo Yan's avatar Nuo Yan
Browse files

fixing CHEF-1541

parent 1f3120f8
...@@ -197,7 +197,8 @@ class Chef ...@@ -197,7 +197,8 @@ class Chef
validate( validate(
{:name => arg }, {:name => arg },
{:name => { :kind_of => String, {:name => { :kind_of => String,
:cannot_be => :blank} :cannot_be => :blank,
:regex => /^[\-[:alnum:]_:.]+$/}
}) })
@name = arg @name = arg
else else
......
## ##
# Nodes should have a unique name # Nodes should have a unique name
## ##
name "test.example.com default" name "test.example.com-default"
## ##
# Nodes can set arbitrary arguments # Nodes can set arbitrary arguments
......
## ##
# Nodes should have a unique name # Nodes should have a unique name
## ##
name "test.example.com short" name "test.example.com-short"
## ##
# Nodes can set arbitrary arguments # Nodes can set arbitrary arguments
......
...@@ -25,7 +25,7 @@ describe Chef::CookbookVersion do ...@@ -25,7 +25,7 @@ describe Chef::CookbookVersion do
@cookbook_collection = Chef::CookbookCollection.new(Chef::CookbookLoader.new) @cookbook_collection = Chef::CookbookCollection.new(Chef::CookbookLoader.new)
@cookbook = @cookbook_collection[:openldap] @cookbook = @cookbook_collection[:openldap]
@node = Chef::Node.new @node = Chef::Node.new
@node.name "Julia Child" @node.name "JuliaChild"
@run_context = Chef::RunContext.new(@node, @cookbook_collection) @run_context = Chef::RunContext.new(@node, @cookbook_collection)
end end
......
...@@ -57,6 +57,10 @@ describe Chef::Node do ...@@ -57,6 +57,10 @@ describe Chef::Node do
it "cannot be blank" do it "cannot be blank" do
lambda { @node.name("")}.should raise_error(Chef::Exceptions::ValidationFailed) lambda { @node.name("")}.should raise_error(Chef::Exceptions::ValidationFailed)
end end
it "should not accept name doesn't match /^[\-[:alnum:]_:.]+$/" do
lambda { @node.name("space in it")}.should raise_error(Chef::Exceptions::ValidationFailed)
end
end end
describe "attributes" do describe "attributes" do
...@@ -357,7 +361,7 @@ describe Chef::Node do ...@@ -357,7 +361,7 @@ describe Chef::Node do
describe "from file" do describe "from file" do
it "should load a node from a ruby file" do it "should load a node from a ruby file" do
@node.from_file(File.expand_path(File.join(CHEF_SPEC_DATA, "nodes", "test.rb"))) @node.from_file(File.expand_path(File.join(CHEF_SPEC_DATA, "nodes", "test.rb")))
@node.name.should eql("test.example.com short") @node.name.should eql("test.example.com-short")
@node.sunshine.should eql("in") @node.sunshine.should eql("in")
@node.something.should eql("else") @node.something.should eql("else")
@node.recipes.should == ["operations-master", "operations-monitoring"] @node.recipes.should == ["operations-master", "operations-monitoring"]
...@@ -378,7 +382,7 @@ describe Chef::Node do ...@@ -378,7 +382,7 @@ describe Chef::Node do
File.stub!(:exists?).and_return(true) File.stub!(:exists?).and_return(true)
File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false) File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false)
@node.find_file("test.example.com") @node.find_file("test.example.com")
@node.name.should == "test.example.com short" @node.name.should == "test.example.com-short"
end end
it "should load a node from the default file" do it "should load a node from the default file" do
...@@ -386,7 +390,7 @@ describe Chef::Node do ...@@ -386,7 +390,7 @@ describe Chef::Node do
File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false) File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false)
File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.rb")).and_return(false) File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.rb")).and_return(false)
@node.find_file("test.example.com") @node.find_file("test.example.com")
@node.name.should == "test.example.com default" @node.name.should == "test.example.com-default"
end end
it "should raise an ArgumentError if it cannot find any node file at all" do it "should raise an ArgumentError if it cannot find any node file at all" do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment