Skip to content

Commit

Permalink
Merge pull request #11 from coi-gov-pl/feature/1-even-more-tests-befo…
Browse files Browse the repository at this point in the history
…re-release

Enh #1 Even more tests before release
  • Loading branch information
cardil committed Sep 25, 2015
2 parents 0a70364 + 765217e commit 4b8a34b
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 7 deletions.
8 changes: 8 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
guard 'rake', :task => :spec_ruby do
watch(%r{spec/(unit|functions|hosts|integration|types)/.+_spec\.rb})
watch(%r{lib/.+\.rb})
end
guard 'rake', :task => :spec_puppet_prepared do
watch(%r{spec/(classes|defines)/.+_spec\.rb})
watch(%r{manifests/.+\.pp})
end
13 changes: 9 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,25 @@ end

Rake::Task[:spec_standalone].clear
desc "Run spec tests on an existing fixtures directory (for Puppet code)"
RSpec::Core::RakeTask.new(:spec_standalone_puppet) do |t|
RSpec::Core::RakeTask.new(:spec_puppet) do |t|
t.rspec_opts = ['--color --order rand']
t.pattern = 'spec/{classes,defines}/**/*_spec.rb'
end
desc "Run spec tests on an existing fixtures directory (for Ruby code)"
RSpec::Core::RakeTask.new(:spec_standalone_ruby) do |t|
RSpec::Core::RakeTask.new(:spec_ruby) do |t|
t.rspec_opts = ['--color --order rand']
t.verbose = true
t.pattern = 'spec/{unit,functions,hosts,integration,types}/**/*_spec.rb'
end
desc 'Run spec tests on an existing fixtures directory'
task :spec_standalone => [
:spec_standalone_puppet,
:spec_standalone_ruby
:spec_puppet,
:spec_ruby
]

task :spec_puppet_prepared => [
:spec_prep,
:spec_puppet
]

begin
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
add_filter "/.vendor/"
add_filter "/vendor/"
add_filter "/gems/"
minimum_coverage 66
minimum_coverage 76
refuse_coverage_drop
end
rescue Gem::LoadError
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/facter/jboss_running_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe 'jboss_running', :type => :fact do
subject { Facter.value(:jboss_running) }
it { expect { subject }.not_to raise_error }
it { expect(subject).to match('^(?:true|false)$') }
end
25 changes: 25 additions & 0 deletions spec/unit/lib/provider/datasource/post_wildfly_provider_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'
require 'puppet_x/coi/jboss/provider/datasource/post_wildfly_provider'

describe Puppet_X::Coi::Jboss::Provider::Datasource::PostWildFlyProvider do

let(:xa) { false }
let(:jta) { true }
let(:provider) { double("Provider") }
before do
allow(provider).to receive(:xa?).and_return(xa)
allow(provider).to receive(:getattrib).and_return(jta)
end
let(:target) { described_class.new(provider) }

describe 'xa_datasource_properties_wrapper' do
let(:parameters) { 'david=one,martha=tree' }
subject { target.xa_datasource_properties_wrapper(parameters) }
it { expect(subject).to eq('{david=one,martha=tree}') }
end

describe 'jta' do
subject { target.jta }
it { expect(subject).to eq('true') }
end
end
13 changes: 13 additions & 0 deletions spec/unit/lib/provider/datasource/pre_wildfly_provider_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'spec_helper'
require 'puppet_x/coi/jboss/provider/datasource/pre_wildfly_provider'

describe Puppet_X::Coi::Jboss::Provider::Datasource::PreWildFlyProvider do

let(:target) { described_class.new(nil) }

describe 'xa_datasource_properties_wrapper' do
let(:parameters) { 'david=one,martha=tree' }
subject { target.xa_datasource_properties_wrapper(parameters) }
it { expect(subject).to eq('[david=one,martha=tree]') }
end
end
39 changes: 38 additions & 1 deletion spec/unit/provider/jboss_datasource/jbosscli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@
:xa => true,
:runasdomain => false,
:jdbcscheme => 'h2:mem',
:options => {},
:jndiname => 'jboss:/datasources/testing'
}
end
before :each do
Expand Down Expand Up @@ -240,7 +242,7 @@
{
:product => 'jboss-eap',
:version => '6.2.0.GA',
:controller => '127.0.0.1:9999',
:controller => '127.0.0.1:9999'
}
end
describe 'jta()' do
Expand All @@ -262,7 +264,42 @@
it { expect(subject).not_to be_nil }
it { expect(cmd).to be_empty }
end

