File: test.rb

package info (click to toggle)
puppetserver 8.7.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,476 kB
  • sloc: ruby: 5,764; sh: 997; java: 221; xml: 111; makefile: 94
file content (91 lines) | stat: -rw-r--r-- 2,550 bytes parent folder | download | duplicates (3)
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
require 'net/http'
require 'json'
require 'rspec/expectations'

include RSpec::Matchers

class CatalogTester
  def initialize
    @uri = URI("http://localhost:8140/puppet/v3/catalog/#{@catalog}?environment=#{@environment}")
  end

  def run
    encoded_result = Net::HTTP.get(@uri)
    result = JSON.parse(encoded_result)
    verify(result)
  end

  def verify(_result)
    raise NotImplementedError
  end
end

class CatalogOneTester < CatalogTester
  def initialize
    @catalog = 'testone'
    @environment = 'production'
    super
  end

  def verify(result)
    expect(result).to include('name' => @catalog)
    expect(result).to include('environment' => @environment)
    # v4 function
    expect(result['resources']).to include(a_hash_including('title' => 'do it'))
    # v3 function
    expect(result['resources']).to include(a_hash_including('title' => 'the old way of functions'))
    # class param from hiera
    expect(result['resources']).to include(a_hash_including('parameters' => { 'input' => 'froyo' }))
  end
end

class CatalogTwoTester < CatalogTester
  def initialize
    @catalog = 'testtwo'
    @environment = 'funky'
    super
  end

  def verify(result)
    expect(result).to include('name' => @catalog)
    expect(result).to include('environment' => @environment)
    # color is turned on in color function
    expect(result['resources']).to include(a_hash_including('title' => 'The funky color is ansi'))
    # v4 function
    expect(result['resources']).to include(a_hash_including('title' => 'Always on the one'))
    # v3 function
    expect(result['resources']).to include(a_hash_including('title' => 'old school v3 function'))
    # class param from hiera
    expect(result['resources']).to include(a_hash_including('parameters' => { 'input' => 'hiera_funky' }))
  end
end

class CatalogThreeTester < CatalogTester
  def initialize
    @catalog = 'testthree'
    @environment = 'production'
    super
  end

  def verify(result)
    expect(result).to include('name' => @catalog)
    expect(result).to include('environment' => @environment)
    # function only loaded for this node
    expect(result['resources']).to include(a_hash_including('title' => "I'm a different function"))
  end
end

# Use tester2 for funky env, and swap out for tester1 to use production instead,
# or tester3 for a node in the production env with special classification.
tester2 = CatalogTwoTester.new
Process.fork do
  tester2.run
end

exit_codes = Process.waitall

if exit_codes.all? { |s| s[1].exitstatus.zero? }
  exit 0
else
  exit 1
end