2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/errors"
|
|
|
|
require "inspec/dependencies/resolver"
|
2016-08-23 13:28:47 +00:00
|
|
|
|
|
|
|
class FakeDep
|
2016-09-08 09:11:44 +00:00
|
|
|
attr_reader :name
|
2016-08-23 13:28:47 +00:00
|
|
|
def initialize(name)
|
|
|
|
@name = name
|
2016-09-08 09:11:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def resolved_source
|
|
|
|
{ path: name }
|
2016-08-23 13:28:47 +00:00
|
|
|
end
|
2016-09-09 12:36:10 +00:00
|
|
|
|
|
|
|
def source_satisfies_spec?
|
|
|
|
true
|
|
|
|
end
|
2016-08-23 13:28:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe Inspec::Resolver do
|
|
|
|
let(:subject) { Inspec::Resolver.new }
|
|
|
|
|
|
|
|
describe "#resolve" do
|
|
|
|
it "returns a Hash" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(subject.resolve([])).must_equal({})
|
2016-08-23 13:28:47 +00:00
|
|
|
end
|
|
|
|
|
2016-09-09 12:36:10 +00:00
|
|
|
it "errors if a dependency is listed twice at the same level" do
|
|
|
|
dep = FakeDep.new("fake_dep_0")
|
2019-09-30 22:31:55 +00:00
|
|
|
_(lambda { subject.resolve([dep, dep]) }).must_raise Inspec::DuplicateDep
|
2016-09-09 12:36:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is a simple cycle " do
|
|
|
|
dep0 = FakeDep.new("fake_dep_0")
|
|
|
|
dep1 = FakeDep.new("fake_dep_1")
|
|
|
|
dep2 = FakeDep.new("fake_dep_2")
|
|
|
|
|
|
|
|
dep0.stubs(:dependencies).returns([dep1])
|
|
|
|
|
|
|
|
dep1.stubs(:dependencies).returns([dep2])
|
|
|
|
dep2.stubs(:dependencies).returns([dep1])
|
2019-09-30 22:31:55 +00:00
|
|
|
_(lambda { subject.resolve([dep0]) }).must_raise Inspec::CyclicDependencyError
|
2016-09-09 12:36:10 +00:00
|
|
|
end
|
|
|
|
|
2016-08-23 13:28:47 +00:00
|
|
|
it "errors if the source version doesn't match the requirement" do
|
|
|
|
dep = FakeDep.new("fake_dep_0")
|
|
|
|
dep.expects(:source_satisfies_spec?).returns(false)
|
|
|
|
dep.expects(:source_version).returns("1.0.0")
|
2017-11-09 11:29:41 +00:00
|
|
|
dep.expects(:version_constraints).returns([">= 1.0.1"])
|
2019-09-30 22:31:55 +00:00
|
|
|
_(lambda { subject.resolve([dep]) }).must_raise Inspec::UnsatisfiedVersionSpecification
|
2016-08-23 13:28:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|