describe 'create()' do
before :each do
cmd = 'xa-data-source add --name=testing --jta=true --jndi-name="jboss:/datasources/testing" ' +
'--driver-name=nil --min-pool-size=nil --max-pool-size=nil' +
' --user-name=nil --password=nil --xa-datasource-properties=' +
'[ServerName=nil,PortNumber=nil,DatabaseName="testing"]'
expect(provider).to receive(:executeWithFail).with('Datasource', cmd, 'to create')
cli = '/subsystem=datasources/xa-data-source=testing:read-attribute(name=enabled)'
expect(provider).to receive(:executeAndGet).with(cli).and_return({
:result => true,
:data => true
})
end
subject { provider.create }
it { expect { subject }.not_to raise_error }
end

describe 'destroy()' do
before :each do
cmd = 'xa-data-source remove --name=testing'
expect(provider).to receive(:executeWithFail).with('Datasource', cmd, 'to remove')
end
subject { provider.destroy }
it { expect { subject }.not_to raise_error }
end
end
end

describe 'prepare_resource()' do
before :each do
provider.instance_variable_set(:@resource, nil)
end
subject { provider.prepare_resource }
it { expect { subject }.not_to raise_error }
end

end
end
179 changes: 179 additions & 0 deletions spec/unit/types/jboss_datasource_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
require 'spec_helper'

describe 'jboss_datasource', :type => :type do
let(:described_class) { Puppet::Type.type(:jboss_datasource) }
subject { described_class }
it { expect(subject).not_to be_nil }
let(:ex_class) { if Puppet.version > '3.0.0' then Puppet::ResourceError else Puppet::Error end }

def extend_params(given)
{
:title => 'spec-datasource'
}.merge(given)
end

let(:type) { described_class.new(params) }

describe 'controller' do
context 'given :undef' do
let(:params) { extend_params({ :controller => :undef }) }
it do
expect { type }.to raise_error(ex_class,
'Parameter controller failed on Jboss_datasource[spec-datasource]: Domain controller must be provided')
end
end
end

describe 'port' do
context 'given invalid text' do
let(:params) { extend_params({ :port => "an invalid port" }) }
it do
expect { type }.to raise_error(ex_class,
'Parameter port failed on Jboss_datasource[spec-datasource]: Datasource port is invalid, given "an invalid port"')
end
end
context 'given "5x45"' do
let(:params) { extend_params({ :port => "5x45" }) }
before { skip('FIXME: A buggy host validation, ref: coi-gov-pl/puppet-jboss#8') }
it do
expect { type }.to raise_error(ex_class,
'Parameter port failed on Jboss_datasource[spec-datasource]: Datasource port is invalid, given "an invalid port"')
end
end
context 'property :port' do
subject { type.property :port }
context 'given as "7778"' do
let(:params) { extend_params({ :port => "7778" }) }
its(:value) { should == 7778 }
end
context 'given as ""' do
let(:params) { extend_params({ :port => "" }) }
its(:value) { should == 0 }
end
end
end

describe 'host' do
context 'given invalid text " "' do
let(:params) { extend_params({ :host => ' ' }) }
it do
expect { type }.to raise_error(ex_class,
'Parameter host failed on Jboss_datasource[spec-datasource]: Datasource host is invalid, given " "')
end
end
context 'given "an invalid host"' do
before { skip('FIXME: A buggy host validation, ref: coi-gov-pl/puppet-jboss#8') }
let(:params) { extend_params({ :host => "an invalid host" }) }
it do
expect { type }.to raise_error(ex_class,
'Parameter host failed on Jboss_datasource[spec-datasource]: Datasource host is invalid, given "an invalid host"')
end
end
end

