warn about legacy supports fields in metadata

I.e.: Prevent users from writing `supports: linux` and similar. These are deprecated and will be removed. Also improve the warning to indicate what the user should do instead. Finally add tests to make sure we get all these.
This commit is contained in:
Dominik Richter 2016-01-16 17:04:25 +01:00 committed by Christoph Hartmann
parent a5ed04d51c
commit d10207caca
2 changed files with 16 additions and 2 deletions

View file

@ -73,7 +73,9 @@ module Inspec
family = try_support[:'os-family']
release = try_support[:release]
elsif entry.is_a?(String)
@logger.warn("Using deprecated `supports` syntax: using `#{entry}` as OS family")
@logger.warn(
"Do not use deprecated `supports: #{entry}` syntax. Instead use "\
"`supports: {os-family: #{entry}}`.")
family = entry
end

View file

@ -6,6 +6,8 @@ require 'helper'
require 'inspec/metadata'
describe 'metadata with supported operating systems' do
let(:logger) { Minitest::Mock.new }
describe 'running on ubuntu 14.04' do
let (:backend) { MockLoader.new(:ubuntu1404).backend }
@ -38,7 +40,7 @@ describe 'metadata with supported operating systems' do
# @param [Type] params describe params
# @return [Type] description of returned object
def create_meta(params)
res = Inspec::Metadata.from_yaml('mock', "---", nil)
res = Inspec::Metadata.from_yaml('mock', "---", nil, logger)
# manually inject supported parameters
res.params[:supports] = params
Inspec::Metadata.finalize(res, 'mock')
@ -50,6 +52,16 @@ describe 'metadata with supported operating systems' do
m.supports_transport?(backend).must_equal true
end
it 'supports legacy simple support style, but warns' do
# i.e. setting this to something that would fail:
m = create_meta('linux')
logger.expect :warn, nil, [
'Do not use deprecated `supports: linux` '\
'syntax. Instead use `supports: {os-family: linux}`.']
m.supports_transport?(backend).must_equal true
logger.verify
end
it 'loads a profile which supports os ubuntu' do
m = create_meta({ 'os' => 'ubuntu' })
m.supports_transport?(backend).must_equal true