Prep for stdlib merge

* Renamed load_yaml & load_json to parseyaml & parsejson
* Renamed is_valid_* functions and remove the 'valid_'
This commit is contained in:
Ken Barber 2011-08-05 08:25:03 +01:00
parent 35fefe1865
commit 681a1c7971
10 changed files with 47 additions and 47 deletions

View file

@ -1,15 +1,15 @@
# #
# is_valid_domain_name.rb # is_domain_name.rb
# #
module Puppet::Parser::Functions module Puppet::Parser::Functions
newfunction(:is_valid_domain_name, :type => :rvalue, :doc => <<-EOS newfunction(:is_domain_name, :type => :rvalue, :doc => <<-EOS
Returns true if the string passed to this function is a valid IP address. Support for IPv4 and IPv6 address types is included. Returns true if the string passed to this function is a valid IP address. Support for IPv4 and IPv6 address types is included.
EOS EOS
) do |arguments| ) do |arguments|
if (arguments.size != 1) then if (arguments.size != 1) then
raise(Puppet::ParseError, "is_valid_domain_name(): Wrong number of arguments "+ raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments "+
"given #{arguments.size} for 1") "given #{arguments.size} for 1")
end end

View file

@ -1,9 +1,9 @@
# #
# is_valid_ip_address.rb # is_ip_address.rb
# #
module Puppet::Parser::Functions module Puppet::Parser::Functions
newfunction(:is_valid_ip_address, :type => :rvalue, :doc => <<-EOS newfunction(:is_ip_address, :type => :rvalue, :doc => <<-EOS
Returns true if the string passed to this function is a valid IP address. Returns true if the string passed to this function is a valid IP address.
EOS EOS
) do |arguments| ) do |arguments|
@ -11,7 +11,7 @@ Returns true if the string passed to this function is a valid IP address.
require 'ipaddr' require 'ipaddr'
if (arguments.size != 1) then if (arguments.size != 1) then
raise(Puppet::ParseError, "is_valid_ip_address(): Wrong number of arguments "+ raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+
"given #{arguments.size} for 1") "given #{arguments.size} for 1")
end end

View file

@ -1,15 +1,15 @@
# #
# is_valid_mac_address.rb # is_mac_address.rb
# #
module Puppet::Parser::Functions module Puppet::Parser::Functions
newfunction(:is_valid_mac_address, :type => :rvalue, :doc => <<-EOS newfunction(:is_mac_address, :type => :rvalue, :doc => <<-EOS
Returns true if the string passed to this function is a valid mac address. Returns true if the string passed to this function is a valid mac address.
EOS EOS
) do |arguments| ) do |arguments|
if (arguments.size != 1) then if (arguments.size != 1) then
raise(Puppet::ParseError, "is_valid_mac_address(): Wrong number of arguments "+ raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments "+
"given #{arguments.size} for 1") "given #{arguments.size} for 1")
end end

View file

@ -1,16 +1,16 @@
# #
# load_json.rb # parsejson.rb
# #
module Puppet::Parser::Functions module Puppet::Parser::Functions
newfunction(:load_json, :type => :rvalue, :doc => <<-EOS newfunction(:parsejson, :type => :rvalue, :doc => <<-EOS
This function accepts JSON as a string and converts into the correct Puppet This function accepts JSON as a string and converts into the correct Puppet
structure. structure.
EOS EOS
) do |arguments| ) do |arguments|
if (arguments.size != 1) then if (arguments.size != 1) then
raise(Puppet::ParseError, "load_json(): Wrong number of arguments "+ raise(Puppet::ParseError, "parsejson(): Wrong number of arguments "+
"given #{arguments.size} for 1") "given #{arguments.size} for 1")
end end

View file

@ -1,16 +1,16 @@
# #
# load_yaml.rb # parseyaml.rb
# #
module Puppet::Parser::Functions module Puppet::Parser::Functions
newfunction(:load_yaml, :type => :rvalue, :doc => <<-EOS newfunction(:parseyaml, :type => :rvalue, :doc => <<-EOS
This function accepts YAML as a string and converts it into the correct This function accepts YAML as a string and converts it into the correct
Puppet structure. Puppet structure.
EOS EOS
) do |arguments| ) do |arguments|
if (arguments.size != 1) then if (arguments.size != 1) then
raise(Puppet::ParseError, "load_yaml(): Wrong number of arguments "+ raise(Puppet::ParseError, "parseyaml(): Wrong number of arguments "+
"given #{arguments.size} for 1") "given #{arguments.size} for 1")
end end

View file

