File: ruby_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 (65 lines) | stat: -rw-r--r-- 1,804 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
# frozen_string_literal: true

require 'spec_helper_rspec'

describe Puppet::Type.type(:elasticsearch_user).provider(:ruby) do
  describe 'instances' do
    it 'has an instance method' do
      expect(described_class).to respond_to :instances
    end

    context 'without users' do
      it 'returns no resources' do
        allow(described_class).to receive(:command_with_path).with('list').and_return(
          'No users found'
        )

        expect(described_class.instances.size).to eq(0)
        expect(described_class).to have_received(:command_with_path).with('list')
      end
    end

    context 'with one user' do
      it 'returns one resource' do
        allow(described_class).to receive(:command_with_path).with('list').and_return(
          'elastic        : admin*,power_user'
        )

        expect(described_class.instances[0].instance_variable_get(
                 '@property_hash'
               )).to eq(
                 ensure: :present,
                 name: 'elastic',
                 provider: :ruby
               )
        expect(described_class).to have_received(:command_with_path).with('list')
      end
    end

    context 'with multiple users' do
      it 'returns three resources' do
        allow(described_class).to receive(
          :command_with_path
        ).with('list').and_return(
          <<-EOL
            elastic        : admin*
            logstash       : user
            kibana         : kibana
          EOL
        )

        expect(described_class.instances.length).to eq(3)

        expect(described_class).to have_received(
          :command_with_path
        ).with('list')
      end
    end
  end

  describe 'prefetch' do
    it 'has a prefetch method' do
      expect(described_class).to respond_to :prefetch
    end
  end
end