mirror of
https://github.com/inspec/inspec
synced 2024-12-12 06:12:37 +00:00
86079ca3c7
When configuring a profile dependency, if the dependent profile had a hyphen in it, it would not properly match the default version constraint of `>= 0`. This is because a hyphen indicates the version is a pre-release version and proper version matching would require the constraint to also be listed with a pre-release version string. The proper solution is to use the `+` character instead which indicates a build number, which is what the hyphen was meant to convey. In the meantime, this change properly compares version strings as SemVer and also adds tests. Signed-off-by: Adam Leff <adam@leff.co>
75 lines
2.4 KiB
Ruby
75 lines
2.4 KiB
Ruby
require 'helper'
|
|
require 'inspec/dependencies/requirement'
|
|
|
|
describe Inspec::Requirement do
|
|
describe '#source_satisfies_spec?' do
|
|
let(:req) { Inspec::Requirement.new('foo', constraints, nil, nil, {}) }
|
|
|
|
describe 'when there are no version constraints' do
|
|
let(:constraints) { nil }
|
|
it 'returns true' do
|
|
req.source_satisfies_spec?.must_equal true
|
|
end
|
|
end
|
|
|
|
describe 'when there is a single, matching version constraint' do
|
|
let(:constraints) { '>= 1' }
|
|
it 'returns true' do
|
|
profile = mock
|
|
profile.stubs(:version).returns('2.0.0')
|
|
req.stubs(:profile).returns(profile)
|
|
req.source_satisfies_spec?.must_equal true
|
|
end
|
|
end
|
|
|
|
describe 'when there is a single, non-matching version constraint' do
|
|
let(:constraints) { '>= 2' }
|
|
it 'returns true' do
|
|
profile = mock
|
|
profile.stubs(:version).returns('1.0.0')
|
|
req.stubs(:profile).returns(profile)
|
|
req.source_satisfies_spec?.must_equal false
|
|
end
|
|
end
|
|
|
|
describe 'when there are multiple matching version constraints' do
|
|
let(:constraints) { ['>= 1', '< 3'] }
|
|
it 'returns true' do
|
|
profile = mock
|
|
profile.stubs(:version).returns('2.0.0')
|
|
req.stubs(:profile).returns(profile)
|
|
req.source_satisfies_spec?.must_equal true
|
|
end
|
|
end
|
|
|
|
describe 'when there are multiple version constraints and one does not match' do
|
|
let(:constraints) { ['>= 1', '< 3'] }
|
|
it 'returns true' do
|
|
profile = mock
|
|
profile.stubs(:version).returns('4.0.0')
|
|
req.stubs(:profile).returns(profile)
|
|
req.source_satisfies_spec?.must_equal false
|
|
end
|
|
end
|
|
|
|
describe 'when a profile has a version with a build number and the constraint matches' do
|
|
let(:constraints) { '>= 1' }
|
|
it 'returns true' do
|
|
profile = mock
|
|
profile.stubs(:version).returns('2.0.0+1')
|
|
req.stubs(:profile).returns(profile)
|
|
req.source_satisfies_spec?.must_equal true
|
|
end
|
|
end
|
|
|
|
describe 'when the constraint is the default >=0 and the profile has a pre-release number' do
|
|
let(:constraints) { '>= 0' }
|
|
it 'returns true' do
|
|
profile = mock
|
|
profile.stubs(:version).returns('2.0.0-1')
|
|
req.stubs(:profile).returns(profile)
|
|
req.source_satisfies_spec?.must_equal true
|
|
end
|
|
end
|
|
end
|
|
end
|