describe 'minpoolsize' do
subject { type.property :minpoolsize }
context 'given invalid text' do
let(:params) { extend_params({ :minpoolsize => "an invalid text" }) }
its(:value) { should == 1 }
end
context 'given 13.45' do
let(:params) { extend_params({ :minpoolsize => 13.45 }) }
its(:value) { should == 13 }
end
context 'given :undef' do
let(:params) { extend_params({ :minpoolsize => :undef }) }
its(:value) { should == 1 }
end
context 'given "17"' do
let(:params) { extend_params({ :minpoolsize => '17' }) }
its(:value) { should == 17 }
end
end

describe 'maxpoolsize' do
subject { type.property :maxpoolsize }
context 'given invalid text' do
let(:params) { extend_params({ :maxpoolsize => "an invalid text" }) }
its(:value) { should == 50 }
end
context 'given 13.45' do
let(:params) { extend_params({ :maxpoolsize => 13.45 }) }
its(:value) { should == 13 }
end
context 'given :undef' do
let(:params) { extend_params({ :maxpoolsize => :undef }) }
its(:value) { should == 50 }
end
context 'given "17"' do
let(:params) { extend_params({ :maxpoolsize => '17' }) }
its(:value) { should == 17 }
end
end

describe 'password' do
let(:params) { extend_params({ :password => "an invalid text" }) }
let(:expected_message) { 'password has been changed.' }
subject { type.property(:password).change_to_s(from, to) }
context 'change_to_s' do
context ':absent, "test-passwd"' do
let(:from) { :absent }
let(:to) { 'test-passwd' }
it { expect(subject).to eq(expected_message) }
end
context '"test-passwd", :absent' do
let(:from) { 'test-passwd' }
let(:to) { :absent }
it { expect(subject).to eq(expected_message) }
end
end
end

describe 'options' do
let(:params) do
extend_params({
:options => options
})
end
context 'given invalid text' do
before { skip('FIXME: String should not be accepted as a parameter, ref: coi-gov-pl/puppet-jboss#9')}
let(:options) { "an invalid text" }
it do
expect { type }.to raise_error(ex_class,
'Parameter options failed on Jboss_datasource[spec-datasource]: You can pass only hash-like objects')
end
end
context 'given invalid boolean' do
let(:options) { true }
it do
expect { type }.to raise_error(ex_class,
'Parameter options failed on Jboss_datasource[spec-datasource]: You can pass only hash-like objects')
end
end
context 'given' do
let(:options) { {} }
subject { type.property(:options).change_to_s(from, to) }
context 'from :absent and to hash', :from => :absent, :to => { 'alice' => 'five', 'bob' => 'seven' } do
before do
msg = 'FIXME: Handle :symbols as parameters in change_to_s, ref: coi-gov-pl/puppet-jboss#9'
skip(msg) if RUBY_VERSION < '1.9.0'
end
let(:from) { |expl| expl.metadata[:from] }
let(:to) { |expl| expl.metadata[:to] }
it { expect(subject).to eq("option 'alice' has changed from nil to \"five\", option 'bob' has changed from nil to \"seven\"") }
end
context 'from hash and to changed hash', :from => { 'alice' => 'five', 'bob' => 'nine' }, :to => { 'alice' => 'five', 'bob' => 'seven' } do
let(:from) { |expl| expl.metadata[:from] }
let(:to) { |expl| expl.metadata[:to] }
it { expect(subject).to eq("option 'bob' has changed from \"nine\" to \"seven\"") }
end
context 'from hash and to :absent', :from => { 'alice' => 'five', 'bob' => 'nine' }, :to => :absent do
before { skip('FIXME: A proper message while executing change_to_s for :to == :absent, ref: coi-gov-pl/puppet-jboss#9')}
let(:from) { |expl| expl.metadata[:from] }
let(:to) { |expl| expl.metadata[:to] }
it { expect(subject).to eq('options has been removed') }
end
end
end

end
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'spec_helper'

describe 'jboss_jdbcdriver', :type => :type do
it { expect('').to be_empty }
let(:described_class) { Puppet::Type.type(:jboss_jdbcdriver) }
subject { described_class }
it { expect(subject).not_to be_nil }
Expand Down

0 comments on commit 4b8a34b

Please sign in to comment.