Permalink
Browse files

fixing CHEF-1541

  • Loading branch information...
1 parent 1f3120f commit 58951da00f8d8ec6b79ae40c53d941616cc474dd Nuo Yan committed Sep 21, 2010
View
@@ -197,7 +197,8 @@ def name(arg=nil)
validate(
{:name => arg },
{:name => { :kind_of => String,
- :cannot_be => :blank}
+ :cannot_be => :blank,
+ :regex => /^[\-[:alnum:]_:.]+$/}
})
@name = arg
else
@@ -1,7 +1,7 @@
##
# Nodes should have a unique name
##
-name "test.example.com default"
+name "test.example.com-default"
##
# Nodes can set arbitrary arguments
@@ -1,7 +1,7 @@
##
# Nodes should have a unique name
##
-name "test.example.com short"
+name "test.example.com-short"
##
# Nodes can set arbitrary arguments
@@ -25,7 +25,7 @@
@cookbook_collection = Chef::CookbookCollection.new(Chef::CookbookLoader.new)
@cookbook = @cookbook_collection[:openldap]
@node = Chef::Node.new
- @node.name "Julia Child"
+ @node.name "JuliaChild"
@run_context = Chef::RunContext.new(@node, @cookbook_collection)
end
@@ -57,6 +57,10 @@
it "cannot be blank" do
lambda { @node.name("")}.should raise_error(Chef::Exceptions::ValidationFailed)
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
describe "attributes" do
@@ -357,7 +361,7 @@
describe "from 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.name.should eql("test.example.com short")
+ @node.name.should eql("test.example.com-short")
@node.sunshine.should eql("in")
@node.something.should eql("else")
@node.recipes.should == ["operations-master", "operations-monitoring"]
@@ -378,15 +382,15 @@
File.stub!(:exists?).and_return(true)
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.name.should == "test.example.com short"
+ @node.name.should == "test.example.com-short"
end
it "should load a node from the default file" do
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.rb")).and_return(false)
@node.find_file("test.example.com")
- @node.name.should == "test.example.com default"
+ @node.name.should == "test.example.com-default"
end
it "should raise an ArgumentError if it cannot find any node file at all" do

0 comments on commit 58951da

Please sign in to comment.