Skip to content

Commit

Permalink
Add spec for openldap_database provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
towo authored and tdb committed May 23, 2024
1 parent 1a8e191 commit 4303368
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions spec/unit/puppet/provider/openldap_database/olc_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

require 'spec_helper'

describe Puppet::Type.type(:openldap_database).provider(:olc) do
let(:params) do
{
suffix: 'dc=example,dc=com',
backend: 'mdb',
readonly: false,
# provider: described_class.name,
}
end

let(:resource) do
Puppet::Type.type(:openldap_database).new(params)
end
let(:provider) do
resource.provider
end

before do
allow(described_class).to receive(:slapcat).with('(|(olcDatabase=monitor)(olcDatabase={0}config)(&(objectClass=olcDatabaseConfig)(|(objectClass=olcBdbConfig)(objectClass=olcHdbConfig)(objectClass=olcMdbConfig)(objectClass=olcMonitorConfig)(objectClass=olcRelayConfig)(objectClass=olcLDAPConfig))))').and_return(<<~SLAPCAT)
dn: olcDatabase={1}mdb,cn=config
olcDatabase: {1}mdb
olcReadOnly: FALSE
SLAPCAT
allow(provider).to receive(:slapcat)
allow(provider).to receive(:ldapmodify)
allow(provider).to receive(:ldapadd)
# allow(described_class).to receive(:slapcat)
# allow(described_class).to receive(:ldapmodify)
# allow(described_class).to receive(:ldapadd)
end

describe 'when creating' do
context 'with readonly set to false' do
it 'parses olcReadOnly as false' do
provider.create
expect(described_class.instances.first.readonly).to eq :false
# expect(described_class.instances.first.readonly).to eq(:false)
end
end

context 'with readonly set to true' do
let(:params) do
super().merge({ readonly: true })
end

it 'parses olcReadonly' do
expect(described_class.instances.first.readonly).to eq(:true)
end
end
end
end

0 comments on commit 4303368

Please sign in to comment.