inspec/test/unit/dependencies/lockfile_test.rb
Steven Danna 85cbe713d7
Add GitFetcher and rework Fetchers+SourceReaders
This adds a new git fetcher. In doing so, it also refactors how the
fetchers work a bit to better support fetchers that need to resolve
user-provided sources to fully specified sources appropriate for a
lockfile.

Signed-off-by: Steven Danna <steve@chef.io>
2016-09-09 14:14:36 +01:00

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: 0
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: 0
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' => 0,
'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' => 0,
'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