Browse Source

Merge pull request #10 from bodepd/11692_manifest_rspec_tests

(#11692) Add unit tests
tags/0.1.0
Dan Bode 7 years ago
parent
commit
c8fe8b083f
6 changed files with 212 additions and 0 deletions
  1. 14
    0
      Rakefile
  2. 83
    0
      spec/classes/glance_api_spec.rb
  3. 67
    0
      spec/classes/glance_registry_spec.rb
  4. 31
    0
      spec/classes/glance_spec.rb
  5. 6
    0
      spec/spec.opts
  6. 11
    0
      spec/spec_helper.rb

+ 14
- 0
Rakefile View File

@@ -0,0 +1,14 @@
1
+require 'rake'
2
+
3
+task :default => [:spec]
4
+
5
+desc "Run all module spec tests (Requires rspec-puppet gem)"
6
+task :spec do
7
+  system("rspec spec/**/*_spec.rb")
8
+end
9
+
10
+desc "Build package"
11
+task :build do
12
+  system("puppet-module build")
13
+end
14
+

+ 83
- 0
spec/classes/glance_api_spec.rb View File

@@ -0,0 +1,83 @@
1
+require 'spec_helper'
2
+
3
+describe 'glance::api' do
4
+
5
+  let :default_params do
6
+    {
7
+      :log_verbose => 'false',
8
+      :log_debug => 'false',
9
+      :default_store => 'file',
10
+      :bind_host => '0.0.0.0',
11
+      :bind_port => '9292',
12
+      :registry_host => '0.0.0.0',
13
+      :registry_port => '9191',
14
+      :log_file => '/var/log/glance/api.log',
15
+      :filesystem_store_datadir => '/var/lib/glance/images/',
16
+      :swift_store_auth_address => '127.0.0.1:8080/v1.0/',
17
+      :swift_store_user => 'jdoe',
18
+      :swift_store_key => 'a86850deb2742ec3cb41518e26aa2d89',
19
+      :swift_store_container => 'glance',
20
+      :swift_store_create_container_on_put => 'False'
21
+    }
22
+  end
23
+
24
+  [{},
25
+   {
26
+      :log_verbose => 'true',
27
+      :log_debug => 'true',
28
+      :default_store => 'file',
29
+      :bind_host => '127.0.0.1',
30
+      :bind_port => '9222',
31
+      :registry_host => '127.0.0.1',
32
+      :registry_port => '9111',
33
+      :log_file => '/var/log/glance-api.log',
34
+      :filesystem_store_datadir => '/var/lib/glance-images/',
35
+      :swift_store_auth_address => '127.0.0.1:8080/v1.1/',
36
+      :swift_store_user => 'dan',
37
+      :swift_store_key => 'a',
38
+      :swift_store_container => 'other',
39
+      :swift_store_create_container_on_put => 'True'
40
+    }
41
+  ].each do |param_set|
42
+
43
+    describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
44
+      let :param_hash do
45
+        param_set == {} ? default_params : params
46
+      end
47
+
48
+      let :params do
49
+        param_set
50
+      end
51
+
52
+      it { should contain_class 'glance' }
53
+
54
+      it do should contain_service('glance-api').with(
55
+        'ensure'     => 'running',
56
+        'hasstatus'  => 'true',
57
+        'hasrestart' => 'true',
58
+        'subscribe'  => 'File[/etc/glance/glance-api.conf]'
59
+      ) end
60
+
61
+      it 'should compile the template based on the class parameters' do
62
+        content = param_value(subject, 'file', '/etc/glance/glance-api.conf', 'content')
63
+        expected_lines = [
64
+          "verbose = #{param_hash[:log_verbose]}",
65
+          "debug = #{param_hash[:log_debug]}",
66
+          "default_store = #{param_hash[:default_store]}",
67
+          "bind_host = #{param_hash[:bind_host]}",
68
+          "bind_port = #{param_hash[:bind_port]}",
69
+          "registry_host = #{param_hash[:registry_host]}",
70
+          "registry_port = #{param_hash[:registry_port]}",
71
+          "log_file = #{param_hash[:log_file]}",
72
+          "filesystem_store_datadir = #{param_hash[:filesystem_store_datadir]}",
73
+          "swift_store_auth_address = #{param_hash[:swift_store_auth_address]}",
74
+          "swift_store_user = #{param_hash[:swift_store_user]}",
75
+          "swift_store_key = #{param_hash[:swift_store_key]}",
76
+          "swift_store_container = #{param_hash[:swift_store_container]}",
77
+          "swift_store_create_container_on_put = #{param_hash[:swift_store_create_container_on_put]}"
78
+        ]
79
+        (content.split("\n") & expected_lines).should == expected_lines
80
+      end
81
+    end
82
+  end
83
+end

+ 67
- 0
spec/classes/glance_registry_spec.rb View File

@@ -0,0 +1,67 @@
1
+require 'spec_helper'
2
+
3
+describe 'glance::registry' do
4
+
5
+  let :default_params do
6
+    {
7
+      :log_verbose => 'false',
8
+      :log_debug => 'false',
9
+      :bind_host => '0.0.0.0',
10
+      :bind_port => '9191',
11
+      :log_file => '/var/log/glance/registry.log',
12
+      :sql_connection => 'sqlite:///var/lib/glance/glance.sqlite',
13
+      :sql_idle_timeout => '3600'
14
+    }
15
+  end
16
+
17
+  [
18
+    {},
19
+    {
20
+      :log_verbose => 'true',
21
+      :log_debug => 'true',
22
+      :bind_host => '127.0.0.1',
23
+      :bind_port => '9111',
24
+      :log_file => '/var/log/glance-registry.log',
25
+      :sql_connection => 'sqlite:///var/lib/glance.sqlite',
26
+      :sql_idle_timeout => '360'
27
+    }
28
+  ].each do |param_set|
29
+
30
+    describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
31
+      let :param_hash do
32
+        param_set == {} ? default_params : params
33
+      end
34
+
35
+      let :params do
36
+        param_set
37
+      end
38
+
39
+      it { should contain_class 'glance::registry' }
40
+
41
+      it do
42
+        should contain_service('glance-registry').with(
43
+          'ensure' => 'running',
44
+          'enable' => 'true',
45
+          'hasstatus' => 'true',
46
+          'hasrestart' => 'true',
47
+          'subscribe' => 'File[/etc/glance/glance-registry.conf]',
48
+          'require' => 'Class[Glance]'
49
+        )
50
+      end
51
+
52
+      it 'should compile the template based on the class parameters' do
53
+        content = param_value(subject, 'file', '/etc/glance/glance-registry.conf', 'content')
54
+        expected_lines = [
55
+          "verbose = #{param_hash[:log_verbose]}",
56
+          "debug = #{param_hash[:log_debug]}",
57
+          "bind_host = #{param_hash[:bind_host]}",
58
+          "bind_port = #{param_hash[:bind_port]}",
59
+          "log_file = #{param_hash[:log_file]}",
60
+          "sql_connection = #{param_hash[:sql_connection]}",
61
+          "sql_idle_timeout = #{param_hash[:sql_idle_timeout]}"
62
+        ]
63
+        (content.split("\n") & expected_lines).should == expected_lines
64
+      end
65
+    end
66
+  end
67
+end

+ 31
- 0
spec/classes/glance_spec.rb View File

@@ -0,0 +1,31 @@
1
+require 'spec_helper'
2
+
3
+describe 'glance' do
4
+
5
+  let :default_params do
6
+    {:package_ensure => 'present'}
7
+  end
8
+
9
+  [
10
+    {},
11
+    {:package_ensure => 'latest'}
12
+  ].each do |param_set|
13
+
14
+    describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
15
+
16
+      let :param_hash do
17
+        param_set == {} ? default_params : params
18
+      end
19
+
20
+      let :params do param_set end
21
+
22
+      it { should contain_package('glance').with_ensure(param_hash[:package_ensure]) }
23
+      it { should contain_file('/etc/glance/').with(
24
+        'ensure' => 'directory',
25
+        'owner' => 'glance',
26
+        'mode' => '770',
27
+        'require' => 'Package[glance]'
28
+      )}
29
+    end
30
+  end
31
+end

+ 6
- 0
spec/spec.opts View File

@@ -0,0 +1,6 @@
1
+--format
2
+s
3
+--colour
4
+--loadby
5
+mtime
6
+--backtrace

+ 11
- 0
spec/spec_helper.rb View File

@@ -0,0 +1,11 @@
1
+require 'puppet'
2
+require 'rubygems'
3
+require 'rspec-puppet'
4
+
5
+def param_value(subject, type, title, param)
6
+  subject.resource(type, title).send(:parameters)[param.to_sym]
7
+end
8
+
9
+RSpec.configure do |c|
10
+  c.module_path = File.join(File.dirname(__FILE__), '../../')
11
+end

Loading…
Cancel
Save