[Pkg-puppet-devel] [facter] 91/352: (fact-79) Add a README.md for the schema and clearer validate.rb output
Stig Sandbeck Mathisen
ssm at debian.org
Sun Apr 6 22:21:34 UTC 2014
This is an automated email from the git hooks/post-receive script.
ssm pushed a commit to branch master
in repository facter.
commit 7ae5189530078699958fe86c1c941bf7f7f75849
Author: Kylo Ginsberg <kylo at puppetlabs.com>
Date: Fri Dec 20 12:45:32 2013 -0800
(fact-79) Add a README.md for the schema and clearer validate.rb output
---
schema/README.md | 34 ++++++++++++++++++++++++++++++++++
schema/validate.rb | 10 +++++++++-
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/schema/README.md b/schema/README.md
new file mode 100644
index 0000000..a69234f
--- /dev/null
+++ b/schema/README.md
@@ -0,0 +1,34 @@
+Facter Schema
+=============
+
+This directory contains a schema to document the types of facter built-in
+facts. As new facts are added, this schema should be augmened to document
+the type of the new facts.
+
+Currently, this is used for acceptance testing.
+
+Developer Validation
+--------------------
+
+As an aid to validation while developing a new fact, there is a simple
+script `validate.rb`. It takes no parameters and assumes it is run from
+the root of the facter tree.
+
+E.g. a successful run would look like:
+
+ > schema/validate.rb
+ Passed validation!
+
+A failed run, after adding a new fact `brand_new_fact` but not updating the
+schema, would look like:
+
+ > schema/validate.rb
+ The property '#/' contains additional properties ["brand_new_fact"] outside of the schema when none are allowed in schema c88b014f-e52a-5479-8720-916c32f56475#
+ Failed validation.
+
+A failed run, after introducing a regression by changing `changed_fact`
+from an integer to a string, would look like:
+
+ > schema/validate.rb
+ The property '#/changed_fact' of type String did not match the following type: integer in schema d588f6fa-bc4a-5283-8830-23015f66c410#
+ Failed validation.
diff --git a/schema/validate.rb b/schema/validate.rb
index 42fcd17..3f4379a 100755
--- a/schema/validate.rb
+++ b/schema/validate.rb
@@ -5,4 +5,12 @@ require 'json-schema'
facts = `bundle exec facter --json`
schema = JSON.parse(File.read("schema/facter.json"))
-JSON::Validator.validate!(schema, facts)
+errors = JSON::Validator.fully_validate(schema, facts)
+if errors.empty?
+ puts "Passed validation!"
+ exit 0
+else
+ puts errors
+ puts "Failed validation."
+ exit 1
+end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git
More information about the Pkg-puppet-devel
mailing list