[Pkg-puppet-devel] [facter] 86/352: (fact-79) Add facter_json_output_validate.rb

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 beb37b2513a23aefc149d5e9737f396fd596fbd8
Author: Kylo Ginsberg <kylo at puppetlabs.com>
Date:   Thu Dec 12 11:57:20 2013 -0800

    (fact-79) Add facter_json_output_validate.rb
    
    Prior to this commit there was no validation of facter output
    against a schema.  This commit adds an acceptance test to validate
    facter output against the recently added schema.
    
    Note that the acceptance test is currently confined off of a
    number of platforms, notably those which come with ruby 1.8.7,
    since that doesn't include the json gem. We should remove those
    confines as acceptance jobs are enhanced to add the gem to those
    platforms.
    
    This also adds a quicky validate.rb script for dev use.
---
 acceptance/Gemfile                               |  7 +++++++
 acceptance/tests/facter_json_output_validates.rb | 16 ++++++++++++++++
 schema/validate.rb                               |  8 ++++++++
 3 files changed, 31 insertions(+)

diff --git a/acceptance/Gemfile b/acceptance/Gemfile
index ccd15ed..8878829 100644
--- a/acceptance/Gemfile
+++ b/acceptance/Gemfile
@@ -2,6 +2,13 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org"
 
 gem "beaker", "~> 1.3.1"
 
+# json-schema does not support windows, so use the 'ruby' platform to exclude it on windows
+platforms :ruby do
+  # json-schema uses multi_json, but chokes with multi_json 1.7.9, so prefer 1.7.7
+  gem "multi_json", "1.7.7", :require => false
+  gem "json-schema", "2.1.1", :require => false
+end
+
 if File.exists? "#{__FILE__}.local"
   eval(File.read("#{__FILE__}.local"), binding)
 end
diff --git a/acceptance/tests/facter_json_output_validates.rb b/acceptance/tests/facter_json_output_validates.rb
new file mode 100644
index 0000000..9716b14
--- /dev/null
+++ b/acceptance/tests/facter_json_output_validates.rb
@@ -0,0 +1,16 @@
+require 'json'
+require 'json-schema'
+
+test_name "Running facter --json should validate against the schema"
+
+confine :except, :platform => 'ubuntu-10.04'
+confine :except, :platform => 'el-6'
+confine :except, :platform => 'el-5'
+
+agents.each do |agent|
+  step "Agent #{agent}: run 'facter --json' and validate"
+  on(agent, facter('--json')) do
+    schema = JSON.parse(File.read("../schema/facter.json"))
+    fail_test "facter --json was invalid" unless JSON::Validator.validate!(schema, stdout)
+  end
+end
diff --git a/schema/validate.rb b/schema/validate.rb
new file mode 100755
index 0000000..42fcd17
--- /dev/null
+++ b/schema/validate.rb
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+
+require 'json'
+require 'json-schema'
+
+facts  = `bundle exec facter --json`
+schema = JSON.parse(File.read("schema/facter.json"))
+JSON::Validator.validate!(schema, facts)

-- 
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