File: simple_tree_traverser_spec.rb

package info (click to toggle)
ruby-dep-selector 1.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 804 kB
  • ctags: 363
  • sloc: ruby: 2,970; cpp: 1,040; makefile: 5
file content (185 lines) | stat: -rw-r--r-- 8,699 bytes parent folder | download
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#
# Author:: Christopher Walters (<cw@opscode.com>)
# Author:: Mark Anderson (<mark@opscode.com>)
# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))

transitive_deps_1 =
  [{"key"=>["A", "1.0.0"], "value"=>{"X"=>">= 1.0.0"}},
   {"key"=>["A", "2.0.0"], "value"=>{"X"=>"= 2.0.0"}},

   {"key"=>["B", "1.0.0"], "value"=>{}},

   {"key"=>["C", "1.0.0"], "value"=>{"A"=>nil}},

   {"key"=>["D", "1.0.0"], "value"=>{"A"=>"= 2.0.0", "X"=>"= 1.0.0"}},

   {"key"=>["X", "1.0.0"], "value"=>{}},
   {"key"=>["X", "2.0.0"], "value"=>{}}
  ]

transitive_deps_2 =
  [{"key"=>["A", "1.0.0"], "value"=>{"L"=>">= 1.0.0"}},
   {"key"=>["A", "2.0.0"], "value"=>{"L"=>"= 2.0.0"}},
   {"key"=>["A", "3.0.0"], "value"=>{"X"=>nil}},

   {"key"=>["B", "1.0.0"], "value"=>{"X"=>">= 1.0.0"}},
   {"key"=>["B", "2.0.0"], "value"=>{}},

   {"key"=>["C", "1.0.0"], "value"=>{"X"=>"= 3.0.0"}},

   {"key"=>["D", "1.0.0"], "value"=>{"X"=>nil}},

   {"key"=>["L", "1.0.0"], "value"=>{"X"=>"= 1.0.0"}},
   {"key"=>["L", "2.0.0"], "value"=>{"X"=>"= 2.0.0"}},

   {"key"=>["X", "1.0.0"], "value"=>{}},
   {"key"=>["X", "2.0.0"], "value"=>{}},
   {"key"=>["X", "3.0.0"], "value"=>{}},
  ]

dependency_on_non_existent_package =
  [{"key"=>["depends_on_nosuch", "1.0.0"], "value"=>{"nosuch"=>"= 2.0.0"}},
   {"key"=>["transitive_dep_on_nosuch", "1.0.0"], "value"=>{"depends_on_nosuch"=>nil}}
  ]

