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:
parent
35fefe1865
commit
681a1c7971
10 changed files with 47 additions and 47 deletions
|
@ -1,15 +1,15 @@
|
|||
#
|
||||
# is_valid_domain_name.rb
|
||||
# is_domain_name.rb
|
||||
#
|
||||
|
||||
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.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
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")
|
||||
end
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
#
|
||||
# is_valid_ip_address.rb
|
||||
# is_ip_address.rb
|
||||
#
|
||||
|
||||
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.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
@ -11,7 +11,7 @@ Returns true if the string passed to this function is a valid IP address.
|
|||
require 'ipaddr'
|
||||
|
||||
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")
|
||||
end
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
#
|
||||
# is_valid_mac_address.rb
|
||||
# is_mac_address.rb
|
||||
#
|
||||
|
||||
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.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
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")
|
||||
end
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
#
|
||||
# load_json.rb
|
||||
# parsejson.rb
|
||||
#
|
||||
|
||||
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
|
||||
structure.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
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")
|
||||
end
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
#
|
||||
# load_yaml.rb
|
||||
# parseyaml.rb
|
||||
#
|
||||
|
||||
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
|
||||
Puppet structure.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
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")
|
||||
end
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env rspec
|
||||
require 'spec_helper'
|
||||
|
||||
describe "the is_valid_domain_name function" do
|
||||
describe "the is_domain_name function" do
|
||||
before :all do
|
||||
Puppet::Parser::Functions.autoloader.loadall
|
||||
end
|
||||
|
@ -11,45 +11,45 @@ describe "the is_valid_domain_name function" do
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env rspec
|
||||
require 'spec_helper'
|
||||
|
||||
describe "the is_valid_ip_address function" do
|
||||
describe "the is_ip_address function" do
|
||||
before :all do
|
||||
Puppet::Parser::Functions.autoloader.loadall
|
||||
end
|
||||
|
@ -11,35 +11,35 @@ describe "the is_valid_ip_address function" do
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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))
|
||||
end
|
||||
|
||||
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))
|
||||
end
|
||||
|
||||
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))
|
||||
end
|
||||
|
||||
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))
|
||||
end
|
||||
|
||||
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))
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env rspec
|
||||
require 'spec_helper'
|
||||
|
||||
describe "the is_valid_mac_address function" do
|
||||
describe "the is_mac_address function" do
|
||||
before :all do
|
||||
Puppet::Parser::Functions.autoloader.loadall
|
||||
end
|
||||
|
@ -11,25 +11,25 @@ describe "the is_valid_mac_address function" do
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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))
|
||||
end
|
||||
|
||||
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))
|
||||
end
|
||||
|
||||
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))
|
||||
end
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env rspec
|
||||
require 'spec_helper'
|
||||
|
||||
describe "the load_json function" do
|
||||
describe "the parsejson function" do
|
||||
before :all do
|
||||
Puppet::Parser::Functions.autoloader.loadall
|
||||
end
|
||||
|
@ -11,18 +11,18 @@ describe "the load_json function" do
|
|||
end
|
||||
|
||||
it "should exist" do
|
||||
Puppet::Parser::Functions.function("load_json").should == "function_load_json"
|
||||
Puppet::Parser::Functions.function("parsejson").should == "function_parsejson"
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
it "should convert JSON to a data structure" do
|
||||
json = <<-EOS
|
||||
["aaa","bbb","ccc"]
|
||||
EOS
|
||||
result = @scope.function_load_json([json])
|
||||
result = @scope.function_parsejson([json])
|
||||
result.should(eq(['aaa','bbb','ccc']))
|
||||
end
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env rspec
|
||||
require 'spec_helper'
|
||||
|
||||
describe "the load_yaml function" do
|
||||
describe "the parseyaml function" do
|
||||
before :all do
|
||||
Puppet::Parser::Functions.autoloader.loadall
|
||||
end
|
||||
|
@ -11,11 +11,11 @@ describe "the load_yaml function" do
|
|||
end
|
||||
|
||||
it "should exist" do
|
||||
Puppet::Parser::Functions.function("load_yaml").should == "function_load_yaml"
|
||||
Puppet::Parser::Functions.function("parseyaml").should == "function_parseyaml"
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
it "should convert YAML to a data structure" do
|
||||
|
@ -24,7 +24,7 @@ describe "the load_yaml function" do
|
|||
- bbb
|
||||
- ccc
|
||||
EOS
|
||||
result = @scope.function_load_yaml([yaml])
|
||||
result = @scope.function_parseyaml([yaml])
|
||||
result.should(eq(['aaa','bbb','ccc']))
|
||||
end
|
||||
|
Loading…
Reference in a new issue