mirror of
https://github.com/inspec/inspec
synced 2024-12-01 00:49:24 +00:00
f23a0d1098
Signed-off-by: Steven Danna <steve@chef.io>
72 lines
1.9 KiB
Ruby
72 lines
1.9 KiB
Ruby
require 'helper'
|
|
|
|
describe Inspec::Lockfile do
|
|
# Ruby 1.9: .to_yaml format is slightly different
|
|
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.0")
|
|
let(:lockfile_content) {
|
|
<<EOF
|
|
---
|
|
lockfile_version: 1
|
|
depends:
|
|
- name: foo
|
|
resolved_source:
|
|
url: http://foo
|
|
version_constraints: ! '>= 0'
|
|
dependencies:
|
|
- name: bar
|
|
resolved_source:
|
|
url: http://bar
|
|
version_constraints: ! '>= 0'
|
|
EOF
|
|
}
|
|
else
|
|
let(:lockfile_content) {
|
|
<<EOF
|
|
---
|
|
lockfile_version: 1
|
|
depends:
|
|
- name: foo
|
|
resolved_source:
|
|
url: http://foo
|
|
version_constraints: ">= 0"
|
|
dependencies:
|
|
- name: bar
|
|
resolved_source:
|
|
url: http://bar
|
|
version_constraints: ">= 0"
|
|
EOF
|
|
}
|
|
end
|
|
|
|
let(:lockfile_hash) {
|
|
{ 'lockfile_version' => 1,
|
|
'depends' => [
|
|
{ 'name' => "foo", 'resolved_source' => {'url' => "http://foo"}, 'version_constraints' => ">= 0",
|
|
'dependencies' => [{ 'name' => 'bar', 'resolved_source' => {'url' => 'http://bar' }, 'version_constraints' => ">= 0"}]
|
|
}]}
|
|
}
|
|
|
|
let(:lockfile_hash_with_symbols) {
|
|
{ 'lockfile_version' => 1,
|
|
'depends' => [
|
|
{ name: "foo", resolved_source: {url: "http://foo"}, version_constraints: ">= 0",
|
|
dependencies: [{ name: 'bar', resolved_source: {url: 'http://bar' }, version_constraints: ">= 0"}]
|
|
}]}
|
|
}
|
|
|
|
it "can generate a yaml representation of the lockfile" do
|
|
l = Inspec::Lockfile.new(lockfile_hash)
|
|
l.to_yaml.force_encoding("UTF-8").must_equal lockfile_content
|
|
end
|
|
|
|
it "can generates a yaml representation of the lockfile even when the depends keys are symbols" do
|
|
l = Inspec::Lockfile.new(lockfile_hash_with_symbols)
|
|
l.to_yaml.force_encoding("UTF-8").must_equal lockfile_content
|
|
end
|
|
|
|
it "uses symbol keys for the deps by default" do
|
|
File.stubs(:read).with("testfile").returns(lockfile_content)
|
|
l = Inspec::Lockfile.from_file("testfile")
|
|
l.deps.must_equal lockfile_hash_with_symbols['depends']
|
|
end
|
|
end
|