From 681a1c7971d78c53dc9a0747ae4d983ff6b0d670 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 5 Aug 2011 08:25:03 +0100 Subject: Prep for stdlib merge * Renamed load_yaml & load_json to parseyaml & parsejson * Renamed is_valid_* functions and remove the 'valid_' --- spec/unit/parser/functions/is_domain_name_spec.rb | 56 ++++++++++++++++++++++ spec/unit/parser/functions/is_ip_address_spec.rb | 45 +++++++++++++++++ spec/unit/parser/functions/is_mac_address_spec.rb | 36 ++++++++++++++ .../parser/functions/is_valid_domain_name_spec.rb | 56 ---------------------- .../parser/functions/is_valid_ip_address_spec.rb | 45 ----------------- .../parser/functions/is_valid_mac_address_spec.rb | 36 -------------- spec/unit/parser/functions/load_json_spec.rb | 29 ----------- spec/unit/parser/functions/load_yaml_spec.rb | 31 ------------ spec/unit/parser/functions/parsejson_spec.rb | 29 +++++++++++ spec/unit/parser/functions/parseyaml_spec.rb | 31 ++++++++++++ 10 files changed, 197 insertions(+), 197 deletions(-) create mode 100644 spec/unit/parser/functions/is_domain_name_spec.rb create mode 100644 spec/unit/parser/functions/is_ip_address_spec.rb create mode 100644 spec/unit/parser/functions/is_mac_address_spec.rb delete mode 100644 spec/unit/parser/functions/is_valid_domain_name_spec.rb delete mode 100644 spec/unit/parser/functions/is_valid_ip_address_spec.rb delete mode 100644 spec/unit/parser/functions/is_valid_mac_address_spec.rb delete mode 100644 spec/unit/parser/functions/load_json_spec.rb delete mode 100644 spec/unit/parser/functions/load_yaml_spec.rb create mode 100644 spec/unit/parser/functions/parsejson_spec.rb create mode 100644 spec/unit/parser/functions/parseyaml_spec.rb (limited to 'spec/unit/parser/functions') diff --git a/spec/unit/parser/functions/is_domain_name_spec.rb b/spec/unit/parser/functions/is_domain_name_spec.rb new file mode 100644 index 0000000..ec7c7f5 --- /dev/null +++ b/spec/unit/parser/functions/is_domain_name_spec.rb @@ -0,0 +1,56 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_domain_name function" do + before :all do + Puppet::Parser::Functions.autoloader.loadall + end + + before :each do + @scope = Puppet::Parser::Scope.new + end + + it "should exist" do + 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_domain_name([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if a valid domain name" do + 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_domain_name(["3foo.2bar.com"]) + result.should(be_true) + end + + it "should allow domain to end with a dot" do + 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_domain_name(["orange"]) + result.should(be_true) + end + + it "should return false if domain parts start with hyphens" do + 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_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_domain_name(["not valid"]) + result.should(be_false) + end + +end diff --git a/spec/unit/parser/functions/is_ip_address_spec.rb b/spec/unit/parser/functions/is_ip_address_spec.rb new file mode 100644 index 0000000..98ce828 --- /dev/null +++ b/spec/unit/parser/functions/is_ip_address_spec.rb @@ -0,0 +1,45 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_ip_address function" do + before :all do + Puppet::Parser::Functions.autoloader.loadall + end + + before :each do + @scope = Puppet::Parser::Scope.new + end + + it "should exist" do + 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_ip_address([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if an IPv4 address" do + 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_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_ip_address(["fe00::1"]) + result.should(eq(true)) + end + + it "should return false if not valid" do + 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_ip_address(["1.1.1.300"]) + result.should(eq(false)) + end +end diff --git a/spec/unit/parser/functions/is_mac_address_spec.rb b/spec/unit/parser/functions/is_mac_address_spec.rb new file mode 100644 index 0000000..c9b9637 --- /dev/null +++ b/spec/unit/parser/functions/is_mac_address_spec.rb @@ -0,0 +1,36 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_mac_address function" do + before :all do + Puppet::Parser::Functions.autoloader.loadall + end + + before :each do + @scope = Puppet::Parser::Scope.new + end + + it "should exist" do + 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_mac_address([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if a valid mac address" do + 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_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_mac_address(["not valid"]) + result.should(eq(false)) + end + +end diff --git a/spec/unit/parser/functions/is_valid_domain_name_spec.rb b/spec/unit/parser/functions/is_valid_domain_name_spec.rb deleted file mode 100644 index 3339447..0000000 --- a/spec/unit/parser/functions/is_valid_domain_name_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the is_valid_domain_name function" do - before :all do - Puppet::Parser::Functions.autoloader.loadall - end - - before :each do - @scope = Puppet::Parser::Scope.new - end - - it "should exist" do - Puppet::Parser::Functions.function("is_valid_domain_name").should == "function_is_valid_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)) - end - - it "should return true if a valid domain name" do - result = @scope.function_is_valid_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.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.should(be_true) - end - - it "should allow a single part domain" do - result = @scope.function_is_valid_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.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.should(be_true) - end - - it "should return false if domain name contains spaces" do - result = @scope.function_is_valid_domain_name(["not valid"]) - result.should(be_false) - end - -end diff --git a/spec/unit/parser/functions/is_valid_ip_address_spec.rb b/spec/unit/parser/functions/is_valid_ip_address_spec.rb deleted file mode 100644 index 2883aaa..0000000 --- a/spec/unit/parser/functions/is_valid_ip_address_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the is_valid_ip_address function" do - before :all do - Puppet::Parser::Functions.autoloader.loadall - end - - before :each do - @scope = Puppet::Parser::Scope.new - end - - it "should exist" do - Puppet::Parser::Functions.function("is_valid_ip_address").should == "function_is_valid_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)) - end - - it "should return true if an IPv4 address" do - result = @scope.function_is_valid_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.should(eq(true)) - end - - it "should return true if a compressed IPv6 address" do - result = @scope.function_is_valid_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.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.should(eq(false)) - end -end diff --git a/spec/unit/parser/functions/is_valid_mac_address_spec.rb b/spec/unit/parser/functions/is_valid_mac_address_spec.rb deleted file mode 100644 index 62e6fee..0000000 --- a/spec/unit/parser/functions/is_valid_mac_address_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the is_valid_mac_address function" do - before :all do - Puppet::Parser::Functions.autoloader.loadall - end - - before :each do - @scope = Puppet::Parser::Scope.new - end - - it "should exist" do - Puppet::Parser::Functions.function("is_valid_mac_address").should == "function_is_valid_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)) - 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.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.should(eq(false)) - end - - it "should return false if not valid" do - result = @scope.function_is_valid_mac_address(["not valid"]) - result.should(eq(false)) - end - -end diff --git a/spec/unit/parser/functions/load_json_spec.rb b/spec/unit/parser/functions/load_json_spec.rb deleted file mode 100644 index 73a4566..0000000 --- a/spec/unit/parser/functions/load_json_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the load_json function" do - before :all do - Puppet::Parser::Functions.autoloader.loadall - end - - before :each do - @scope = Puppet::Parser::Scope.new - end - - it "should exist" do - Puppet::Parser::Functions.function("load_json").should == "function_load_json" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { @scope.function_load_json([]) }.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.should(eq(['aaa','bbb','ccc'])) - end - -end diff --git a/spec/unit/parser/functions/load_yaml_spec.rb b/spec/unit/parser/functions/load_yaml_spec.rb deleted file mode 100644 index 2498d12..0000000 --- a/spec/unit/parser/functions/load_yaml_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the load_yaml function" do - before :all do - Puppet::Parser::Functions.autoloader.loadall - end - - before :each do - @scope = Puppet::Parser::Scope.new - end - - it "should exist" do - Puppet::Parser::Functions.function("load_yaml").should == "function_load_yaml" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { @scope.function_load_yaml([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should convert YAML to a data structure" do - yaml = <<-EOS -- aaa -- bbb -- ccc -EOS - result = @scope.function_load_yaml([yaml]) - result.should(eq(['aaa','bbb','ccc'])) - end - -end diff --git a/spec/unit/parser/functions/parsejson_spec.rb b/spec/unit/parser/functions/parsejson_spec.rb new file mode 100644 index 0000000..26eea36 --- /dev/null +++ b/spec/unit/parser/functions/parsejson_spec.rb @@ -0,0 +1,29 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the parsejson function" do + before :all do + Puppet::Parser::Functions.autoloader.loadall + end + + before :each do + @scope = Puppet::Parser::Scope.new + end + + it "should exist" do + 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_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_parsejson([json]) + result.should(eq(['aaa','bbb','ccc'])) + end + +end diff --git a/spec/unit/parser/functions/parseyaml_spec.rb b/spec/unit/parser/functions/parseyaml_spec.rb new file mode 100644 index 0000000..f9cb049 --- /dev/null +++ b/spec/unit/parser/functions/parseyaml_spec.rb @@ -0,0 +1,31 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the parseyaml function" do + before :all do + Puppet::Parser::Functions.autoloader.loadall + end + + before :each do + @scope = Puppet::Parser::Scope.new + end + + it "should exist" do + 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_parseyaml([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert YAML to a data structure" do + yaml = <<-EOS +- aaa +- bbb +- ccc +EOS + result = @scope.function_parseyaml([yaml]) + result.should(eq(['aaa','bbb','ccc'])) + end + +end -- cgit v1.2.3