This repository was archived by the owner on Nov 30, 2022. It is now read-only.
generated from codenamephp/template.chef.cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_users_from_data_bag_spec.rb
81 lines (71 loc) · 2.65 KB
/
config_users_from_data_bag_spec.rb
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
require 'spec_helper'
describe 'codenamephp_git_client_config_users_from_data_bag' do
platform 'debian' # https://github.com/chefspec/chefspec/issues/953
step_into :codenamephp_git_client_config_users_from_data_bag
before(:example) do
stub_search('users', 'codenamephp_git_client_config*:*').and_return([])
end
context 'Install with minimal properties' do
before(:example) do
stub_search('users', 'codenamephp_git_client_config*:*').and_return([
{
'id' => 'user1',
'codenamephp' => {
'git_client' => {
'config' => { 'user1_config1' => 'user1_value1', 'user1_config2' => 'user1_value2' },
},
},
},
{
'id' => 'user2',
'codenamephp' => {
'git_client' => {
'config' => {
'config' => { 'user2_config1' => 'user2_value1', 'user2_config2' => 'user2_value2' },
},
},
},
},
{
'id' => 'user3',
'codenamephp' => {
'git_client' => {},
},
},
{
'id' => 'user4',
'codenamephp' => {
'git_client' => {
'config' => { 'user4_config1' => 'user4_value1', 'user4_config2' => 'user4_value2' },
},
},
},
])
end
stubs_for_provider('codenamephp_git_client_config_users_from_data_bag[Manage git users]') do |provider|
allow(provider).to receive_shell_out()
allow(provider).to receive_shell_out('getent passwd user1', exitstatus: 0)
allow(provider).to receive_shell_out('getent passwd user2', exitstatus: 1)
allow(provider).to receive_shell_out('getent passwd user3', exitstatus: 0)
allow(provider).to receive_shell_out('getent passwd user4', exitstatus: 0)
end
recipe do
codenamephp_git_client_config_users_from_data_bag 'Manage git users'
end
it 'converges successfully' do
expect { chef_run }.to_not raise_error
end
it 'should set configs with mapped users' do
expect(chef_run).to set_codenamephp_git_client_config_users('Config users from databag').with(
users_configs: {
'user1' => { 'user1_config1' => 'user1_value1', 'user1_config2' => 'user1_value2' },
'user4' => { 'user4_config1' => 'user4_value1', 'user4_config2' => 'user4_value2' },
}
)
end
it 'does nothing when databag was not found' do
stub_search('users', 'codenamephp_git_client_config*:*').and_raise(Chef::Exceptions::InvalidDataBagPath)
expect(chef_run).to_not set_codenamephp_git_client_config_users('Config users from databag')
end
end
end