Skip to content

Commit

Permalink
Use facterdb with db_spec file
Browse files Browse the repository at this point in the history
With OS facts set the following error occured:

```
NoMethodError:
     #   undefined method `downcase' for nil:NilClass
     #   ./vendor/bundle/ruby/3.2.0/gems/puppet-8.3.1/lib/puppet/provider/service/init.rb:25:in `block in <top (required)>'
```

since the service provider could not be determined correctly.
  • Loading branch information
traylenator committed Nov 10, 2023
1 parent ff72806 commit 8fc4788
Showing 1 changed file with 67 additions and 59 deletions.
126 changes: 67 additions & 59 deletions spec/defines/db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,85 @@
context 'default' do
let(:title) { 'testdb' }

let(:params) do
{ 'user' => 'testuser',
'password' => 'testpass' }
end
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) do
os_facts
end

it 'contains mongodb_database with mongodb::server requirement' do
is_expected.to contain_mongodb_database('testdb')
end
let(:params) do
{ 'user' => 'testuser',
'password' => 'testpass' }
end

it 'contains mongodb_user with mongodb_database requirement' do
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_username('testuser'). \
with_database('testdb'). \
that_requires('Mongodb_database[testdb]')
end
it 'contains mongodb_database with mongodb::server requirement' do
is_expected.to contain_mongodb_database('testdb')
end

it 'contains mongodb_user with proper roles' do
params['roles'] = %w[testrole1 testrole2]
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_roles(%w[testrole1 testrole2])
end
it 'contains mongodb_user with mongodb_database requirement' do
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_username('testuser'). \
with_database('testdb'). \
that_requires('Mongodb_database[testdb]')
end

it 'prefers password_hash instead of password' do
params['password_hash'] = 'securehash'
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_password_hash('securehash')
end
it 'contains mongodb_user with proper roles' do
params['roles'] = %w[testrole1 testrole2]
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_roles(%w[testrole1 testrole2])
end

it 'contains mongodb_database with proper tries param' do
params['tries'] = 5
is_expected.to contain_mongodb_database('testdb').with_tries(5)
end
end
it 'prefers password_hash instead of password' do
params['password_hash'] = 'securehash'
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_password_hash('securehash')
end

context 'with a db_name value' do
let(:title) { 'testdb-title' }
it 'contains mongodb_database with proper tries param' do
params['tries'] = 5
is_expected.to contain_mongodb_database('testdb').with_tries(5)
end
end

let(:params) do
{
'db_name' => 'testdb',
'user' => 'testuser',
'password' => 'testpass'
}
end
context 'with a db_name value' do
let(:title) { 'testdb-title' }

it 'contains mongodb_database with mongodb::server requirement' do
is_expected.to contain_mongodb_database('testdb')
end
let(:params) do
{
'db_name' => 'testdb',
'user' => 'testuser',
'password' => 'testpass'
}
end

it 'contains mongodb_user with mongodb_database requirement' do
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_username('testuser'). \
with_database('testdb'). \
that_requires('Mongodb_database[testdb]')
end
it 'contains mongodb_database with mongodb::server requirement' do
is_expected.to contain_mongodb_database('testdb')
end

it 'contains mongodb_user with proper roles' do
params['roles'] = %w[testrole1 testrole2]
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_roles(%w[testrole1 testrole2])
end
it 'contains mongodb_user with mongodb_database requirement' do
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_username('testuser'). \
with_database('testdb'). \
that_requires('Mongodb_database[testdb]')
end

it 'prefers password_hash instead of password' do
params['password_hash'] = 'securehash'
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_password_hash('securehash')
end
it 'contains mongodb_user with proper roles' do
params['roles'] = %w[testrole1 testrole2]
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_roles(%w[testrole1 testrole2])
end

it 'prefers password_hash instead of password' do
params['password_hash'] = 'securehash'
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_password_hash('securehash')
end

it 'contains mongodb_database with proper tries param' do
params['tries'] = 5
is_expected.to contain_mongodb_database('testdb').with_tries(5)
it 'contains mongodb_database with proper tries param' do
params['tries'] = 5
is_expected.to contain_mongodb_database('testdb').with_tries(5)
end
end
end
end
end

0 comments on commit 8fc4788

Please sign in to comment.