File: transport_schema_def_spec.rb

package info (click to toggle)
ruby-puppet-resource-api 1.8.16-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,228 kB
  • sloc: ruby: 9,519; sh: 4; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,669 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
51
52
53
54
55
56
57
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Puppet::ResourceApi::TransportSchemaDef do
  subject(:type) { described_class.new(definition) }

  let(:definition) do
    { name: 'some_target',
      connection_info: {
        host:        {
          type:      'String',
          desc:      'The IP address or hostname',
        },
        user:        {
          type:      'String',
          desc:      'The user to connect as',
        },
      } }
  end

  it { expect { described_class.new(nil) }.to raise_error Puppet::DevError, %r{TransportSchemaDef must be a Hash} }

  describe '#attributes' do
    context 'when type has attributes' do
      it { expect(type.attributes).to be_key(:host) }
      it { expect(type.attributes).to be_key(:user) }
    end
  end

  describe '#validate' do
    context 'when resource is missing attributes' do
      let(:resource) { {} }

      it 'raises an error listing the missing attributes' do
        expect { type.validate(resource) }.to raise_error Puppet::ResourceError, %r{host}
        expect { type.validate(resource) }.to raise_error Puppet::ResourceError, %r{user}
      end
    end

    context 'when resource has all its attributes' do
      let(:resource) { { host: '1234', user: '4321' } }

      it {  expect { type.validate(resource) }.not_to raise_error }
    end
  end

  describe '#notify_schema_errors' do
    context 'when a message is received ' do
      let(:message) { 'Missing attribute: foo' }

      it 'raises an error with the supplied message' do
        expect { type.notify_schema_errors(message) }.to raise_error Puppet::DevError, message
      end
    end
  end
end