Skip to content

Commit

Permalink
rename class selenium::install -> selenium and refactor it as common …
Browse files Browse the repository at this point in the history
…base
  • Loading branch information
Joshua Hoblitt committed Oct 2, 2013
1 parent 50e63e6 commit 8523e66
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 170 deletions.
7 changes: 4 additions & 3 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@
$user = $selenium::params::user,
$group = $selenium::params::group,
$install_root = $selenium::params::install_root,
$options = $selenium::params::default_options,
$options = $selenium::params::server_options,
$java = $selenium::params::java,
$jar_name = $selenium::install::jar_name,
$jar_name = $selenium::jar_name,
) {
validate_string($display)
validate_string($user)
validate_string($group)
validate_string($install_root)
validate_string($options)
validate_string($java)
validate_string($jar_name)

# prog is the 'name' of the init.d script.
$prog = $name
$prog = $name

file { "/etc/init.d/${prog}":
ensure => 'file',
Expand Down
42 changes: 23 additions & 19 deletions manifests/install.pp → manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# == Class: megaraid::lsiget
#
# installs the `lsiget` utility for LSI MegaRAID controllers
#
# See: http://mycusthelp.info/LSI/_cs/AnswerDetail.aspx?inc=8264
# == Class: selenium
#
#
# === Parameters
Expand All @@ -12,27 +8,35 @@
#
# === Examples
#
# class{ 'megaraid::lsiget': }
# class{ 'selenium': }
#
#
# === Authors
#
# Joshua Hoblitt <jhoblitt@cpan.org>
#
#
class selenium::install(
$version = '2.35.0',
$url = undef,
) {
class selenium(
$user = $selenium::params::user,
$group = $selenium::params::group,
$install_root = $selenium::params::install_root,
$java = $selenium::params::java,
$version = $selenium::params::version,
$url = undef,
) inherits selenium::params {
validate_string($user)
validate_string($group)
validate_string($install_root)
validate_string($java)
validate_string($version)
validate_string($url)

include wget

user { $selenium::server::user:
gid => [$selenium::server::group],
user { $user:
gid => [$group],
}
group { $selenium::server::group: }
group { $group: }

$jar_name = "selenium-server-standalone-${version}.jar"

Expand All @@ -43,16 +47,16 @@
}

File {
owner => $selenium::server::user,
group => $selenium::server::group,
owner => $user,
group => $group,
}

file { $selenium::server::install_root:
file { $install_root:
ensure => directory,
}

$jar_path = "${selenium::server::install_root}/jars"
$log_path = "${selenium::server::install_root}/log"
$jar_path = "${install_root}/jars"
$log_path = "${install_root}/log"

file { $jar_path:
ensure => directory,
Expand All @@ -73,7 +77,7 @@
source => $jar_url,
destination => "${jar_path}/${jar_name}",
timeout => 90,
execuser => $selenium::server::user,
execuser => $user,
require => File[$jar_path],
}

Expand Down
4 changes: 3 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
$user = 'selenium'
$group = $user
$install_root = '/opt/selenium'
$default_options = '-Dwebdriver.enable.native.events=1'
$server_options = '-Dwebdriver.enable.native.events=1'
$hub_options = '-role hub'
$java = 'java'
$version = '2.35.0'

case $::osfamily {
'redhat': {}
Expand Down
23 changes: 9 additions & 14 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,21 @@
#
class selenium::server(
$display = $selenium::params::display,
$user = $selenium::params::user,
$group = $selenium::params::group,
$install_root = $selenium::params::install_root,
$options = $selenium::params::default_options,
$java = $selenium::params::java,
$options = $selenium::params::server_options,
) inherits selenium::params {
validate_string($display)
validate_string($user)
validate_string($group)
validate_string($install_root)
validate_string($options)
validate_string($java)

class { 'selenium::install': } ->
include selenium

Class[ 'selenium' ] ->
selenium::config{ 'seleniumstandalone':
display => $display,
user => $user,
group => $group,
install_root => $install_root,
java => $java,
user => $selenium::user,
group => $selenium::group,
install_root => $selenium::install_root,
options => $options,
java => $selenium::java,
} ->
class { 'selenium::service': } ->
Class[ 'selenium::server' ]
Expand Down
46 changes: 0 additions & 46 deletions spec/classes/selenium_install_spec.rb

This file was deleted.

104 changes: 21 additions & 83 deletions spec/classes/selenium_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,37 @@

describe 'selenium::server', :type => :class do

shared_examples 'server' do |user, group|
shared_examples 'server' do |params|
p = {
:display => ':0',
:options => '-Dwebdriver.enable.native.events=1',
}

p.merge!(params) if params

it do
should contain_class('selenium::server')
should contain_class('selenium::install')
should contain_file('/etc/init.d/seleniumstandalone')
should include_class('selenium')
should contain_selenium__config('seleniumstandalone').with({
'display' => p[:display],
'options' => p[:options],
})
should contain_class('selenium::service')
should contain_user(user).with_gid(group)
should contain_group(group)
should contain_class('selenium::server')
end
end

context 'for osfamily RedHat' do
let(:facts) {{ :osfamily => 'RedHat' }}

context 'no params' do
it_behaves_like 'server', 'selenium', 'selenium'
it_behaves_like 'server', {}
end

context 'display => :42' do
let(:params) {{ :display => ':42' }}
p = { :display => ':42' }
let(:params) { p }

it_behaves_like 'server', 'selenium', 'selenium'
it_behaves_like 'server', p
end

context 'display => :42' do
Expand All @@ -36,66 +45,11 @@
end
end

context 'user => foo' do
let(:params) {{ :user => 'foo' }}

it_behaves_like 'server', 'foo', 'selenium'
end

context 'user => []' do
let(:params) {{ :user => [] }}

it 'should fail' do
expect {
should contain_class('selenium::server')
}.to raise_error
end
end

context 'group => foo' do
let(:params) {{ :group => 'foo' }}

it_behaves_like 'server', 'selenium', 'foo'
end

context 'group => []' do
let(:params) {{ :group => [] }}

it 'should fail' do
expect {
should contain_class('selenium::server')
}.to raise_error
end
end

context 'install_root => /foo/selenium' do
let(:params) {{ :install_root => '/foo/selenium' }}

it_behaves_like 'server', 'selenium', 'selenium'

it do
should contain_file('/foo/selenium').with({
'ensure' => 'directory',
'owner' => 'selenium',
'group' => 'selenium',
})
end
end

context 'install_root => []' do
let(:params) {{ :install_root => [] }}

it 'should fail' do
expect {
should contain_class('selenium::server')
}.to raise_error
end
end

context 'options => -foo' do
let(:params) {{ :options => '-foo' }}
p = { :options => '-foo' }
let(:params) { p }

it_behaves_like 'server', 'selenium', 'selenium'
it_behaves_like 'server', p
end

context 'options => []' do
Expand All @@ -107,22 +61,6 @@
}.to raise_error
end
end

context 'java => /opt/java' do
let(:params) {{ :java => '/opt/java' }}

it_behaves_like 'server', 'selenium', 'selenium'
end

context 'java => []' do
let(:params) {{ :java => [] }}

it 'should fail' do
expect {
should contain_class('selenium::server')
}.to raise_error
end
end
end

end
Loading

0 comments on commit 8523e66

Please sign in to comment.