1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
require 'spec_helper'
require 'semantic_puppet/dependency/graph'
describe SemanticPuppet::Dependency::Graph do
Graph = SemanticPuppet::Dependency::Graph
GraphNode = SemanticPuppet::Dependency::GraphNode
ModuleRelease = SemanticPuppet::Dependency::ModuleRelease
Version = SemanticPuppet::Version
VersionRange = SemanticPuppet::VersionRange
describe '#initialize' do
it 'can be called without arguments' do
expect { Graph.new }.to_not raise_error
end
it 'implements the GraphNode protocol' do
expect(Graph.new).to be_a GraphNode
end
it 'adds constraints for every key in the passed hash' do
graph = Graph.new('foo' => 1, 'bar' => 2, 'baz' => 3)
expect(graph.constraints.keys).to match_array %w[ foo bar baz ]
end
it 'adds the named dependencies for every key in the passed hash' do
graph = Graph.new('foo' => 1, 'bar' => 2, 'baz' => 3)
expect(graph.dependency_names).to match_array %w[ foo bar baz ]
end
end
describe '#add_constraint' do
let(:graph) { Graph.new }
it 'can create a new constraint on a module' do
expect(graph.constraints.keys).to be_empty
graph.add_constraint('test', 'module-name', 'nil') { }
expect(graph.constraints.keys).to match_array %w[ module-name ]
end
it 'permits multiple constraints against the same module name' do
expect(graph.constraints.keys).to be_empty
graph.add_constraint('test', 'module-name', 'nil') { }
graph.add_constraint('test', 'module-name', 'nil') { }
expect(graph.constraints.keys).to match_array %w[ module-name ]
end
end
describe '#satisfies_dependency?' do
it 'is not satisfied by modules it does not depend on' do
graph = Graph.new('foo' => VersionRange.parse('1.x'))
release = ModuleRelease.new(nil, 'bar', Version.parse('1.0.0'))
expect(graph.satisfies_dependency?(release)).to_not be true
end
it 'is not satisfied by modules that do not fulfill the constraint' do
graph = Graph.new('foo' => VersionRange.parse('1.x'))
release = ModuleRelease.new(nil, 'foo', Version.parse('2.3.1'))
expect(graph.satisfies_dependency?(release)).to_not be true
end
it 'is not satisfied by modules that do not fulfill all the constraints' do
graph = Graph.new('foo' => VersionRange.parse('1.x'))
graph.add_constraint('me', 'foo', '1.2.3') do |node|
node.version.to_s == '1.2.3'
end
release = ModuleRelease.new(nil, 'foo', Version.parse('1.2.1'))
expect(graph.satisfies_dependency?(release)).to_not be true
end
it 'is satisfied by modules that do fulfill all the constraints' do
graph = Graph.new('foo' => VersionRange.parse('1.x'))
graph.add_constraint('me', 'foo', '1.2.3') do |node|
node.version.to_s == '1.2.3'
end
release = ModuleRelease.new(nil, 'foo', Version.parse('1.2.3'))
expect(graph.satisfies_dependency?(release)).to be true
end
end
describe '#add_graph_constraint' do
let(:graph) { Graph.new }
it 'can create a new constraint on a graph' do
expect(graph.constraints.keys).to be_empty
graph.add_graph_constraint('test') { }
expect(graph.constraints.keys).to match_array [ :graph ]
end
it 'permits multiple graph constraints' do
expect(graph.constraints.keys).to be_empty
graph.add_graph_constraint('test') { }
graph.add_graph_constraint('test') { }
expect(graph.constraints.keys).to match_array [ :graph ]
end
end
describe '#satisfies_graph?' do
it 'returns false if the solution violates a graph constraint' do
graph = Graph.new
graph.add_graph_constraint('me') do |nodes|
nodes.none? { |node| node.name =~ /z/ }
end
releases = [
double('Node', :name => 'foo'),
double('Node', :name => 'bar'),
double('Node', :name => 'baz'),
]
expect(graph.satisfies_graph?(releases)).to_not be true
end
it 'returns false if the solution violates any graph constraint' do
graph = Graph.new
graph.add_graph_constraint('me') do |nodes|
nodes.all? { |node| node.name.length < 5 }
end
graph.add_graph_constraint('me') do |nodes|
nodes.none? { |node| node.name =~ /z/ }
end
releases = [
double('Node', :name => 'foo'),
double('Node', :name => 'bar'),
double('Node', :name => 'bangerang'),
]
expect(graph.satisfies_graph?(releases)).to_not be true
end
it 'returns true if the solution violates no graph constraints' do
graph = Graph.new
graph.add_graph_constraint('me') do |nodes|
nodes.all? { |node| node.name.length < 5 }
end
graph.add_graph_constraint('me') do |nodes|
nodes.none? { |node| node.name =~ /z/ }
end
releases = [
double('Node', :name => 'foo'),
double('Node', :name => 'bar'),
double('Node', :name => 'boom'),
]
expect(graph.satisfies_graph?(releases)).to be true
end
end
end
|