|
71 | 71 | ], |
72 | 72 | }).each do |os, facts| |
73 | 73 | context "When on an #{os} system" do |
| 74 | + environment = RSpec::Puppet.environment |
74 | 75 | let(:facts) do |
75 | 76 | facts.merge({ |
76 | 77 | :concat_basedir => '/tmp', |
77 | 78 | :clientcert => 'my.client.cert', |
78 | 79 | :fqdn => 'my.fq.hostname', |
79 | | - :environment => 'production', |
80 | | - :puppetversion => Puppet.version |
| 80 | + :environment => environment, |
| 81 | + :puppetversion => Puppet.version |
81 | 82 | }) |
82 | 83 | end |
83 | 84 | it { is_expected.to compile.with_all_deps } |
84 | 85 | if Puppet.version.to_f >= 4.0 |
85 | 86 | facterbasepath = '/opt/puppetlabs/facter' |
| 87 | + facterbasepath_group = 'root' |
86 | 88 | else |
87 | 89 | facterbasepath = '/etc/facter' |
| 90 | + facterbasepath_group = 'puppet' |
88 | 91 | end |
89 | 92 | context 'when fed no parameters' do |
90 | | - if Puppet.version.to_f >= 4.0 |
91 | | - # setting environemnt doesn't work in puppet 4 |
92 | | - it "should lay down #{facterbasepath}/facts.d/local.yaml" do |
93 | | - should contain_file("#{facterbasepath}/facts.d/local.yaml").with_content( |
94 | | - /facts for my.client.cert/ |
95 | | - ).with_content( |
96 | | - /FQDN my.fq.hostname/ |
97 | | - ).with_validate_cmd( |
98 | | - "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"" |
99 | | - )#.with_content( |
100 | | - # /Environment production/ |
101 | | - #) |
102 | | - end |
103 | | - else |
104 | | - it "should lay down #{facterbasepath}/facts.d/local.yaml" do |
105 | | - should contain_file("#{facterbasepath}/facts.d/local.yaml").with_content( |
106 | | - /facts for my.client.cert/ |
107 | | - ).with_content( |
108 | | - /FQDN my.fq.hostname/ |
109 | | - ).with_content( |
110 | | - /Environment production/ |
111 | | - ).with_validate_cmd( |
112 | | - "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"" |
113 | | - ) |
114 | | - end |
| 93 | + it "should lay down #{facterbasepath}/facts.d/local.yaml" do |
| 94 | + should contain_file("#{facterbasepath}/facts.d/local.yaml").with({ |
| 95 | + :path=>"#{facterbasepath}/facts.d/local.yaml", |
| 96 | + :ensure=>'file', |
| 97 | + :owner=>'root', |
| 98 | + :group=>"#{facterbasepath_group}", |
| 99 | + :mode=>'0640' |
| 100 | + }).with_content( |
| 101 | + /facts for my.client.cert/ |
| 102 | + ).with_content( |
| 103 | + /FQDN my.fq.hostname/ |
| 104 | + ).with_content( |
| 105 | + /Environment #{environment}/ |
| 106 | + ).with_content( |
| 107 | + /---/ |
| 108 | + ).with_validate_cmd( |
| 109 | + "/usr/bin/env ruby -ryaml -e \"YAML.load_file '%'\"" |
| 110 | + ) |
115 | 111 | end |
116 | 112 | end#no params |
117 | 113 | context 'when the custom_facts parameter is properly set key values is string' do |
118 | | - let(:params) {{'custom_facts' => {'key1' => 'val1', 'key2' => 'val2'}}} |
119 | | - it 'should iterate through the hash and properly populate the local_facts.yaml file' do |
120 | | - should contain_file("#{facterbasepath}/facts.d/local.yaml").with_content( |
| 114 | + let(:params) { {'custom_facts' => {'key1' => 'val1', 'key2' => 'val2'}} } |
| 115 | + it "should lay down #{facterbasepath}/facts.d/local.yaml" do |
| 116 | + should contain_file("#{facterbasepath}/facts.d/local.yaml").with({ |
| 117 | + :path=>"#{facterbasepath}/facts.d/local.yaml", |
| 118 | + :ensure=>'file', |
| 119 | + :owner=>'root', |
| 120 | + :group=>"#{facterbasepath_group}", |
| 121 | + :mode=>'0640' |
| 122 | + }).with_content( |
| 123 | + /facts for my.client.cert/ |
| 124 | + ).with_content( |
| 125 | + /FQDN my.fq.hostname/ |
| 126 | + ).with_content( |
| 127 | + /Environment #{environment}/ |
| 128 | + ).with_content( |
121 | 129 | /---/ |
122 | 130 | ).with_content( |
123 | 131 | /key1: val1/ |
|
129 | 137 | end |
130 | 138 | end#custom_facts set key values is string |
131 | 139 | context 'when the custom_facts parameter is properly set key values is array' do |
132 | | - let(:params) {{'custom_facts' => {'key1' => [ 'val11', 'val12' ], 'key2' => [ 'val21', 'val22']}}} |
133 | | - it 'should iterate through the hash and properly populate the local_facts.yaml file' do |
134 | | - should contain_file("#{facterbasepath}/facts.d/local.yaml").with_content( |
| 140 | + let(:params) { {'custom_facts' => {'key1' => [ 'val11', 'val12' ], 'key2' => [ 'val21', 'val22']}} } |
| 141 | + it "should lay down #{facterbasepath}/facts.d/local.yaml" do |
| 142 | + should contain_file("#{facterbasepath}/facts.d/local.yaml").with({ |
| 143 | + :path=>"#{facterbasepath}/facts.d/local.yaml", |
| 144 | + :ensure=>'file', |
| 145 | + :owner=>'root', |
| 146 | + :group=>"#{facterbasepath_group}", |
| 147 | + :mode=>'0640' |
| 148 | + }).with_content( |
| 149 | + /facts for my.client.cert/ |
| 150 | + ).with_content( |
| 151 | + /FQDN my.fq.hostname/ |
| 152 | + ).with_content( |
| 153 | + /Environment #{environment}/ |
| 154 | + ).with_content( |
135 | 155 | /---/ |
136 | 156 | ).with_content( |
137 | 157 | /key1:/ |
|
151 | 171 | end |
152 | 172 | end#custom_facts set key values is array |
153 | 173 | context 'when the custom_facts parameter is properly set key values is hash' do |
154 | | - let(:params) {{'custom_facts' => {'key1' => { 'key11' => 'val11' }, 'key2' => { 'key21' => 'val21'}}}} |
155 | | - it 'should iterate through the hash and properly populate the local_facts.yaml file' do |
156 | | - should contain_file("#{facterbasepath}/facts.d/local.yaml").with_content( |
| 174 | + let(:params) { {'custom_facts' => {'key1' => { 'key11' => 'val11' }, 'key2' => { 'key21' => 'val21'}}} } |
| 175 | + it "should lay down #{facterbasepath}/facts.d/local.yaml" do |
| 176 | + should contain_file("#{facterbasepath}/facts.d/local.yaml").with({ |
| 177 | + :path=>"#{facterbasepath}/facts.d/local.yaml", |
| 178 | + :ensure=>'file', |
| 179 | + :owner=>'root', |
| 180 | + :group=>"#{facterbasepath_group}", |
| 181 | + :mode=>'0640' |
| 182 | + }).with_content( |
| 183 | + /facts for my.client.cert/ |
| 184 | + ).with_content( |
| 185 | + /FQDN my.fq.hostname/ |
| 186 | + ).with_content( |
| 187 | + /Environment #{environment}/ |
| 188 | + ).with_content( |
157 | 189 | /---/ |
158 | 190 | ).with_content( |
159 | 191 | /key1:/ |
|
0 commit comments