Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add platforms schema command #3346

Merged
merged 5 commits into from Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion inspec-core.gemspec
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.3'

spec.add_dependency 'train-core', '~> 1.4', '>= 1.4.35'
spec.add_dependency 'train-core', '~> 1.4', '>= 1.4.37'
spec.add_dependency 'thor', '~> 0.20'
spec.add_dependency 'json', '>= 1.8', '< 3.0'
spec.add_dependency 'method_source', '~> 0.8'
Expand Down
2 changes: 1 addition & 1 deletion inspec.gemspec
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.3'

spec.add_dependency 'train', '~> 1.4', '>= 1.4.35'
spec.add_dependency 'train', '~> 1.4', '>= 1.4.37'
spec.add_dependency 'thor', '~> 0.20'
spec.add_dependency 'json', '>= 1.8', '< 3.0'
spec.add_dependency 'method_source', '~> 0.8'
Expand Down
17 changes: 15 additions & 2 deletions lib/inspec/schema.rb
Expand Up @@ -200,18 +200,31 @@ class Schema
},
}.freeze

# using a proc here so we can lazy load it when we need
PLATFORMS = lambda do
require 'train'
Train.create('mock').connection
Train::Platforms.export
end

LIST = {
'exec-json' => EXEC_JSON,
'exec-jsonmin' => EXEC_JSONMIN,
'platforms' => PLATFORMS,
}.freeze

def self.names
LIST.keys
end

def self.json(name)
v = LIST[name] ||
raise("Cannot find schema #{name.inspect}.")
if !LIST.key?(name)
raise("Cannot find schema #{name.inspect}.")
elsif LIST[name].is_a?(Proc)
v = LIST[name].call
else
v = LIST[name]
end
JSON.dump(v)
end
end
Expand Down
21 changes: 21 additions & 0 deletions test/functional/inspec_schema_test.rb
@@ -0,0 +1,21 @@
# encoding: utf-8

require 'functional/helper'

describe 'inspec schema' do
include FunctionalHelper

describe 'extracting the platforms schema export' do
it 'can execute a platforms schema command' do
out = inspec('schema platforms')
out.stderr.must_equal ''
out.exit_status.must_equal 0
data = JSON.parse(out.stdout)
data.class.must_equal Array
data.size.must_be(:>, 1)
data[0]['name'].must_equal 'aix'
families = ['aix', 'unix', 'os']
data[0]['families'].must_equal families
end
end
end