Skip to content

Commit

Permalink
Cleanup and extend acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bobapple committed Sep 25, 2017
1 parent 2354ebc commit 5c302c1
Show file tree
Hide file tree
Showing 25 changed files with 398 additions and 158 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -21,5 +21,6 @@ unless RUBY_VERSION < '2.0.0'
end
gem 'serverspec', :require => false
gem 'beaker-puppet_install_helper', :require => false
gem 'beaker-module_install_helper', :require => false
end
end
16 changes: 16 additions & 0 deletions TESTING.md
Expand Up @@ -41,6 +41,22 @@ rake spec
With integration tests this module is tested on multiple platforms to check the complete installation process. We define
these tests with [ServerSpec] and run them on VMs by using [Beaker].

Run all tests:
```
bundle exec rake acceptance
```

Run a single test:
```
bundle exec rake beaker:ubuntu-server-1604-x64
```

Don't destroy VM after tests:
```
export BEAKER_destroy=no
bundle exec rake beaker:ubuntu-server-1604-x64
```

### Run tests
All available ServerSpec tests are listed in the `spec/acceptance/` directory.

Expand Down
21 changes: 11 additions & 10 deletions examples/apache2.pp
Expand Up @@ -25,21 +25,22 @@
import_schema => true,
db_type => 'mysql',
db_host => 'localhost',
db_port => '3306',
db_port => 3306,
db_username => 'icingaweb2',
db_password => 'icingaweb2',
require => Mysql::Db['icingaweb2'],
}

class {'icingaweb2::module::monitoring':
ido_host => 'localhost',
ido_db_name => 'icinga2',
ido_db_username => 'icinga2',
ido_db_password => 'supersecret',
icinga2 => {
transport => 'api',
username => 'root',
password => 'icinga',
ido_host => 'localhost',
ido_db_name => 'icinga2',
ido_db_username => 'icinga2',
ido_db_password => 'supersecret',
commandtransports => {
icinga2 => {
transport => 'api',
username => 'root',
password => 'icinga',
}
}
}
}
2 changes: 1 addition & 1 deletion examples/authmethod.pp
Expand Up @@ -9,7 +9,7 @@
type => 'db',
db_type => 'mysql',
host => 'localhost',
port => '3306',
port => 3306,
db_name => 'icingaweb2',
db_username => 'root',
db_password => 'supersecret',
Expand Down
2 changes: 1 addition & 1 deletion examples/import_schema.pp
Expand Up @@ -19,7 +19,7 @@
import_schema => true,
db_type => 'pgsql',
db_host => 'localhost',
db_port => '5432',
db_port => 5432,
db_username => 'icingaweb2',
db_password => 'icingaweb2',
require => [ Postgresql::Server::Db['icingaweb2'], Mysql::Db['icingaweb2'] ]
Expand Down
11 changes: 10 additions & 1 deletion examples/module_director.pp
@@ -1,3 +1,5 @@
package { 'git': }

include ::mysql::server

mysql::db { 'director':
Expand All @@ -13,7 +15,7 @@
import_schema => true,
db_type => 'mysql',
db_host => 'localhost',
db_port => '3306',
db_port => 3306,
db_username => 'icingaweb2',
db_password => 'icingaweb2',
}
Expand All @@ -23,6 +25,13 @@
ido_db_name => 'icinga2',
ido_db_username => 'icinga2',
ido_db_password => 'supersecret',
commandtransports => {
icinga2 => {
transport => 'api',
username => 'root',
password => 'icinga',
}
}
}

