diff --git a/manifests/node.pp b/manifests/node.pp new file mode 100644 index 0000000..fc4a166 --- /dev/null +++ b/manifests/node.pp @@ -0,0 +1,40 @@ +# == Class: selenium::node +# +# simple template +# +# +# === Examples +# +# include selenium::node +# +# +# === Authors +# +# Joshua Hoblitt +# +# +class selenium::node( + $display = $selenium::params::display, + $options = $selenium::params::node_options, + $hub = $selenium::params::default_hub, +) inherits selenium::params { + validate_string($display) + validate_string($options) + validate_string($hub) + + include selenium + + $safe_options = "${options} -hub ${hub}" + + anchor { 'selenium::node::begin': } + Class[ 'selenium' ] -> + selenium::config{ 'node': + display => $display, + user => $selenium::user, + group => $selenium::group, + install_root => $selenium::install_root, + options => $safe_options, + java => $selenium::java, + } -> + anchor { 'selenium::node::end': } +} diff --git a/manifests/params.pp b/manifests/params.pp index 81af212..45f003b 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -10,8 +10,10 @@ $install_root = '/opt/selenium' $server_options = '-Dwebdriver.enable.native.events=1' $hub_options = '-role hub' + $node_options = '-role node' $java = 'java' $version = '2.35.0' + $default_hub = 'http://localhost:4444/grid/register' case $::osfamily { 'redhat': {} diff --git a/spec/classes/selenium_node_spec.rb b/spec/classes/selenium_node_spec.rb new file mode 100644 index 0000000..1abf396 --- /dev/null +++ b/spec/classes/selenium_node_spec.rb @@ -0,0 +1,82 @@ +require 'spec_helper' + +describe 'selenium::node', :type => :class do + + shared_examples 'node' do |params| + p = { + :display => ':0', + :options => '-role node', + :hub => 'http://localhost:4444/grid/register', + } + + p.merge!(params) if params + + it do + should include_class('selenium') + should contain_selenium__config('node').with({ + 'options' => "#{p[:options]} -hub #{p[:hub]}", + }) + should contain_class('selenium::node') + end + end + + context 'for osfamily RedHat' do + let(:facts) {{ :osfamily => 'RedHat' }} + + context 'no params' do + it_behaves_like 'node', {} + end + + context 'display => :42' do + p = { :display => ':42' } + let(:params) { p } + + it_behaves_like 'node', p + end + + context 'display => :42' do + let(:params) {{ :display => [] }} + + it 'should fail' do + expect { + should contain_class('selenium::node') + }.to raise_error + end + end + + context 'options => -foo' do + p = { :options => '-foo' } + let(:params) { p } + + it_behaves_like 'node', p + end + + context 'options => []' do + let(:params) {{ :options => [] }} + + it 'should fail' do + expect { + should contain_class('selenium::node') + }.to raise_error + end + end + + context 'hub => http://foo' do + p = { :hub => 'http://foo' } + let(:params) { p } + + it_behaves_like 'node', p + end + + context 'hub => []' do + let(:params) {{ :hub => [] }} + + it 'should fail' do + expect { + should contain_class('selenium::node') + }.to raise_error + end + end + end + +end