]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
* Moved kwalify to puppetlabs-kwalify project
authorKen Barber <ken@bob.sh>
Fri, 5 Aug 2011 07:46:38 +0000 (08:46 +0100)
committerKen Barber <ken@bob.sh>
Fri, 5 Aug 2011 07:46:38 +0000 (08:46 +0100)
* Re-arranged tests in line with puppetlabs-stdlib

57 files changed:
README.markdown
examples/kwalify-1.pp [deleted file]
examples/kwalify-2.pp [deleted file]
examples/validate_resource-1.pp [deleted file]
examples/validate_resource-1.schema [deleted file]
examples/validate_resource-2.pp [deleted file]
examples/validate_resource-2.schema [deleted file]
lib/puppet/parser/functions/kwalify.rb [deleted file]
lib/puppet/parser/functions/validate_resource.rb [deleted file]
spec/unit/parser/functions/kwalify_spec.rb [deleted file]
spec/unit/puppet/parser/functions/abs_spec.rb [moved from spec/unit/parser/functions/abs_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/bool2num_spec.rb [moved from spec/unit/parser/functions/bool2num_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/capitalize_spec.rb [moved from spec/unit/parser/functions/capitalize_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/chomp_spec.rb [moved from spec/unit/parser/functions/chomp_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/chop_spec.rb [moved from spec/unit/parser/functions/chop_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/delete_at_spec.rb [moved from spec/unit/parser/functions/delete_at_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/delete_spec.rb [moved from spec/unit/parser/functions/delete_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/downcase_spec.rb [moved from spec/unit/parser/functions/downcase_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/empty_spec.rb [moved from spec/unit/parser/functions/empty_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/flatten_spec.rb [moved from spec/unit/parser/functions/flatten_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/grep_spec.rb [moved from spec/unit/parser/functions/grep_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/hash_spec.rb [moved from spec/unit/parser/functions/hash_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/is_array_spec.rb [moved from spec/unit/parser/functions/is_array_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/is_domain_name_spec.rb [moved from spec/unit/parser/functions/is_domain_name_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/is_float_spec.rb [moved from spec/unit/parser/functions/is_float_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/is_hash_spec.rb [moved from spec/unit/parser/functions/is_hash_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/is_integer_spec.rb [moved from spec/unit/parser/functions/is_integer_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/is_ip_address_spec.rb [moved from spec/unit/parser/functions/is_ip_address_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/is_mac_address_spec.rb [moved from spec/unit/parser/functions/is_mac_address_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/is_numeric_spec.rb [moved from spec/unit/parser/functions/is_numeric_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/is_string_spec.rb [moved from spec/unit/parser/functions/is_string_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/join_spec.rb [moved from spec/unit/parser/functions/join_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/keys_spec.rb [moved from spec/unit/parser/functions/keys_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/lstrip_spec.rb [moved from spec/unit/parser/functions/lstrip_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/member_spec.rb [moved from spec/unit/parser/functions/member_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/num2bool_spec.rb [moved from spec/unit/parser/functions/num2bool_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/parsejson_spec.rb [moved from spec/unit/parser/functions/parsejson_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/parseyaml_spec.rb [moved from spec/unit/parser/functions/parseyaml_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/prefix_spec.rb [moved from spec/unit/parser/functions/prefix_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/range_spec.rb [moved from spec/unit/parser/functions/range_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/reverse_spec.rb [moved from spec/unit/parser/functions/reverse_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/rstrip_spec.rb [moved from spec/unit/parser/functions/rstrip_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/shuffle_spec.rb [moved from spec/unit/parser/functions/shuffle_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/size_spec.rb [moved from spec/unit/parser/functions/size_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/sort_spec.rb [moved from spec/unit/parser/functions/sort_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/squeeze_spec.rb [moved from spec/unit/parser/functions/squeeze_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/str2bool_spec.rb [moved from spec/unit/parser/functions/str2bool_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/strftime_spec.rb [moved from spec/unit/parser/functions/strftime_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/strip_spec.rb [moved from spec/unit/parser/functions/strip_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/swapcase_spec.rb [moved from spec/unit/parser/functions/swapcase_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/time_spec.rb [moved from spec/unit/parser/functions/time_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/type_spec.rb [moved from spec/unit/parser/functions/type_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/unique_spec.rb [moved from spec/unit/parser/functions/unique_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/upcase_spec.rb [moved from spec/unit/parser/functions/upcase_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/values_at_spec.rb [moved from spec/unit/parser/functions/values_at_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/values_spec.rb [moved from spec/unit/parser/functions/values_spec.rb with 100% similarity]
spec/unit/puppet/parser/functions/zip_spec.rb [moved from spec/unit/parser/functions/zip_spec.rb with 100% similarity]

index 68e559ea6d4d3ab424e44d045e85109f84342969..a15338fae817caad91b0adc7218779cea699849c 100644 (file)
@@ -20,29 +20,4 @@ Depending on the version of Puppet, you may need to restart the puppetmasterd (o
 
 ## Functions
 
-### kwalify
-
-This function allows you to validate Puppet data structures using Kwalify 
-schemas as documented here:
-
-http://www.kuwata-lab.com/kwalify/ruby/users-guide.01.html
-
-To validate, create a schema in Puppet:
-
-    $schema = {
-      'type' => 'seq',
-      'sequence' => [
-        { 'type' => 'str' }
-      ]
-    }
-
-And create some content that you want validated:
-
-    $document = ['a', 'b', 'c']
-
-And then use the function to validate:
-
-    kwalify($schema, $document)
-
-The function will throw an error and list all validation errors if there is a
-problem otherwise it succeeds silently.
+TODO
diff --git a/examples/kwalify-1.pp b/examples/kwalify-1.pp
deleted file mode 100644 (file)
index 852e46c..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-$schema = {
-  'type' => 'seq',
-  'sequence' => [
-    { 'type' => 'str', 'enum' => ['asdf','fdsa'] }
-  ]
-}
-$document = ['a', 'b', 'c']
-
-kwalify($schema, $document)
diff --git a/examples/kwalify-2.pp b/examples/kwalify-2.pp
deleted file mode 100644 (file)
index 3f4ec33..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-$schema = {
-  'type' => 'map',
-  'mapping' => {
-    'name' => {
-      'type' => 'str',
-      'required' => true,
-    },
-    'email' => {
-      'type' => 'str',
-      'pattern' => '/@/',
-    },
-    'age' => {
-      'type' => 'str',
-      'pattern' => '/^\d+$/',
-    },
-  }
-}
-$document = {
-  'name' => 'foo',
-  'email' => 'foo@mail.com',
-  'age' => 20,
-}
-
-kwalify($schema, $document)
diff --git a/examples/validate_resource-1.pp b/examples/validate_resource-1.pp
deleted file mode 100644 (file)
index c701b8d..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-define fooresource(
-  $color,
-  $type,
-  $somenumber,
-  $map
-  ) {
-
-  validate_resource()
-
-  # ... do something ...
-}
-
-fooresource { "example1":
-  color => "blue",
-  type => "circle",
-  somenumber => 5,
-  map => {
-    a => 1,
-    b => 2,
-    c => 3,
-  }
-}
diff --git a/examples/validate_resource-1.schema b/examples/validate_resource-1.schema
deleted file mode 100644 (file)
index c540db5..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-type: map
-mapping:
-  "title":
-    type: str
-    required: yes
-  "name":
-    type: str
-    required: yes
-  "caller_module_name":
-    type: str
-    required: yes
-  "module_name":
-    type: str
-    required: yes
-  "color":
-    type: str
-    required: yes
-  "type":
-    type: str
-    required: yes
-  "somenumber":
-    type: str
-    required: yes
-    pattern: /^\d+$/
-  "map":
-    type: map
-    mapping:
-      "a":
-        type: str
-        required: yes
-        pattern: /^\d+$/
-      "b":
-        type: str
-        required: yes
-        pattern: /^\d+$/
-      "c":
-        type: str
-        required: yes
-        pattern: /^\d+$/
diff --git a/examples/validate_resource-2.pp b/examples/validate_resource-2.pp
deleted file mode 100644 (file)
index b53b109..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-class foo (
-  $a,
-  $b,
-  $c
-  ) {
-
-  validate_resource()
-
-  # ... do something ...
-
-}
-
-class { "foo": 
-  a => "1",
-  b => "foobaz",
-  c => ['a','b','c'] 
-}
diff --git a/examples/validate_resource-2.schema b/examples/validate_resource-2.schema
deleted file mode 100644 (file)
index b516945..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-type: map
-mapping:
-  "title":
-    type: str
-    required: yes
-  "name":
-    type: str
-    required: yes
-  "caller_module_name":
-    type: str
-    required: yes
-  "module_name":
-    type: str
-    required: yes
-  "a":
-    type: str
-    required: yes
-  "b":
-    type: str
-    required: yes
-    pattern: /^foo/
-  "c":
-    type: seq
-    required: yes
-    sequence:
-      - type: str
diff --git a/lib/puppet/parser/functions/kwalify.rb b/lib/puppet/parser/functions/kwalify.rb
deleted file mode 100644 (file)
index 49b9aeb..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#
-# kwalify.rb
-#
-
-module Puppet::Parser::Functions
-  newfunction(:kwalify, :type => :statement, :doc => <<-EOS
-This function uses kwalify to validate Puppet data structures against Kwalify
-schemas.
-    EOS
-  ) do |args|
-
-    raise(Puppet::ParseError, "kwalify(): Wrong number of arguments " +
-      "given (#{args.size} for 2)") if args.size != 2
-
-    schema = args[0]
-    document = args[1]
-
-    require 'kwalify'
-
-    validator = Kwalify::Validator.new(schema)
-
-    errors = validator.validate(document)
-
-    if errors && !errors.empty?
-      error_out = []
-      for e in errors
-        error_out << "[#{e.path}] #{e.message}"
-      end
-      raise(Puppet::ParseError, "Failed kwalify schema validation:\n" + error_out.join("\n"))
-    end
-
-  end
-end
-
-# vim: set ts=2 sw=2 et :
diff --git a/lib/puppet/parser/functions/validate_resource.rb b/lib/puppet/parser/functions/validate_resource.rb
deleted file mode 100644 (file)
index d71ef3f..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-#
-# validate_resource
-#
-
-module Puppet::Parser::Functions
-  newfunction(:validate_resource, :type => :statement, :doc => <<-EOS
-This function when placed at the beginning of a class, will go looking for a
-valid kwalify schema by replacing the extension of the file with '.schema'.
-
-It will then validate the arguments passed to the function using that kwalify
-schema.
-    EOS
-  ) do |arguments|
-    require 'kwalify'
-
-    if (arguments.size != 0) then
-      raise(Puppet::ParseError, "validate_resource(): Wrong number of arguments "+
-        "given #{arguments.size} for 0")
-    end
-
-
-    classhash = to_hash(recursive=false)
-    sourcepath = source.file
-    schemapath = sourcepath.gsub(/\.(rb|pp)$/, ".schema")
-    schema = Kwalify::Yaml.load_file(schemapath)
-    validator = Kwalify::Validator.new(schema)
-    errors = validator.validate(classhash)
-
-    if errors && !errors.empty?
-      error_output = "Resource validation failed:\n"
-      for e in errors
-        error_output += "[#{e.path}] #{e.message}\n"
-      end
-      raise(Puppet::ParseError, error_output)
-    end
-
-  end
-end
-
-# vim: set ts=2 sw=2 et :
diff --git a/spec/unit/parser/functions/kwalify_spec.rb b/spec/unit/parser/functions/kwalify_spec.rb
deleted file mode 100755 (executable)
index abdd529..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env rspec
-require 'spec_helper'
-
-describe "the kwalify 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("kwalify").should == "function_kwalify"
-  end
-
-  it "should raise a ParseError if there is less than 2 arguments" do
-    lambda { @scope.function_kwalify([]) }.should( raise_error(Puppet::ParseError))
-  end
-
-  it "should validate a simple array schema" do
-    schema = { 
-      'type' => 'seq',
-      'sequence' => [
-        { 'type' => 'str' }
-      ]
-    }
-    document = ['a','b','c']
-    @scope.function_kwalify([schema, document])
-  end
-
-  it "should not validate a simple array schema when invalid" do
-    schema = { 
-      'type' => 'seq',
-      'sequence' => [
-        { 'type' => 'str' }
-      ]
-    }
-    document = ['a','b',{'a' => 'b'}]
-    lambda { @scope.function_kwalify([schema, document]) }.should(raise_error(Puppet::ParseError))
-  end
-
-  it "should validate a hash schema" do
-    schema = {
-      'type' => 'map',
-      'mapping' => {
-        'key1' => {
-          'type' => 'str',
-        },
-        'key2' => {
-          'type' => 'str',
-        },
-      }
-    }
-    document = {
-      'key1' => 'b',
-      'key2' => 'c',
-    }
-    @scope.function_kwalify([schema, document])
-  end
-
-end