@ -1,7 +1,7 @@
#!/usr/bin/env rspec #!/usr/bin/env rspec
require 'spec_helper' require 'spec_helper'
describe "the is_valid_domain_name function" do describe "the is_domain_name function" do
before :all do before :all do
Puppet::Parser::Functions.autoloader.loadall Puppet::Parser::Functions.autoloader.loadall
end end
@ -11,45 +11,45 @@ describe "the is_valid_domain_name function" do
end end
it "should exist" do it "should exist" do
Puppet::Parser::Functions.function("is_valid_domain_name").should == "function_is_valid_domain_name" Puppet::Parser::Functions.function("is_domain_name").should == "function_is_domain_name"
end end
it "should raise a ParseError if there is less than 1 arguments" do it "should raise a ParseError if there is less than 1 arguments" do
lambda { @scope.function_is_valid_domain_name([]) }.should( raise_error(Puppet::ParseError)) lambda { @scope.function_is_domain_name([]) }.should( raise_error(Puppet::ParseError))
end end
it "should return true if a valid domain name" do it "should return true if a valid domain name" do
result = @scope.function_is_valid_domain_name(["foo.bar.com"]) result = @scope.function_is_domain_name(["foo.bar.com"])
result.should(be_true) result.should(be_true)
end end
it "should allow domain parts to start with numbers" do it "should allow domain parts to start with numbers" do
result = @scope.function_is_valid_domain_name(["3foo.2bar.com"]) result = @scope.function_is_domain_name(["3foo.2bar.com"])
result.should(be_true) result.should(be_true)
end end
it "should allow domain to end with a dot" do it "should allow domain to end with a dot" do
result = @scope.function_is_valid_domain_name(["3foo.2bar.com."]) result = @scope.function_is_domain_name(["3foo.2bar.com."])
result.should(be_true) result.should(be_true)
end end
it "should allow a single part domain" do it "should allow a single part domain" do
result = @scope.function_is_valid_domain_name(["orange"]) result = @scope.function_is_domain_name(["orange"])
result.should(be_true) result.should(be_true)
end end
it "should return false if domain parts start with hyphens" do it "should return false if domain parts start with hyphens" do
result = @scope.function_is_valid_domain_name(["-3foo.2bar.com"]) result = @scope.function_is_domain_name(["-3foo.2bar.com"])
result.should(be_false) result.should(be_false)
end end
it "should return true if domain contains hyphens" do it "should return true if domain contains hyphens" do
result = @scope.function_is_valid_domain_name(["3foo-bar.2bar-fuzz.com"]) result = @scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"])
result.should(be_true) result.should(be_true)
end end
it "should return false if domain name contains spaces" do it "should return false if domain name contains spaces" do
result = @scope.function_is_valid_domain_name(["not valid"]) result = @scope.function_is_domain_name(["not valid"])
result.should(be_false) result.should(be_false)
end end

View file

@ -1,7 +1,7 @@
#!/usr/bin/env rspec #!/usr/bin/env rspec
require 'spec_helper' require 'spec_helper'
describe "the is_valid_ip_address function" do describe "the is_ip_address function" do
before :all do before :all do
Puppet::Parser::Functions.autoloader.loadall Puppet::Parser::Functions.autoloader.loadall
end end
@ -11,35 +11,35 @@ describe "the is_valid_ip_address function" do
end end
it "should exist" do it "should exist" do
Puppet::Parser::Functions.function("is_valid_ip_address").should == "function_is_valid_ip_address" Puppet::Parser::Functions.function("is_ip_address").should == "function_is_ip_address"
end end
it "should raise a ParseError if there is less than 1 arguments" do it "should raise a ParseError if there is less than 1 arguments" do
lambda { @scope.function_is_valid_ip_address([]) }.should( raise_error(Puppet::ParseError)) lambda { @scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError))
end end
it "should return true if an IPv4 address" do it "should return true if an IPv4 address" do
result = @scope.function_is_valid_ip_address(["1.2.3.4"]) result = @scope.function_is_ip_address(["1.2.3.4"])
result.should(eq(true)) result.should(eq(true))
end end
it "should return true if a full IPv6 address" do it "should return true if a full IPv6 address" do
result = @scope.function_is_valid_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"]) result = @scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"])
result.should(eq(true)) result.should(eq(true))
end end
it "should return true if a compressed IPv6 address" do it "should return true if a compressed IPv6 address" do
result = @scope.function_is_valid_ip_address(["fe00::1"]) result = @scope.function_is_ip_address(["fe00::1"])
result.should(eq(true)) result.should(eq(true))
end end
it "should return false if not valid" do it "should return false if not valid" do
result = @scope.function_is_valid_ip_address(["asdf"]) result = @scope.function_is_ip_address(["asdf"])
result.should(eq(false)) result.should(eq(false))
end end
it "should return false if IP octets out of range" do it "should return false if IP octets out of range" do
result = @scope.function_is_valid_ip_address(["1.1.1.300"]) result = @scope.function_is_ip_address(["1.1.1.300"])
result.should(eq(false)) result.should(eq(false))
end end
end end

