mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 10:26:28 +00:00
Switch to puppetlabs/apt
(imported from commit b2f581280dc7877051ef79d86eac671bfd455ace)
This commit is contained in:
37
puppet/stdlib/spec/functions/defined_with_params_spec.rb
Normal file
37
puppet/stdlib/spec/functions/defined_with_params_spec.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
#! /usr/bin/env ruby -S rspec
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rspec-puppet'
|
||||
describe 'defined_with_params' do
|
||||
describe 'when a resource is not specified' do
|
||||
it { should run.with_params().and_raise_error(ArgumentError) }
|
||||
end
|
||||
describe 'when compared against a resource with no attributes' do
|
||||
let :pre_condition do
|
||||
'user { "dan": }'
|
||||
end
|
||||
it do
|
||||
should run.with_params('User[dan]', {}).and_return(true)
|
||||
should run.with_params('User[bob]', {}).and_return(false)
|
||||
should run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when compared against a resource with attributes' do
|
||||
let :pre_condition do
|
||||
'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
|
||||
end
|
||||
it do
|
||||
should run.with_params('User[dan]', {}).and_return(true)
|
||||
should run.with_params('User[dan]', '').and_return(true)
|
||||
should run.with_params('User[dan]', {'ensure' => 'present'}
|
||||
).and_return(true)
|
||||
should run.with_params('User[dan]',
|
||||
{'ensure' => 'present', 'managehome' => false}
|
||||
).and_return(true)
|
||||
should run.with_params('User[dan]',
|
||||
{'ensure' => 'absent', 'managehome' => false}
|
||||
).and_return(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
42
puppet/stdlib/spec/functions/ensure_packages_spec.rb
Normal file
42
puppet/stdlib/spec/functions/ensure_packages_spec.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
#! /usr/bin/env ruby
|
||||
|
||||
require 'spec_helper'
|
||||
require 'rspec-puppet'
|
||||
|
||||
describe 'ensure_packages' do
|
||||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
||||
|
||||
describe 'argument handling' do
|
||||
it 'fails with no arguments' do
|
||||
should run.with_params().and_raise_error(Puppet::ParseError)
|
||||
end
|
||||
it 'requires an array' do
|
||||
lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error
|
||||
end
|
||||
it 'fails when given a string' do
|
||||
should run.with_params('foo').and_raise_error(Puppet::ParseError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'given a catalog containing Package[puppet]{ensure => absent}' do
|
||||
let :pre_condition do
|
||||
'package { puppet: ensure => absent }'
|
||||
end
|
||||
|
||||
# NOTE: should run.with_params has the side effect of making the compiler
|
||||
# available to the test harness.
|
||||
it 'has no effect on Package[puppet]' do
|
||||
should run.with_params(['puppet'])
|
||||
rsrc = compiler.catalog.resource('Package[puppet]')
|
||||
rsrc.to_hash.should == {:ensure => "absent"}
|
||||
end
|
||||
end
|
||||
|
||||
context 'given a clean catalog' do
|
||||
it 'declares package resources with ensure => present' do
|
||||
should run.with_params(['facter'])
|
||||
rsrc = compiler.catalog.resource('Package[facter]')
|
||||
rsrc.to_hash.should == {:name => "facter", :ensure => "present"}
|
||||
end
|
||||
end
|
||||
end
|
||||
64
puppet/stdlib/spec/functions/ensure_resource_spec.rb
Normal file
64
puppet/stdlib/spec/functions/ensure_resource_spec.rb
Normal file
@@ -0,0 +1,64 @@
|
||||
#! /usr/bin/env ruby -S rspec
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rspec-puppet'
|
||||
describe 'ensure_resource' do
|
||||
describe 'when a type or title is not specified' do
|
||||
it { should run.with_params().and_raise_error(ArgumentError) }
|
||||
it { should run.with_params(['type']).and_raise_error(ArgumentError) }
|
||||
end
|
||||
|
||||
describe 'when compared against a resource with no attributes' do
|
||||
let :pre_condition do
|
||||
'user { "dan": }'
|
||||
end
|
||||
it "should contain the the ensured resources" do
|
||||
subject.should run.with_params('user', 'dan', {})
|
||||
compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when compared against a resource with attributes' do
|
||||
let :pre_condition do
|
||||
'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
|
||||
end
|
||||
# these first three should not fail
|
||||
it { should run.with_params('User', 'dan', {}) }
|
||||
it { should run.with_params('User', 'dan', '') }
|
||||
it { should run.with_params('User', 'dan', {'ensure' => 'present'}) }
|
||||
it { should run.with_params('User', 'dan', {'ensure' => 'present', 'managehome' => false}) }
|
||||
# test that this fails
|
||||
it { should run.with_params('User', 'dan', {'ensure' => 'absent', 'managehome' => false}).and_raise_error(Puppet::Error) }
|
||||
end
|
||||
|
||||
describe 'when an array of new resources are passed in' do
|
||||
it "should contain the ensured resources" do
|
||||
subject.should run.with_params('User', ['dan', 'alex'], {})
|
||||
compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
|
||||
compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when an array of existing resources is compared against existing resources' do
|
||||
let :pre_condition do
|
||||
'user { "dan": ensure => present; "alex": ensure => present }'
|
||||
end
|
||||
it "should return the existing resources" do
|
||||
subject.should run.with_params('User', ['dan', 'alex'], {})
|
||||
compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
|
||||
compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when compared against existing resources with attributes' do
|
||||
let :pre_condition do
|
||||
'user { "dan": ensure => present; "alex": ensure => present }'
|
||||
end
|
||||
# These should not fail
|
||||
it { should run.with_params('User', ['dan', 'alex'], {}) }
|
||||
it { should run.with_params('User', ['dan', 'alex'], '') }
|
||||
it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'present'}) }
|
||||
# This should fail
|
||||
it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'absent'}).and_raise_error(Puppet::Error) }
|
||||
end
|
||||
end
|
||||
34
puppet/stdlib/spec/functions/getparam_spec.rb
Normal file
34
puppet/stdlib/spec/functions/getparam_spec.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
#! /usr/bin/env ruby -S rspec
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rspec-puppet'
|
||||
describe 'getparam' do
|
||||
describe 'when a resource is not specified' do
|
||||
it do
|
||||
should run.with_params().and_raise_error(ArgumentError)
|
||||
should run.with_params('User[dan]').and_raise_error(ArgumentError)
|
||||
should run.with_params('User[dan]', {}).and_raise_error(ArgumentError)
|
||||
should run.with_params('User[dan]', '').and_return('')
|
||||
end
|
||||
end
|
||||
describe 'when compared against a resource with no params' do
|
||||
let :pre_condition do
|
||||
'user { "dan": }'
|
||||
end
|
||||
it do
|
||||
should run.with_params('User[dan]', 'shell').and_return('')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when compared against a resource with params' do
|
||||
let :pre_condition do
|
||||
'user { "dan": ensure => present, shell => "/bin/sh", managehome => false}'
|
||||
end
|
||||
it do
|
||||
should run.with_params('User[dan]', 'shell').and_return('/bin/sh')
|
||||
should run.with_params('User[dan]', '').and_return('')
|
||||
should run.with_params('User[dan]', 'ensure').and_return('present')
|
||||
should run.with_params('User[dan]', 'managehome').and_return(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user