| 1 |
# Copyright (C) 2013 Mirantis Inc. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
# |
| 15 |
# Author: Andrew Woodward <xarses> |
| 16 |
|
| 17 |
# This is aparently one of the few ways to do this load |
| 18 |
# see https://github.com/openstack/puppet-nova/blob/master/spec/unit/provider/nova_config/ini_setting_spec.rb |
| 19 |
$LOAD_PATH.push( |
| 20 |
File.join( |
| 21 |
File.dirname(__FILE__), |
| 22 |
'..', |
| 23 |
'..', |
| 24 |
'..', |
| 25 |
'fixtures', |
| 26 |
'modules', |
| 27 |
'inifile', |
| 28 |
'lib') |
| 29 |
) |
| 30 |
|
| 31 |
require 'spec_helper' |
| 32 |
require 'puppet' |
| 33 |
|
| 34 |
provider_class = Puppet::Type.type(:ceph_config).provider(:ini_setting) |
| 35 |
|
| 36 |
describe provider_class do |
| 37 |
include PuppetlabsSpec::Files |
| 38 |
|
| 39 |
let(:tmpfile) { tmpfilename("ceph_config_test") } |
| 40 |
|
| 41 |
let(:params) { { |
| 42 |
:path => tmpfile, |
| 43 |
} } |
| 44 |
|
| 45 |
def validate(expected) |
| 46 |
expect(File.read(tmpfile)).to eq(expected) |
| 47 |
end |
| 48 |
|
| 49 |
it 'should create keys = value and ensure space around equals' do |
| 50 |
resource = Puppet::Type::Ceph_config.new(params.merge( |
| 51 |
:name => 'global/ceph_is_foo', :value => 'bar')) |
| 52 |
provider = provider_class.new(resource) |
| 53 |
expect(provider.exists?).to be_falsey |
| 54 |
provider.create |
| 55 |
expect(provider.exists?).to be_truthy |
| 56 |
validate(<<-EOS |
| 57 |
|
| 58 |
[global] |
| 59 |
ceph_is_foo = bar |
| 60 |
EOS |
| 61 |
) |
| 62 |
end |
| 63 |
|
| 64 |
it 'should default to file_path if param path is not passed' do |
| 65 |
resource = Puppet::Type::Ceph_config.new( |
| 66 |
:name => 'global/ceph_is_foo', :value => 'bar') |
| 67 |
provider = provider_class.new(resource) |
| 68 |
expect(provider.file_path).to eq('/etc/ceph/ceph.conf') |
| 69 |
end |
| 70 |
|
| 71 |
end |