File: title_hash_prioritizer_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (50 lines) | stat: -rw-r--r-- 1,857 bytes parent folder | download | duplicates (2)
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
require 'spec_helper'
require 'puppet/graph'

describe Puppet::Graph::TitleHashPrioritizer do
  it "produces different priorities for different resource references" do
    prioritizer = Puppet::Graph::TitleHashPrioritizer.new

    expect(prioritizer.generate_priority_for(resource(:notify, "one"))).to_not(
      eq(prioritizer.generate_priority_for(resource(:notify, "two"))))
  end

  it "always produces the same priority for the same resource ref" do
    a_prioritizer = Puppet::Graph::TitleHashPrioritizer.new
    another_prioritizer = Puppet::Graph::TitleHashPrioritizer.new

    expect(a_prioritizer.generate_priority_for(resource(:notify, "one"))).to(
      eq(another_prioritizer.generate_priority_for(resource(:notify, "one"))))
  end

  it "does not use the container when generating priorities" do
    prioritizer = Puppet::Graph::TitleHashPrioritizer.new

    expect(prioritizer.generate_priority_contained_in(nil, resource(:notify, "one"))).to(
      eq(prioritizer.generate_priority_for(resource(:notify, "one"))))
  end

  it "can retrieve a previously provided priority with the same resource" do
    prioritizer = Puppet::Graph::TitleHashPrioritizer.new
    resource = resource(:notify, "title")

    generated = prioritizer.generate_priority_for(resource)

    expect(prioritizer.priority_of(resource)).to eq(generated)
  end

  it "can not retrieve the priority of a resource with a different resource with the same title" do
    prioritizer = Puppet::Graph::TitleHashPrioritizer.new
    resource = resource(:notify, "title")
    different_resource = resource(:notify, "title")

    prioritizer.generate_priority_for(resource)

    expect(prioritizer.priority_of(resource)).not_to be_nil
    expect(prioritizer.priority_of(different_resource)).to be_nil
  end

  def resource(type, title)
    Puppet::Resource.new(type, title)
  end
end