class {'icingaweb2::module::director':
Expand Down
2 changes: 1 addition & 1 deletion examples/module_monitoring.pp
Expand Up @@ -13,7 +13,7 @@
import_schema => true,
db_type => 'mysql',
db_host => 'localhost',
db_port => '3306',
db_port => 3306,
db_username => 'icingaweb2',
db_password => 'icingaweb2',
require => Mysql::Db['icingaweb2'],
Expand Down
26 changes: 0 additions & 26 deletions spec/acceptance/1_init_spec.rb

This file was deleted.

56 changes: 56 additions & 0 deletions spec/acceptance/apache2_spec.rb
@@ -0,0 +1,56 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'icingaweb2 with apache2' do
it 'with basic settings and apache2' do
pp = "
class { 'apache':
mpm_module => 'prefork'
}
class { 'apache::mod::php': }
case $::osfamily {
'redhat': {
package { 'php-mysql': }
file {'/etc/httpd/conf.d/icingaweb2.conf':
source => 'puppet:///modules/icingaweb2/examples/apache2/icingaweb2.conf',
require => Class['apache'],
notify => Service['httpd'],
}
}
'debian': {
class { 'apache::mod::rewrite': }
file {'/etc/apache2/conf.d/icingaweb2.conf':
source => 'puppet:///modules/icingaweb2/examples/apache2/icingaweb2.conf',
require => Class['apache'],
notify => Service['apache2'],
}
}
}
class {'icingaweb2':
manage_repo => true,
}
"

apply_manifest(pp, catch_failures: true)
end

if fact('osfamily') == 'Debian'
describe service('apache2') do
it { is_expected.to be_running }
end
end

if fact('osfamily') == 'RedHat'
describe service('httpd') do
it { is_expected.to be_running }
end
end

describe command('curl -I http://localhost/icingaweb2/') do
its(:stdout) { should match(%r{302 Found}) }
end
end
25 changes: 25 additions & 0 deletions spec/acceptance/class_spec.rb
@@ -0,0 +1,25 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'icingaweb2 class:' do
it 'runs successfully' do
pp = "
class { '::icingaweb2':
manage_repo => true,
}
"

apply_manifest(pp, catch_failures: true)
end

describe package('icingaweb2') do
it { is_expected.to be_installed }
end

describe file('/etc/icingaweb2/config.ini') do
it { is_expected.to be_file }
it { is_expected.to contain '[global]' }
it { is_expected.to contain '[logging]' }
end

end
95 changes: 95 additions & 0 deletions spec/acceptance/icingaweb2_director_spec.rb
@@ -0,0 +1,95 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'

describe 'icingaweb2::module::director class:' do
it 'runs successfully' do
pp = "
package { 'git': }
include ::mysql::server
mysql::db { 'icingaweb2':
user => 'icingaweb2',
password => 'icingaweb2',
host => 'localhost',
grant => ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'DROP', 'CREATE VIEW', 'CREATE', 'INDEX', 'EXECUTE', 'ALTER', 'REFERENCES'],
}
mysql::db { 'director':
user => 'director',
password => 'director',
host => 'localhost',
charset => 'utf8',
grant => ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'DROP', 'CREATE VIEW', 'CREATE', 'INDEX', 'EXECUTE', 'ALTER', 'REFERENCES'],
}
class {'icingaweb2':
manage_repo => true,
import_schema => true,
db_type => 'mysql',
db_host => 'localhost',
db_port => 3306,
db_username => 'icingaweb2',
db_password => 'icingaweb2',
require => Mysql::Db['icingaweb2'],
}
class {'icingaweb2::module::monitoring':
ido_host => 'localhost',
ido_db_name => 'icinga2',
ido_db_username => 'icinga2',
ido_db_password => 'supersecret',
commandtransports => {
icinga2 => {
transport => 'api',
username => 'root',
password => 'icinga',
}
}
}
class {'icingaweb2::module::director':
git_revision => 'v1.3.2',
db_host => 'localhost',
db_name => 'director',
db_username => 'director',
db_password => 'director',
import_schema => true,
kickstart => false,
endpoint => 'puppet-icingaweb2.localdomain',
api_username => 'root',
api_password => 'icinga',
require => Mysql::Db['director']
}
"

apply_manifest(pp, catch_failures: true)
end

describe file('/etc/icingaweb2/enabledModules/director') do
it { is_expected.to be_symlink }
end

describe file('/etc/icingaweb2/modules/director/config.ini') do
it { is_expected.to be_file }
it { is_expected.to contain '[db]' }
it { is_expected.to contain 'resource = "icingaweb2-module-director"' }
end

describe file('/etc/icingaweb2/resources.ini') do
it { is_expected.to be_file }
it { is_expected.to contain '[icingaweb2-module-director]' }
it { is_expected.to contain 'type = "db"' }
it { is_expected.to contain 'db = "mysql"' }
it { is_expected.to contain 'host = "localhost"' }
it { is_expected.to contain 'port = "3306"' }
it { is_expected.to contain 'dbname = "director"' }
it { is_expected.to contain 'username = "director"' }
it { is_expected.to contain 'password = "director"' }
it { is_expected.to contain 'charset = "utf8"' }
end

#describe command('mysql -e "select object_name from director.icinga_apiuser"') do
# its(:stdout) { should match(%r{root}) }
#end
end

0 comments on commit 5c302c1

Please sign in to comment.