inspec/test/unit/profiles/metadata_test.rb

138 lines
4.6 KiB
Ruby
Raw Normal View History

2015-12-31 16:54:13 +00:00
# encoding: utf-8
# author: Dominik Richter
# author: Christoph Hartmann
require 'helper'
require 'inspec/metadata'
describe 'metadata with supported operating systems' do
let(:logger) { Minitest::Mock.new }
2016-04-16 16:54:05 +00:00
def supports_meta(params)
res = Inspec::Metadata.from_yaml('mock', "---", nil, logger)
# manually inject supported parameters
res.params[:supports] = params
2016-04-16 22:09:28 +00:00
Inspec::Metadata.finalize(res, 'mock', logger)
2016-04-16 16:54:05 +00:00
res
end
2015-12-31 16:54:13 +00:00
describe 'running on ubuntu 14.04' do
let (:backend) { MockLoader.new(:ubuntu1404).backend }
it 'finalizes a loaded metadata via Profile ID' do
res = Inspec::Metadata.from_yaml('mock', '---', nil)
Inspec::Metadata.finalize(res, 'mock')
res.params[:name].must_equal('mock')
end
it 'finalizes a loaded metadata via Profile ID and overwrites the ID' do
res = Inspec::Metadata.from_yaml('mock', "---\nname: hello", nil)
Inspec::Metadata.finalize(res, 'mock')
res.params[:name].must_equal('mock')
end
it 'finalizes a loaded metadata by turning strings into symbols' do
res = Inspec::Metadata.from_yaml('mock', "---\nauthor: world", nil)
Inspec::Metadata.finalize(res, 'mock')
res.params[:author].must_equal('world')
end
it 'loads the support field from metadata' do
res = Inspec::Metadata.from_yaml('mock',
"---\nsupports:\n - os: ubuntu", nil)
2016-04-16 22:09:28 +00:00
res.params[:supports].must_equal([{ os: 'ubuntu' }])
end
2015-12-31 16:57:59 +00:00
it 'load a profile with empty supports clause' do
2016-04-16 16:54:05 +00:00
m = supports_meta(nil)
2015-12-31 16:57:59 +00:00
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:
logger.expect :warn, nil, ["Do not use deprecated `supports: linux` syntax. Instead use:\nsupports:\n - os-family: linux\n\n"]
2016-04-16 22:09:28 +00:00
m = supports_meta('linux')
m.supports_transport?(backend).must_equal true
logger.verify
end
it 'supports legacy simple support style, but warns' do
# i.e. setting this to something that would fail:
logger.expect :warn, nil, ["Do not use deprecated `supports: linux` syntax. Instead use:\nsupports:\n - os-family: linux\n\n"]
m = supports_meta(['linux'])
m.supports_transport?(backend).must_equal true
logger.verify
end
2015-12-31 16:54:13 +00:00
it 'loads a profile which supports os ubuntu' do
2016-04-16 16:54:05 +00:00
m = supports_meta({ 'os' => 'ubuntu' })
2015-12-31 16:54:13 +00:00
m.supports_transport?(backend).must_equal true
end
it 'loads a profile which supports os name ubuntu' do
2016-04-16 16:54:05 +00:00
m = supports_meta({ 'os-name' => 'ubuntu' })
2015-12-31 16:54:13 +00:00
m.supports_transport?(backend).must_equal true
end
it 'loads a profile which supports os family linux' do
2016-04-16 16:54:05 +00:00
m = supports_meta({ 'os-family' => 'linux' })
2015-12-31 16:54:13 +00:00
m.supports_transport?(backend).must_equal true
end
it 'loads a profile which supports release 14.04' do
2016-04-16 16:54:05 +00:00
m = supports_meta({ 'release' => '14.04' })
2015-12-31 16:54:13 +00:00
m.supports_transport?(backend).must_equal true
end
it 'rejects a profile which supports release 12.04' do
2016-04-16 16:54:05 +00:00
m = supports_meta({ 'release' => '12.04' })
2015-12-31 16:54:13 +00:00
m.supports_transport?(backend).must_equal false
end
it 'loads a profile which supports ubuntu 14.04' do
2016-04-16 16:54:05 +00:00
m = supports_meta({ 'os-name' => 'ubuntu', 'release' => '14.04' })
2015-12-31 16:54:13 +00:00
m.supports_transport?(backend).must_equal true
end
it 'rejects a profile which supports ubuntu 12.04' do
2016-04-16 16:54:05 +00:00
m = supports_meta({ 'os-name' => 'ubuntu', 'release' => '12.04' })
2015-12-31 16:54:13 +00:00
m.supports_transport?(backend).must_equal false
end
2016-01-02 20:27:40 +00:00
it 'reject unsupported os' do
2016-04-16 16:54:05 +00:00
m = supports_meta({ 'os-name' => 'windows' })
2016-01-02 20:27:40 +00:00
m.supports_transport?(backend).must_equal false
end
2015-12-31 16:54:13 +00:00
end
2016-04-16 16:54:05 +00:00
describe 'testing the supported runtime' do
let(:current_version) { Inspec::VERSION }
let(:next_version) { Gem::Version.new(current_version).bump.to_s }
2016-04-16 16:54:05 +00:00
it 'returns true on testing the current version' do
m = supports_meta({ 'inspec' => current_version })
m.supports_runtime?.must_equal true
end
it 'returns true on testing the current version' do
m = supports_meta({ 'inspec' => '= ' + current_version })
m.supports_runtime?.must_equal true
end
it 'returns true on testing >= current version' do
m = supports_meta({ 'inspec' => '>= ' + current_version })
m.supports_runtime?.must_equal true
end
it 'returns false on testing >= the next version' do
m = supports_meta({ 'inspec' => '>= ' + next_version })
m.supports_runtime?.must_equal false
end
it 'returns false on testing > the next version' do
m = supports_meta({ 'inspec' => '> ' + next_version })
m.supports_runtime?.must_equal false
end
end
2015-12-31 16:54:13 +00:00
end