describe DepSelector::ErrorReporter::SimpleTreeTraverser do

  describe "give_feedback" do

    it "finds constraints on the target package in the solution constraints" do
      dep_graph = DepSelector::DependencyGraph.new
      setup_constraint(dep_graph, transitive_deps_1)

      solution_constraints =
        setup_soln_constraints(dep_graph,
                               [
                                ["X", "> 1.0.0"],
                                ["D"]
                               ])
      er = DepSelector::ErrorReporter::SimpleTreeTraverser.new
      er.give_feedback(dep_graph, solution_constraints, 1, dep_graph.package('X')).should ==
        "Unable to satisfy constraints on package X due to solution constraint (D >= 0.0.0). Solution constraints that may result in a constraint on X: [(X > 1.0.0)], [(D = 1.0.0) -> (A = 2.0.0) -> (X = 2.0.0)], [(D = 1.0.0) -> (X = 1.0.0)]"
    end

    it "finds constraints on the target package in first-level dependencies" do
      dep_graph = DepSelector::DependencyGraph.new
      setup_constraint(dep_graph, transitive_deps_1)

      solution_constraints =
        setup_soln_constraints(dep_graph,
                               [
                                ["A"],
                                ["D"]
                               ])
      er = DepSelector::ErrorReporter::SimpleTreeTraverser.new
      er.give_feedback(dep_graph, solution_constraints, 1, dep_graph.package('X')).should ==
        "Unable to satisfy constraints on package X due to solution constraint (D >= 0.0.0). Solution constraints that may result in a constraint on X: [(A = 1.0.0) -> (X >= 1.0.0)], [(A = 2.0.0) -> (X = 2.0.0)], [(D = 1.0.0) -> (A = 2.0.0) -> (X = 2.0.0)], [(D = 1.0.0) -> (X = 1.0.0)]"
    end

    it "finds constraints on the target package in transitive dependencies" do
      dep_graph = DepSelector::DependencyGraph.new
      setup_constraint(dep_graph, transitive_deps_1)

      solution_constraints =
        setup_soln_constraints(dep_graph,
                               [
                                ["C"],
                                ["D"]
                               ])
      er = DepSelector::ErrorReporter::SimpleTreeTraverser.new
      er.give_feedback(dep_graph, solution_constraints, 1, dep_graph.package("X")).should ==
        "Unable to satisfy constraints on package X due to solution constraint (D >= 0.0.0). Solution constraints that may result in a constraint on X: [(C = 1.0.0) -> (A = 1.0.0) -> (X >= 1.0.0)], [(C = 1.0.0) -> (A = 2.0.0) -> (X = 2.0.0)], [(D = 1.0.0) -> (A = 2.0.0) -> (X = 2.0.0)], [(D = 1.0.0) -> (X = 1.0.0)]"
    end

    it "should construct all paths from the solution constraint packages to the most constrained package and collapse paths that have exactly one difference on the version selected of the same package" do
      dep_graph = DepSelector::DependencyGraph.new
      setup_constraint(dep_graph, transitive_deps_2)

      solution_constraints =
        setup_soln_constraints(dep_graph,
                               [
                                ["A", "<= 2.0.0"],
                                ["B"],
                                ["C"],
                                ["D"]
                               ])
      er = DepSelector::ErrorReporter::SimpleTreeTraverser.new
      er.give_feedback(dep_graph, solution_constraints, 2, dep_graph.package("X")).should ==
        "Unable to satisfy constraints on package X due to solution constraint (C >= 0.0.0). Solution constraints that may result in a constraint on X: [(A = 1.0.0) -> (L = 1.0.0) -> (X = 1.0.0)], [(A = {1.0.0,2.0.0}) -> (L = 2.0.0) -> (X = 2.0.0)], [(B = 1.0.0) -> (X >= 1.0.0)], [(C = 1.0.0) -> (X = 3.0.0)], [(D = 1.0.0) -> (X >= 0.0.0)]"
    end

    it "should report failures that are caused by non-existent dependencies" do
      dep_graph = DepSelector::DependencyGraph.new
      setup_constraint(dep_graph, dependency_on_non_existent_package)

      solution_constraints =
        setup_soln_constraints(dep_graph,
                               [
                                ["depends_on_nosuch"]
                               ])
      er = DepSelector::ErrorReporter::SimpleTreeTraverser.new
      er.give_feedback(dep_graph, solution_constraints, 0, dep_graph.package('nosuch')).should ==
        "Unable to satisfy constraints on package nosuch, which does not exist, due to solution constraint (depends_on_nosuch >= 0.0.0). Solution constraints that may result in a constraint on nosuch: [(depends_on_nosuch = 1.0.0) -> (nosuch = 2.0.0)]"
    end

    it "should report failures that are caused by non-existent transitive dependencies" do
      dep_graph = DepSelector::DependencyGraph.new
      setup_constraint(dep_graph, dependency_on_non_existent_package)

      solution_constraints =
        setup_soln_constraints(dep_graph,
                               [
                                ["transitive_dep_on_nosuch"]
                               ])
      er = DepSelector::ErrorReporter::SimpleTreeTraverser.new
      er.give_feedback(dep_graph, solution_constraints, 0, dep_graph.package('nosuch')).should ==
        "Unable to satisfy constraints on package nosuch, which does not exist, due to solution constraint (transitive_dep_on_nosuch >= 0.0.0). Solution constraints that may result in a constraint on nosuch: [(transitive_dep_on_nosuch = 1.0.0) -> (depends_on_nosuch = 1.0.0) -> (nosuch = 2.0.0)]"
    end

    it "should not report non-existent cookbooks when they are not deemed to be the most constrained package" do
      dep_graph = DepSelector::DependencyGraph.new
      setup_constraint(dep_graph, transitive_deps_1)
      setup_constraint(dep_graph, dependency_on_non_existent_package)

      solution_constraints =
        setup_soln_constraints(dep_graph,
                               [
                                ["X", "> 1.0.0"],
                                ["D"]
                               ])
      er = DepSelector::ErrorReporter::SimpleTreeTraverser.new
      er.give_feedback(dep_graph, solution_constraints, 1, dep_graph.package('X')).should ==
        "Unable to satisfy constraints on package X due to solution constraint (D >= 0.0.0). Solution constraints that may result in a constraint on X: [(X > 1.0.0)], [(D = 1.0.0) -> (A = 2.0.0) -> (X = 2.0.0)], [(D = 1.0.0) -> (X = 1.0.0)]"
    end

  end

  describe "collapse" do

    it "should collapse two neighbors that have only one difference in the path" do
      skip
    end

    it "should not collapse neighbors that are only different at the constraint on the target package" do
      skip
    end
    
  end

end