Browse Source

(#11692) Add unit tests

This commit adds full test coverage for all manifests
in the glance repo.
changes/58/26158/1
Dan Bode 10 years ago
parent
commit
4fa5d3f046
  1. 14
      Rakefile
  2. 83
      spec/classes/glance_api_spec.rb
  3. 67
      spec/classes/glance_registry_spec.rb
  4. 31
      spec/classes/glance_spec.rb
  5. 6
      spec/spec.opts
  6. 11
      spec/spec_helper.rb

14
Rakefile

@ -0,0 +1,14 @@
require 'rake'
task :default => [:spec]
desc "Run all module spec tests (Requires rspec-puppet gem)"
task :spec do
system("rspec spec/**/*_spec.rb")
end
desc "Build package"
task :build do
system("puppet-module build")
end

83
spec/classes/glance_api_spec.rb

@ -0,0 +1,83 @@
require 'spec_helper'
describe 'glance::api' do
let :default_params do
{
:log_verbose => 'false',
:log_debug => 'false',
:default_store => 'file',
:bind_host => '0.0.0.0',
:bind_port => '9292',
:registry_host => '0.0.0.0',
:registry_port => '9191',
:log_file => '/var/log/glance/api.log',
:filesystem_store_datadir => '/var/lib/glance/images/',
:swift_store_auth_address => '127.0.0.1:8080/v1.0/',
:swift_store_user => 'jdoe',
:swift_store_key => 'a86850deb2742ec3cb41518e26aa2d89',
:swift_store_container => 'glance',
:swift_store_create_container_on_put => 'False'
}
end
[{},
{
:log_verbose => 'true',
:log_debug => 'true',
:default_store => 'file',
:bind_host => '127.0.0.1',
:bind_port => '9222',
:registry_host => '127.0.0.1',
:registry_port => '9111',
:log_file => '/var/log/glance-api.log',
:filesystem_store_datadir => '/var/lib/glance-images/',
:swift_store_auth_address => '127.0.0.1:8080/v1.1/',
:swift_store_user => 'dan',
:swift_store_key => 'a',
:swift_store_container => 'other',
:swift_store_create_container_on_put => 'True'
}
].each do |param_set|
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
let :param_hash do
param_set == {} ? default_params : params
end
let :params do
param_set
end
it { should contain_class 'glance' }
it do should contain_service('glance-api').with(
'ensure' => 'running',
'hasstatus' => 'true',
'hasrestart' => 'true',
'subscribe' => 'File[/etc/glance/glance-api.conf]'
) end
it 'should compile the template based on the class parameters' do
content = param_value(subject, 'file', '/etc/glance/glance-api.conf', 'content')
expected_lines = [
"verbose = #{param_hash[:log_verbose]}",
"debug = #{param_hash[:log_debug]}",
"default_store = #{param_hash[:default_store]}",
"bind_host = #{param_hash[:bind_host]}",
"bind_port = #{param_hash[:bind_port]}",
"registry_host = #{param_hash[:registry_host]}",
"registry_port = #{param_hash[:registry_port]}",
"log_file = #{param_hash[:log_file]}",
"filesystem_store_datadir = #{param_hash[:filesystem_store_datadir]}",
"swift_store_auth_address = #{param_hash[:swift_store_auth_address]}",
"swift_store_user = #{param_hash[:swift_store_user]}",
"swift_store_key = #{param_hash[:swift_store_key]}",
"swift_store_container = #{param_hash[:swift_store_container]}",
"swift_store_create_container_on_put = #{param_hash[:swift_store_create_container_on_put]}"
]
(content.split("\n") & expected_lines).should == expected_lines
end
end
end
end

67
spec/classes/glance_registry_spec.rb

@ -0,0 +1,67 @@
require 'spec_helper'
describe 'glance::registry' do
let :default_params do
{
:log_verbose => 'false',
:log_debug => 'false',
:bind_host => '0.0.0.0',
:bind_port => '9191',
:log_file => '/var/log/glance/registry.log',
:sql_connection => 'sqlite:///var/lib/glance/glance.sqlite',
:sql_idle_timeout => '3600'
}
end
[
{},
{
:log_verbose => 'true',
:log_debug => 'true',
:bind_host => '127.0.0.1',
:bind_port => '9111',
:log_file => '/var/log/glance-registry.log',
:sql_connection => 'sqlite:///var/lib/glance.sqlite',
:sql_idle_timeout => '360'
}
].each do |param_set|
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
let :param_hash do
param_set == {} ? default_params : params
end
let :params do
param_set
end
it { should contain_class 'glance::registry' }
it do
should contain_service('glance-registry').with(
'ensure' => 'running',
'enable' => 'true',
'hasstatus' => 'true',
'hasrestart' => 'true',
'subscribe' => 'File[/etc/glance/glance-registry.conf]',
'require' => 'Class[Glance]'
)
end
it 'should compile the template based on the class parameters' do
content = param_value(subject, 'file', '/etc/glance/glance-registry.conf', 'content')
expected_lines = [
"verbose = #{param_hash[:log_verbose]}",
"debug = #{param_hash[:log_debug]}",
"bind_host = #{param_hash[:bind_host]}",
"bind_port = #{param_hash[:bind_port]}",
"log_file = #{param_hash[:log_file]}",
"sql_connection = #{param_hash[:sql_connection]}",
"sql_idle_timeout = #{param_hash[:sql_idle_timeout]}"
]
(content.split("\n") & expected_lines).should == expected_lines
end
end
end
end

31
spec/classes/glance_spec.rb

@ -0,0 +1,31 @@
require 'spec_helper'
describe 'glance' do
let :default_params do
{:package_ensure => 'present'}
end
[
{},
{:package_ensure => 'latest'}
].each do |param_set|
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
let :param_hash do
param_set == {} ? default_params : params
end
let :params do param_set end
it { should contain_package('glance').with_ensure(param_hash[:package_ensure]) }
it { should contain_file('/etc/glance/').with(
'ensure' => 'directory',
'owner' => 'glance',
'mode' => '770',
'require' => 'Package[glance]'
)}
end
end
end

6
spec/spec.opts

@ -0,0 +1,6 @@
--format
s
--colour
--loadby
mtime
--backtrace

11
spec/spec_helper.rb

@ -0,0 +1,11 @@
require 'puppet'
require 'rubygems'
require 'rspec-puppet'
def param_value(subject, type, title, param)
subject.resource(type, title).send(:parameters)[param.to_sym]
end
RSpec.configure do |c|
c.module_path = File.join(File.dirname(__FILE__), '../../')
end
Loading…
Cancel
Save