|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'collectd::plugin::openvpn', :type => :class do |
| 4 | + |
| 5 | + ###################################################################### |
| 6 | + # Default param validation, compilation succeeds |
| 7 | + |
| 8 | + context ':ensure => present, default params' do |
| 9 | + let :facts do |
| 10 | + { :osfamily => 'RedHat', |
| 11 | + :collectd_version => '5.4', |
| 12 | + } |
| 13 | + end |
| 14 | + |
| 15 | + it 'Will create /etc/collectd.d/10-openvpn.conf' do |
| 16 | + should contain_file('openvpn.load').with({ |
| 17 | + :ensure => 'present', |
| 18 | + :path => '/etc/collectd.d/10-openvpn.conf', |
| 19 | + :content => "#\ Generated by Puppet\n<LoadPlugin openvpn>\n Globals false\n</LoadPlugin>\n\n<Plugin openvpn>\n StatusFile \"/etc/openvpn/openvpn-status.log\"\n ImprovedNamingSchema false\n CollectCompression true\n CollectIndividualUsers true\n CollectUserCount false\n</Plugin>\n\n", |
| 20 | + }) |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + context ':statusfile param is an array' do |
| 25 | + let :facts do |
| 26 | + { :osfamily => 'RedHat', |
| 27 | + :collectd_version => '5.4', |
| 28 | + } |
| 29 | + end |
| 30 | + |
| 31 | + let :params do |
| 32 | + {:statusfile => ['/etc/openvpn/openvpn-tcp.status', '/etc/openvpn/openvpn-udp.status']} |
| 33 | + end |
| 34 | + |
| 35 | + it 'Will create /etc/collectd.d/10-openvpn.conf with two :statusfile params' do |
| 36 | + should contain_file('openvpn.load').with({ |
| 37 | + :ensure => 'present', |
| 38 | + :path => '/etc/collectd.d/10-openvpn.conf', |
| 39 | + :content => "#\ Generated by Puppet\n<LoadPlugin openvpn>\n Globals false\n</LoadPlugin>\n\n<Plugin openvpn>\n StatusFile \"/etc/openvpn/openvpn-tcp.status\"\n StatusFile \"/etc/openvpn/openvpn-udp.status\"\n ImprovedNamingSchema false\n CollectCompression true\n CollectIndividualUsers true\n CollectUserCount false\n</Plugin>\n\n", |
| 40 | + }) |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + ###################################################################### |
| 45 | + # Remaining parameter validation, compilation fails |
| 46 | + |
| 47 | + context ':statusfile is a string but not an absolute path' do |
| 48 | + let :facts do |
| 49 | + { :osfamily => 'RedHat', |
| 50 | + :collectd_version => '5.4', |
| 51 | + } |
| 52 | + end |
| 53 | + |
| 54 | + let :params do |
| 55 | + {:statusfile => 'megafrobber'} |
| 56 | + end |
| 57 | + |
| 58 | + it 'Will raise an error about :statusfile not being an absolute path' do |
| 59 | + should compile.and_raise_error(/"megafrobber" is not an absolute path./) |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + |
| 64 | + context ':statusfile param is not a string or array' do |
| 65 | + let :facts do |
| 66 | + { :osfamily => 'RedHat', |
| 67 | + :collectd_version => '5.4', |
| 68 | + } |
| 69 | + end |
| 70 | + |
| 71 | + let :params do |
| 72 | + {:statusfile => true} |
| 73 | + end |
| 74 | + |
| 75 | + it 'Will raise an error about :statusfile not being a string or array' do |
| 76 | + should compile.and_raise_error(/array or string:/) |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + context ':improvednamingschema is not a bool' do |
| 81 | + let :facts do |
| 82 | + { :osfamily => 'RedHat', |
| 83 | + :collectd_version => '5.4'} |
| 84 | + end |
| 85 | + let :params do |
| 86 | + {:improvednamingschema => "true"} |
| 87 | + end |
| 88 | + |
| 89 | + it 'Will raise an error about :improvednamingschema not being a boolean' do |
| 90 | + should compile.and_raise_error(/"true" is not a boolean. It looks to be a String/) |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + context ':collectcompression is not a bool' do |
| 95 | + let :facts do |
| 96 | + { :osfamily => 'RedHat', |
| 97 | + :collectd_version => '5.4'} |
| 98 | + end |
| 99 | + let :params do |
| 100 | + {:collectcompression => "true"} |
| 101 | + end |
| 102 | + |
| 103 | + it 'Will raise an error about :collectcompression not being a boolean' do |
| 104 | + should compile.and_raise_error(/"true" is not a boolean. It looks to be a String/) |
| 105 | + end |
| 106 | + end |
| 107 | + |
| 108 | + context ':collectindividualusers is not a bool' do |
| 109 | + let :facts do |
| 110 | + { :osfamily => 'RedHat', |
| 111 | + :collectd_version => '5.4'} |
| 112 | + end |
| 113 | + let :params do |
| 114 | + {:collectindividualusers => "true"} |
| 115 | + end |
| 116 | + |
| 117 | + it 'Will raise an error about :collectindividualusers not being a boolean' do |
| 118 | + should compile.and_raise_error(/"true" is not a boolean. It looks to be a String/) |
| 119 | + end |
| 120 | + end |
| 121 | + |
| 122 | + context ':collectusercount is not a bool' do |
| 123 | + let :facts do |
| 124 | + { :osfamily => 'RedHat', |
| 125 | + :collectd_version => '5.4'} |
| 126 | + end |
| 127 | + let :params do |
| 128 | + {:collectusercount => "true"} |
| 129 | + end |
| 130 | + |
| 131 | + it 'Will raise an error about :collectusercount not being a boolean' do |
| 132 | + should compile.and_raise_error(/"true" is not a boolean. It looks to be a String/) |
| 133 | + end |
| 134 | + end |
| 135 | + |
| 136 | + context ':interval is not default and is an integer' do |
| 137 | + let :facts do |
| 138 | + { :osfamily => 'RedHat', |
| 139 | + :collectd_version => '5.4'} |
| 140 | + end |
| 141 | + let :params do |
| 142 | + {:interval => 15} |
| 143 | + end |
| 144 | + |
| 145 | + it 'Will create /etc/collectd.d/10-openvpn.conf' do |
| 146 | + should contain_file('openvpn.load').with({ |
| 147 | + :ensure => 'present', |
| 148 | + :path => '/etc/collectd.d/10-openvpn.conf', |
| 149 | + :content => /^ Interval 15/, |
| 150 | + }) |
| 151 | + end |
| 152 | + end |
| 153 | + |
| 154 | + context ':ensure => absent' do |
| 155 | + let :facts do |
| 156 | + { :osfamily => 'RedHat', |
| 157 | + :collectd_version => '5.4', |
| 158 | + } |
| 159 | + end |
| 160 | + let :params do |
| 161 | + {:ensure => 'absent'} |
| 162 | + end |
| 163 | + |
| 164 | + it 'Will not create /etc/collectd.d/10-openvpn.conf' do |
| 165 | + should contain_file('openvpn.load').with({ |
| 166 | + :ensure => 'absent', |
| 167 | + :path => '/etc/collectd.d/10-openvpn.conf', |
| 168 | + }) |
| 169 | + end |
| 170 | + end |
| 171 | +end |
0 commit comments