View file

@ -1,7 +1,7 @@
#!/usr/bin/env rspec #!/usr/bin/env rspec
require 'spec_helper' require 'spec_helper'
describe "the is_valid_mac_address function" do describe "the is_mac_address function" do
before :all do before :all do
Puppet::Parser::Functions.autoloader.loadall Puppet::Parser::Functions.autoloader.loadall
end end
@ -11,25 +11,25 @@ describe "the is_valid_mac_address function" do
end end
it "should exist" do it "should exist" do
Puppet::Parser::Functions.function("is_valid_mac_address").should == "function_is_valid_mac_address" Puppet::Parser::Functions.function("is_mac_address").should == "function_is_mac_address"
end end
it "should raise a ParseError if there is less than 1 arguments" do it "should raise a ParseError if there is less than 1 arguments" do
lambda { @scope.function_is_valid_mac_address([]) }.should( raise_error(Puppet::ParseError)) lambda { @scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError))
end end
it "should return true if a valid mac address" do it "should return true if a valid mac address" do
result = @scope.function_is_valid_mac_address(["00:a0:1f:12:7f:a0"]) result = @scope.function_is_mac_address(["00:a0:1f:12:7f:a0"])
result.should(eq(true)) result.should(eq(true))
end end
it "should return false if octets are out of range" do it "should return false if octets are out of range" do
result = @scope.function_is_valid_mac_address(["00:a0:1f:12:7f:g0"]) result = @scope.function_is_mac_address(["00:a0:1f:12:7f:g0"])
result.should(eq(false)) result.should(eq(false))
end end
it "should return false if not valid" do it "should return false if not valid" do
result = @scope.function_is_valid_mac_address(["not valid"]) result = @scope.function_is_mac_address(["not valid"])
result.should(eq(false)) result.should(eq(false))
end end

View file

@ -1,7 +1,7 @@
#!/usr/bin/env rspec #!/usr/bin/env rspec
require 'spec_helper' require 'spec_helper'
describe "the load_json function" do describe "the parsejson function" do
before :all do before :all do
Puppet::Parser::Functions.autoloader.loadall Puppet::Parser::Functions.autoloader.loadall
end end
@ -11,18 +11,18 @@ describe "the load_json function" do
end end
it "should exist" do it "should exist" do
Puppet::Parser::Functions.function("load_json").should == "function_load_json" Puppet::Parser::Functions.function("parsejson").should == "function_parsejson"
end end
it "should raise a ParseError if there is less than 1 arguments" do it "should raise a ParseError if there is less than 1 arguments" do
lambda { @scope.function_load_json([]) }.should( raise_error(Puppet::ParseError)) lambda { @scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError))
end end
it "should convert JSON to a data structure" do it "should convert JSON to a data structure" do
json = <<-EOS json = <<-EOS
["aaa","bbb","ccc"] ["aaa","bbb","ccc"]
EOS EOS
result = @scope.function_load_json([json]) result = @scope.function_parsejson([json])
result.should(eq(['aaa','bbb','ccc'])) result.should(eq(['aaa','bbb','ccc']))
end end

View file

@ -1,7 +1,7 @@
#!/usr/bin/env rspec #!/usr/bin/env rspec
require 'spec_helper' require 'spec_helper'
describe "the load_yaml function" do describe "the parseyaml function" do
before :all do before :all do
Puppet::Parser::Functions.autoloader.loadall Puppet::Parser::Functions.autoloader.loadall
end end
@ -11,11 +11,11 @@ describe "the load_yaml function" do
end end
it "should exist" do it "should exist" do
Puppet::Parser::Functions.function("load_yaml").should == "function_load_yaml" Puppet::Parser::Functions.function("parseyaml").should == "function_parseyaml"
end end
it "should raise a ParseError if there is less than 1 arguments" do it "should raise a ParseError if there is less than 1 arguments" do
lambda { @scope.function_load_yaml([]) }.should( raise_error(Puppet::ParseError)) lambda { @scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError))
end end
it "should convert YAML to a data structure" do it "should convert YAML to a data structure" do
@ -24,7 +24,7 @@ describe "the load_yaml function" do
- bbb - bbb
- ccc - ccc
EOS EOS
result = @scope.function_load_yaml([yaml]) result = @scope.function_parseyaml([yaml])
result.should(eq(['aaa','bbb','ccc'])) result.should(eq(['aaa','bbb','ccc']))
end end