diff options
author | Raphaël Pinson <raphael.pinson@camptocamp.com> | 2013-03-18 03:31:49 -0700 |
---|---|---|
committer | Raphaël Pinson <raphael.pinson@camptocamp.com> | 2013-03-18 03:31:49 -0700 |
commit | 0aa01df4742ac55385e1eb8a0421e2cd1d7ce14f (patch) | |
tree | 37ee4482a666eac29372efe2e788ade2b30d78f6 /spec | |
parent | 8df48d003efcf055b27593091fb981c5c193bc6a (diff) | |
parent | a7c41208cc4a6e9b543487bf606b551307fdc05a (diff) |
Merge pull request #23 from raphink/dev/reorganize
Refactor the module
Diffstat (limited to 'spec')
-rw-r--r-- | spec/.rspec (renamed from spec/spec.opts) | 0 | ||||
-rw-r--r-- | spec/defines/augeas_lens_spec.rb | 68 | ||||
-rw-r--r-- | spec/fixtures/manifests/site.pp | 23 | ||||
-rw-r--r-- | spec/hosts/simple_debian_squeeze_spec.rb | 91 | ||||
-rw-r--r-- | spec/hosts/simple_debian_wheezy_spec.rb | 91 | ||||
-rw-r--r-- | spec/hosts/simple_redhat_spec.rb | 82 | ||||
-rw-r--r-- | spec/hosts/with_lens_noaugeas_spec.rb | 9 | ||||
-rw-r--r-- | spec/hosts/with_lens_spec.rb | 56 | ||||
-rw-r--r-- | spec/hosts/wrong_os_spec.rb | 11 | ||||
-rw-r--r-- | spec/spec_helper.rb | 34 |
10 files changed, 441 insertions, 24 deletions
diff --git a/spec/spec.opts b/spec/.rspec index 91cd642..91cd642 100644 --- a/spec/spec.opts +++ b/spec/.rspec diff --git a/spec/defines/augeas_lens_spec.rb b/spec/defines/augeas_lens_spec.rb new file mode 100644 index 0000000..57d30b6 --- /dev/null +++ b/spec/defines/augeas_lens_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +describe 'augeas::lens' do + let (:title) { 'foo' } + let (:facts) { { + :osfamily => 'RedHat', + } } + context 'when no lens_source is passed' do + it 'should error' do + expect { + should contain_file('/usr/share/augeas/lenses/foo.aug') + }.to raise_error(Puppet::Error, /Must pass lens_source/) + end + end + + context 'when lens_source is passed' do + let (:params) { { + :lens_source => '/tmp/foo.aug', + } } + + it { should contain_file('/usr/share/augeas/lenses/foo.aug') } + it { should contain_exec('Typecheck lens foo') } + it { should_not contain_file('/usr/share/augeas/lenses/tests/test_foo.aug') } + it { should_not contain_exec('Test lens foo') } + end + + context 'when lens_source and test_source are passed' do + let (:params) { { + :lens_source => '/tmp/foo.aug', + :test_source => '/tmp/test_foo.aug', + } } + + it { should contain_file('/usr/share/augeas/lenses/foo.aug') } + it { should contain_exec('Typecheck lens foo') } + it { should contain_file('/usr/share/augeas/lenses/tests/test_foo.aug') } + it { should contain_exec('Test lens foo') } + end + + context 'when stock_since is passed and augeas is older' do + let (:params) { { + :lens_source => '/tmp/foo.aug', + :stock_since => '1.2.3', + } } + + let (:facts) { { + :osfamily => 'RedHat', + :augeasversion => '1.0.0', + } } + + it { should contain_file('/usr/share/augeas/lenses/foo.aug') } + it { should contain_exec('Typecheck lens foo') } + end + + context 'when stock_since is passed and augeas is newer' do + let (:params) { { + :lens_source => '/tmp/foo.aug', + :stock_since => '1.2.3', + } } + + let (:facts) { { + :osfamily => 'RedHat', + :augeasversion => '1.5.0', + } } + + it { should_not contain_file('/usr/share/augeas/lenses/foo.aug') } + it { should_not contain_exec('Typecheck lens foo') } + end +end diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp new file mode 100644 index 0000000..fb803e5 --- /dev/null +++ b/spec/fixtures/manifests/site.pp @@ -0,0 +1,23 @@ +# simple_* and wrong_os tests +node default { + class { '::augeas': + version => $::augeas_version, + ruby_version => $::augeas_ruby_version, + lens_dir => $::augeas_lens_dir, + } +} + +node 'with_lens_noaugeas' { + ::augeas::lens { 'foo': + lens_source => '/tmp/foo.aug', + } +} + +node 'with_lens' { + include ::augeas + ::augeas::lens { 'foo': + lens_source => $::augeas_lens_source, + test_source => $::augeas_test_source, + stock_since => $::augeas_stock_since, + } +} diff --git a/spec/hosts/simple_debian_squeeze_spec.rb b/spec/hosts/simple_debian_squeeze_spec.rb new file mode 100644 index 0000000..4b41105 --- /dev/null +++ b/spec/hosts/simple_debian_squeeze_spec.rb @@ -0,0 +1,91 @@ +require 'spec_helper' + +describe 'simple_debian_squeeze' do + let (:facts) { { + :osfamily => 'Debian', + :lsbdistcodename => 'squeeze', + } } + + context 'when versions are not specified' do + it { should contain_package('libaugeas0').with( + :ensure => 'present' + ) } + it { should contain_package('augeas-tools').with( + :ensure => 'present' + ) } + it { should contain_package('augeas-lenses').with( + :ensure => 'present' + ) } + it { should contain_package('ruby-augeas').with( + :ensure => 'present', + :name => 'libaugeas-ruby1.8' + ) } + end + + context 'when versions are specified' do + let (:facts) { { + :osfamily => 'Debian', + :lsbdistcodename => 'squeeze', + :augeas_version => '1.2.3', + :augeas_ruby_version => '3.2.1', + } } + + it { should contain_package('libaugeas0').with( + :ensure => '1.2.3' + ) } + it { should contain_package('augeas-tools').with( + :ensure => '1.2.3' + ) } + it { should contain_package('augeas-lenses').with( + :ensure => '1.2.3' + ) } + it { should contain_package('ruby-augeas').with( + :ensure => '3.2.1', + :name => 'libaugeas-ruby1.8' + ) } + end + + context 'with standard lens_dir' do + it { should contain_file('/usr/share/augeas/lenses').with( + :ensure => 'directory', + :purge => 'true', + :force => 'true', + :recurse => 'true', + :recurselimit => 1 + ) } + it { should contain_file('/usr/share/augeas/lenses/dist').with( + :ensure => 'directory', + :purge => 'false' + ) } + it { should contain_file('/usr/share/augeas/lenses/tests').with( + :ensure => 'directory', + :purge => 'true', + :force => 'true' + ).without(:recurse) } + end + + context 'with a non standard lens_dir' do + let (:facts) { { + :osfamily => 'Debian', + :lsbdistcodename => 'squeeze', + :augeas_lens_dir => '/opt/augeas/lenses' + } } + + it { should contain_file('/opt/augeas/lenses').with( + :ensure => 'directory', + :purge => 'true', + :force => 'true', + :recurse => 'true', + :recurselimit => 1 + ) } + it { should contain_file('/opt/augeas/lenses/dist').with( + :ensure => 'directory', + :purge => 'false' + ) } + it { should contain_file('/opt/augeas/lenses/tests').with( + :ensure => 'directory', + :purge => 'true', + :force => 'true' + ).without(:recurse) } + end +end diff --git a/spec/hosts/simple_debian_wheezy_spec.rb b/spec/hosts/simple_debian_wheezy_spec.rb new file mode 100644 index 0000000..23c0d1d --- /dev/null +++ b/spec/hosts/simple_debian_wheezy_spec.rb @@ -0,0 +1,91 @@ +require 'spec_helper' + +describe 'simple_debian_squeeze' do + let (:facts) { { + :osfamily => 'Debian', + :lsbdistcodename => 'wheezy', + } } + + context 'when versions are not specified' do + it { should contain_package('libaugeas0').with( + :ensure => 'present' + ) } + it { should contain_package('augeas-tools').with( + :ensure => 'present' + ) } + it { should contain_package('augeas-lenses').with( + :ensure => 'present' + ) } + it { should contain_package('ruby-augeas').with( + :ensure => 'present', + :name => 'libaugeas-ruby1.9.1' + ) } + end + + context 'when versions are specified' do + let (:facts) { { + :osfamily => 'Debian', + :lsbdistcodename => 'wheezy', + :augeas_version => '1.2.3', + :augeas_ruby_version => '3.2.1', + } } + + it { should contain_package('libaugeas0').with( + :ensure => '1.2.3' + ) } + it { should contain_package('augeas-tools').with( + :ensure => '1.2.3' + ) } + it { should contain_package('augeas-lenses').with( + :ensure => '1.2.3' + ) } + it { should contain_package('ruby-augeas').with( + :ensure => '3.2.1', + :name => 'libaugeas-ruby1.9.1' + ) } + end + + context 'with standard lens_dir' do + it { should contain_file('/usr/share/augeas/lenses').with( + :ensure => 'directory', + :purge => 'true', + :force => 'true', + :recurse => 'true', + :recurselimit => 1 + ) } + it { should contain_file('/usr/share/augeas/lenses/dist').with( + :ensure => 'directory', + :purge => 'false' + ) } + it { should contain_file('/usr/share/augeas/lenses/tests').with( + :ensure => 'directory', + :purge => 'true', + :force => 'true' + ).without(:recurse) } + end + + context 'with a non standard lens_dir' do + let (:facts) { { + :osfamily => 'Debian', + :lsbdistcodename => 'wheezy', + :augeas_lens_dir => '/opt/augeas/lenses' + } } + + it { should contain_file('/opt/augeas/lenses').with( + :ensure => 'directory', + :purge => 'true', + :force => 'true', + :recurse => 'true', + :recurselimit => 1 + ) } + it { should contain_file('/opt/augeas/lenses/dist').with( + :ensure => 'directory', + :purge => 'false' + ) } + it { should contain_file('/opt/augeas/lenses/tests').with( + :ensure => 'directory', + :purge => 'true', + :force => 'true' + ).without(:recurse) } + end +end diff --git a/spec/hosts/simple_redhat_spec.rb b/spec/hosts/simple_redhat_spec.rb new file mode 100644 index 0000000..5045377 --- /dev/null +++ b/spec/hosts/simple_redhat_spec.rb @@ -0,0 +1,82 @@ +require 'spec_helper' + +describe 'simple_redhat' do + let (:facts) { { + :osfamily => 'RedHat', + } } + + context 'when versions are not specified' do + it { should contain_package('augeas').with( + :ensure => 'present' + ) } + it { should contain_package('augeas-libs').with( + :ensure => 'present' + ) } + it { should contain_package('ruby-augeas').with( + :ensure => 'present', + :name => 'ruby-augeas' + ) } + end + + context 'when versions are specified' do + let (:facts) { { + :osfamily => 'RedHat', + :augeas_version => '1.2.3', + :augeas_ruby_version => '3.2.1', + } } + + it { should contain_package('augeas').with( + :ensure => '1.2.3' + ) } + it { should contain_package('augeas-libs').with( + :ensure => '1.2.3' + ) } + it { should contain_package('ruby-augeas').with( + :ensure => '3.2.1', + :name => 'ruby-augeas' + ) } + end + + context 'with standard lens_dir' do + it { should contain_file('/usr/share/augeas/lenses').with( + :ensure => 'directory', + :purge => 'true', + :force => 'true', + :recurse => 'true', + :recurselimit => 1 + ) } + it { should contain_file('/usr/share/augeas/lenses/dist').with( + :ensure => 'directory', + :purge => 'false' + ) } + it { should contain_file('/usr/share/augeas/lenses/tests').with( + :ensure => 'directory', + :purge => 'true', + :force => 'true' + ).without(:recurse) } + end + + context 'with a non standard lens_dir' do + let (:facts) { { + :osfamily => 'RedHat', + :augeas_lens_dir => '/opt/augeas/lenses' + } } + + it { should contain_file('/opt/augeas/lenses').with( + :ensure => 'directory', + :purge => 'true', + :force => 'true', + :recurse => 'true', + :recurselimit => 1 + ) } + it { should contain_file('/opt/augeas/lenses/dist').with( + :ensure => 'directory', + :purge => 'false' + ) } + it { should contain_file('/opt/augeas/lenses/tests').with( + :ensure => 'directory', + :purge => 'true', + :force => 'true' + ).without(:recurse) } + end +end diff --git a/spec/hosts/with_lens_noaugeas_spec.rb b/spec/hosts/with_lens_noaugeas_spec.rb new file mode 100644 index 0000000..b26563b --- /dev/null +++ b/spec/hosts/with_lens_noaugeas_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe 'with_lens_noaugeas' do + it 'should error' do + expect { + should contain_file('/usr/share/augeas/lenses/foo.aug') + }.to raise_error(Puppet::Error, /You must declare the augeas class/) + end +end diff --git a/spec/hosts/with_lens_spec.rb b/spec/hosts/with_lens_spec.rb new file mode 100644 index 0000000..d7a5249 --- /dev/null +++ b/spec/hosts/with_lens_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe 'with_lens' do + let (:facts) { { + :osfamily => 'RedHat', + } } + + context 'when lens_source is passed' do + let (:facts) { { + :osfamily => 'RedHat', + :augeas_lens_source => '/tmp/foo.aug', + } } + + it { should contain_file('/usr/share/augeas/lenses/foo.aug') } + it { should contain_exec('Typecheck lens foo') } + it { should_not contain_file('/usr/share/augeas/lenses/tests/test_foo.aug') } + it { should_not contain_exec('Test lens foo') } + end + + context 'when lens_source and test_source are passed' do + let (:facts) { { + :osfamily => 'RedHat', + :augeas_lens_source => '/tmp/foo.aug', + :augeas_test_source => '/tmp/test_foo.aug', + } } + + it { should contain_file('/usr/share/augeas/lenses/foo.aug') } + it { should contain_exec('Typecheck lens foo') } + it { should contain_file('/usr/share/augeas/lenses/tests/test_foo.aug') } + it { should contain_exec('Test lens foo') } + end + + context 'when stock_since is passed and augeas is older' do + let (:facts) { { + :osfamily => 'RedHat', + :augeas_lens_source => '/tmp/foo.aug', + :augeas_stock_since => '1.2.3', + :augeasversion => '1.0.0', + } } + + it { should contain_file('/usr/share/augeas/lenses/foo.aug') } + it { should contain_exec('Typecheck lens foo') } + end + + context 'when stock_since is passed and augeas is newer' do + let (:facts) { { + :osfamily => 'RedHat', + :augeas_lens_source => '/tmp/foo.aug', + :augeas_stock_since => '1.2.3', + :augeasversion => '1.5.0', + } } + + it { should_not contain_file('/usr/share/augeas/lenses/foo.aug') } + it { should_not contain_exec('Typecheck lens foo') } + end +end diff --git a/spec/hosts/wrong_os_spec.rb b/spec/hosts/wrong_os_spec.rb new file mode 100644 index 0000000..5704ded --- /dev/null +++ b/spec/hosts/wrong_os_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe 'wrong_os' do + let (:facts) { { + :osfamily => 'MS-DOS' + } } + + it 'should fail' do + expect { should contain_package('ruby-augeas') }.to raise_error(Puppet::Error, /Unsupported OS family/) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 931d35c..5e28e1f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,28 +1,14 @@ -dir = File.expand_path(File.dirname(__FILE__)) -$LOAD_PATH.unshift File.join(dir, 'lib') - -# Don't want puppet getting the command line arguments for rake or autotest -ARGV.clear - -require 'puppet' -require 'facter' require 'mocha' -gem 'rspec', '>=2.0.0' -require 'rspec/expectations' +require 'rspec-puppet' -require 'puppetlabs_spec_helper/module_spec_helper' +fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) -RSpec.configure do |config| - # FIXME REVISIT - We may want to delegate to Facter like we do in - # Puppet::PuppetSpecInitializer.initialize_via_testhelper(config) because - # this behavior is a duplication of the spec_helper in Facter. - config.before :each do - # Ensure that we don't accidentally cache facts and environment between - # test cases. This requires each example group to explicitly load the - # facts being exercised with something like - # Facter.collection.loader.load(:ipaddress) - Facter::Util::Loader.any_instance.stubs(:load_all) - Facter.clear - Facter.clear_messages - end +RSpec.configure do |c| + c.module_path = File.join(fixture_path, 'modules') + c.manifest_dir = File.join(fixture_path, 'manifests') end + + +dir = File.expand_path(File.dirname(__FILE__)) +$LOAD_PATH.unshift File.join(dir, 'lib') + |