File: 014_elasticsearch_component_template_spec.rb

package info (click to toggle)
puppet-module-voxpupuli-elasticsearch 9.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,496 kB
  • sloc: ruby: 9,906; sh: 392; makefile: 4
file content (138 lines) | stat: -rw-r--r-- 3,665 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
# frozen_string_literal: true

require 'spec_helper'

describe 'elasticsearch::component_template', type: 'define' do
  on_supported_os(
    hardwaremodels: ['x86_64'],
    supported_os: [
      {
        'operatingsystem' => 'CentOS',
        'operatingsystemrelease' => ['6']
      }
    ]
  ).each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts.merge(
          scenario: '',
          common: ''
        )
      end

      let(:title) { 'foo' }
      let(:pre_condition) do
        'class { "elasticsearch" : }'
      end

      describe 'parameter validation' do
        %i[api_ca_file api_ca_path].each do |param|
          let :params do
            {
              :ensure => 'present',
              :content => '{}',
              param => 'foo/cert'
            }
          end

          it 'validates cert paths' do
            expect(subject).to compile.and_raise_error(%r{expects a})
          end
        end

        describe 'missing parent class' do
          it { is_expected.not_to compile }
        end
      end

      describe 'template from source' do
        let :params do
          {
            ensure: 'present',
            source: 'puppet:///path/to/foo.json',
            api_protocol: 'https',
            api_host: '127.0.0.1',
            api_port: 9201,
            api_timeout: 11,
            api_basic_auth_username: 'elastic',
            api_basic_auth_password: 'password',
            validate_tls: false
          }
        end

        it { is_expected.to contain_elasticsearch__component_template('foo') }

        it do
          expect(subject).to contain_es_instance_conn_validator('foo-component_template-conn-validator').
            that_comes_before('Elasticsearch_component_template[foo]')
        end

        it 'passes through parameters' do
          expect(subject).to contain_elasticsearch_component_template('foo').with(
            ensure: 'present',
            source: 'puppet:///path/to/foo.json',
            protocol: 'https',
            host: '127.0.0.1',
            port: 9201,
            timeout: 11,
            username: 'elastic',
            password: 'password',
            validate_tls: false
          )
        end
      end

      describe 'class parameter inheritance' do
        let :params do
          {
            ensure: 'present',
            content: '{}'
          }
        end
        let(:pre_condition) do
          <<-EOS
            class { 'elasticsearch' :
              api_protocol => 'https',
              api_host => '127.0.0.1',
              api_port => 9201,
              api_timeout => 11,
              api_basic_auth_username => 'elastic',
              api_basic_auth_password => 'password',
              api_ca_file => '/foo/bar.pem',
              api_ca_path => '/foo/',
              validate_tls => false,
            }
          EOS
        end

        it do
          expect(subject).to contain_elasticsearch_component_template('foo').with(
            ensure: 'present',
            content: '{}',
            protocol: 'https',
            host: '127.0.0.1',
            port: 9201,
            timeout: 11,
            username: 'elastic',
            password: 'password',
            ca_file: '/foo/bar.pem',
            ca_path: '/foo/',
            validate_tls: false
          )
        end
      end

      describe 'template deletion' do
        let :params do
          {
            ensure: 'absent'
          }
        end

        it 'removes templates' do
          expect(subject).to contain_elasticsearch_component_template('foo').with(ensure: 'absent')
        end
      end
    end
  end
end