Write version_constraints as an array for inspec.lock (#2619)

* Modify version constraints to be an Array

This will allow both old and new versions of InSpec to parse the
`inspec.lock` correctly.

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
This commit is contained in:
Jerry Aldrich 2018-03-12 03:02:37 -10:00 committed by Jared Quick
parent c3064f0b0d
commit 439fcb5993
2 changed files with 20 additions and 2 deletions

View file

@ -80,7 +80,7 @@ module Inspec
h = { h = {
'name' => name, 'name' => name,
'resolved_source' => resolved_source, 'resolved_source' => resolved_source,
'version_constraints' => version_constraints.to_s, 'version_constraints' => version_constraints,
} }
if !dependencies.empty? if !dependencies.empty?

View file

@ -2,9 +2,10 @@ require 'helper'
require 'inspec/dependencies/requirement' require 'inspec/dependencies/requirement'
describe Inspec::Requirement do describe Inspec::Requirement do
describe '#source_satisfies_spec?' do
let(:req) { Inspec::Requirement.new('foo', constraints, nil, nil, {}) } let(:req) { Inspec::Requirement.new('foo', constraints, nil, nil, {}) }
describe '#source_satisfies_spec?' do
describe 'when there are no version constraints' do describe 'when there are no version constraints' do
let(:constraints) { nil } let(:constraints) { nil }
it 'returns true' do it 'returns true' do
@ -72,4 +73,21 @@ describe Inspec::Requirement do
end end
end end
end end
describe '#to_hash' do
let(:constraints) { nil }
it 'returns the correct Hash' do
resolved_source = { compliance: 'spam', url: 'eggs', sha256: 'bacon' }
req.stubs(:resolved_source).returns(resolved_source)
req.stubs(:dependencies).returns({})
correct_hash = {
'name' => 'foo',
'resolved_source' => resolved_source,
'version_constraints' => [],
}
req.to_hash.must_equal correct_hash
end
end
end end