forked from redhat-openstack/openstack-puppet-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert tests to use plain rspec-puppet
Tests in the new style produces the following documentation output: abs should not eq nil should run abs() and raise an Puppet::ParseError should run abs(-34) and return 34 should run abs("-34") and return 34 should run abs(34) and return 34 should run abs("34") and return 34
- Loading branch information
Showing
115 changed files
with
2,432 additions
and
4,139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'spec_helper_acceptance' | ||
|
||
describe 'anchor type', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do | ||
describe 'success' do | ||
it 'should effect proper chaining of resources' do | ||
pp = <<-EOS | ||
class anchored { | ||
anchor { 'anchored::begin': } | ||
~> anchor { 'anchored::end': } | ||
} | ||
class anchorrefresh { | ||
notify { 'first': } | ||
~> class { 'anchored': } | ||
~> anchor { 'final': } | ||
} | ||
include anchorrefresh | ||
EOS | ||
|
||
apply_manifest(pp, :catch_failures => true) do |r| | ||
expect(r.stdout).to match(/Anchor\[final\]: Triggered 'refresh'/) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
#! /usr/bin/env ruby -S rspec | ||
|
||
require 'spec_helper' | ||
|
||
describe "the abs function" do | ||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope } | ||
|
||
it "should exist" do | ||
expect(Puppet::Parser::Functions.function("abs")).to eq("function_abs") | ||
end | ||
describe 'abs' do | ||
it { is_expected.not_to eq(nil) } | ||
|
||
it "should raise a ParseError if there is less than 1 arguments" do | ||
expect { scope.function_abs([]) }.to( raise_error(Puppet::ParseError)) | ||
describe 'signature validation in puppet3', :unless => RSpec.configuration.puppet_future do | ||
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } | ||
it { | ||
pending("Current implementation ignores parameters after the first.") | ||
is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) | ||
} | ||
end | ||
|
||
it "should convert a negative number into a positive" do | ||
result = scope.function_abs(["-34"]) | ||
expect(result).to(eq(34)) | ||
describe 'signature validation in puppet4', :if => RSpec.configuration.puppet_future do | ||
it { pending "the puppet 4 implementation"; is_expected.to run.with_params().and_raise_error(ArgumentError) } | ||
it { pending "the puppet 4 implementation"; is_expected.to run.with_params(1, 2).and_raise_error(ArgumentError) } | ||
it { pending "the puppet 4 implementation"; is_expected.to run.with_params([]).and_raise_error(ArgumentError) } | ||
it { pending "the puppet 4 implementation"; is_expected.to run.with_params({}).and_raise_error(ArgumentError) } | ||
it { pending "the puppet 4 implementation"; is_expected.to run.with_params(true).and_raise_error(ArgumentError) } | ||
end | ||
|
||
it "should do nothing with a positive number" do | ||
result = scope.function_abs(["5678"]) | ||
expect(result).to(eq(5678)) | ||
end | ||
it { is_expected.to run.with_params(-34).and_return(34) } | ||
it { is_expected.to run.with_params("-34").and_return(34) } | ||
it { is_expected.to run.with_params(34).and_return(34) } | ||
it { is_expected.to run.with_params("34").and_return(34) } | ||
it { is_expected.to run.with_params(-34.5).and_return(34.5) } | ||
it { is_expected.to run.with_params("-34.5").and_return(34.5) } | ||
it { is_expected.to run.with_params(34.5).and_return(34.5) } | ||
it { is_expected.to run.with_params("34.5").and_return(34.5) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,15 @@ | ||
#! /usr/bin/env ruby -S rspec | ||
require 'spec_helper' | ||
|
||
describe "the any2array function" do | ||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope } | ||
|
||
it "should exist" do | ||
expect(Puppet::Parser::Functions.function("any2array")).to eq("function_any2array") | ||
end | ||
|
||
it "should return an empty array if there is less than 1 argument" do | ||
result = scope.function_any2array([]) | ||
expect(result).to(eq([])) | ||
end | ||
|
||
it "should convert boolean true to [ true ] " do | ||
result = scope.function_any2array([true]) | ||
expect(result).to(eq([true])) | ||
end | ||
|
||
it "should convert one object to [object]" do | ||
result = scope.function_any2array(['one']) | ||
expect(result).to(eq(['one'])) | ||
end | ||
|
||
it "should convert multiple objects to [objects]" do | ||
result = scope.function_any2array(['one', 'two']) | ||
expect(result).to(eq(['one', 'two'])) | ||
end | ||
|
||
it "should return empty array it was called with" do | ||
result = scope.function_any2array([[]]) | ||
expect(result).to(eq([])) | ||
end | ||
|
||
it "should return one-member array it was called with" do | ||
result = scope.function_any2array([['string']]) | ||
expect(result).to(eq(['string'])) | ||
end | ||
|
||
it "should return multi-member array it was called with" do | ||
result = scope.function_any2array([['one', 'two']]) | ||
expect(result).to(eq(['one', 'two'])) | ||
end | ||
|
||
it "should return members of a hash it was called with" do | ||
result = scope.function_any2array([{ 'key' => 'value' }]) | ||
expect(result).to(eq(['key', 'value'])) | ||
end | ||
|
||
it "should return an empty array if it was called with an empty hash" do | ||
result = scope.function_any2array([{ }]) | ||
expect(result).to(eq([])) | ||
end | ||
describe "any2array" do | ||
it { is_expected.not_to eq(nil) } | ||
it { is_expected.to run.with_params().and_return([]) } | ||
it { is_expected.to run.with_params(true).and_return([true]) } | ||
it { is_expected.to run.with_params('one').and_return(['one']) } | ||
it { is_expected.to run.with_params('one', 'two').and_return(['one', 'two']) } | ||
it { is_expected.to run.with_params([]).and_return([]) } | ||
it { is_expected.to run.with_params(['one']).and_return(['one']) } | ||
it { is_expected.to run.with_params(['one', 'two']).and_return(['one', 'two']) } | ||
it { is_expected.to run.with_params({}).and_return([]) } | ||
it { is_expected.to run.with_params({ 'key' => 'value' }).and_return(['key', 'value']) } | ||
it { is_expected.to run.with_params({ 'key' => 'value' }).and_return(['key', 'value']) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,15 @@ | ||
#! /usr/bin/env ruby -S rspec | ||
|
||
require 'spec_helper' | ||
|
||
describe "the base64 function" do | ||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope } | ||
|
||
it "should exist" do | ||
expect(Puppet::Parser::Functions.function("base64")).to eq("function_base64") | ||
end | ||
|
||
it "should raise a ParseError if there are other than 2 arguments" do | ||
expect { scope.function_base64([]) }.to(raise_error(Puppet::ParseError)) | ||
expect { scope.function_base64(["asdf"]) }.to(raise_error(Puppet::ParseError)) | ||
expect { scope.function_base64(["asdf","moo","cow"]) }.to(raise_error(Puppet::ParseError)) | ||
end | ||
|
||
it "should raise a ParseError if argument 1 isn't 'encode' or 'decode'" do | ||
expect { scope.function_base64(["bees","astring"]) }.to(raise_error(Puppet::ParseError, /first argument must be one of/)) | ||
end | ||
|
||
it "should raise a ParseError if argument 2 isn't a string" do | ||
expect { scope.function_base64(["encode",["2"]]) }.to(raise_error(Puppet::ParseError, /second argument must be a string/)) | ||
end | ||
|
||
it "should encode a encoded string" do | ||
result = scope.function_base64(["encode",'thestring']) | ||
expect(result).to match(/\AdGhlc3RyaW5n\n\Z/) | ||
end | ||
it "should decode a base64 encoded string" do | ||
result = scope.function_base64(["decode",'dGhlc3RyaW5n']) | ||
expect(result).to eq('thestring') | ||
end | ||
describe 'base64' do | ||
it { is_expected.not_to eq(nil) } | ||
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } | ||
it { is_expected.to run.with_params("one").and_raise_error(Puppet::ParseError) } | ||
it { is_expected.to run.with_params("one", "two", "three").and_raise_error(Puppet::ParseError) } | ||
it { is_expected.to run.with_params("one", "two").and_raise_error(Puppet::ParseError, /first argument must be one of/) } | ||
it { is_expected.to run.with_params("encode", ["two"]).and_raise_error(Puppet::ParseError, /second argument must be a string/) } | ||
it { is_expected.to run.with_params("encode", 2).and_raise_error(Puppet::ParseError, /second argument must be a string/) } | ||
|
||
it { is_expected.to run.with_params("encode", "thestring").and_return("dGhlc3RyaW5n\n") } | ||
it { is_expected.to run.with_params("decode", "dGhlc3RyaW5n").and_return("thestring") } | ||
it { is_expected.to run.with_params("decode", "dGhlc3RyaW5n\n").and_return("thestring") } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,13 @@ | ||
#! /usr/bin/env ruby -S rspec | ||
require 'spec_helper' | ||
|
||
describe "the basename function" do | ||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope } | ||
|
||
it "should exist" do | ||
Puppet::Parser::Functions.function("basename").should == "function_basename" | ||
end | ||
|
||
it "should raise a ParseError if there is less than 1 argument" do | ||
lambda { scope.function_basename([]) }.should( raise_error(Puppet::ParseError)) | ||
end | ||
|
||
it "should raise a ParseError if there are more than 2 arguments" do | ||
lambda { scope.function_basename(['a', 'b', 'c']) }.should( raise_error(Puppet::ParseError)) | ||
end | ||
|
||
it "should return basename for an absolute path" do | ||
result = scope.function_basename(['/path/to/a/file.ext']) | ||
result.should(eq('file.ext')) | ||
end | ||
|
||
it "should return basename for a relative path" do | ||
result = scope.function_basename(['path/to/a/file.ext']) | ||
result.should(eq('file.ext')) | ||
end | ||
|
||
it "should strip extention when extension specified (absolute path)" do | ||
result = scope.function_basename(['/path/to/a/file.ext', '.ext']) | ||
result.should(eq('file')) | ||
end | ||
|
||
it "should strip extention when extension specified (relative path)" do | ||
result = scope.function_basename(['path/to/a/file.ext', '.ext']) | ||
result.should(eq('file')) | ||
end | ||
|
||
it "should complain about non-string first argument" do | ||
lambda { scope.function_basename([[]]) }.should( raise_error(Puppet::ParseError)) | ||
end | ||
|
||
it "should complain about non-string second argument" do | ||
lambda { scope.function_basename(['/path/to/a/file.ext', []]) }.should( raise_error(Puppet::ParseError)) | ||
end | ||
describe 'basename' do | ||
it { is_expected.not_to eq(nil) } | ||
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } | ||
it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(Puppet::ParseError) } | ||
it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) } | ||
it { is_expected.to run.with_params('/path/to/a/file.ext', []).and_raise_error(Puppet::ParseError) } | ||
it { is_expected.to run.with_params('/path/to/a/file.ext').and_return('file.ext') } | ||
it { is_expected.to run.with_params('relative_path/to/a/file.ext').and_return('file.ext') } | ||
it { is_expected.to run.with_params('/path/to/a/file.ext', '.ext').and_return('file') } | ||
it { is_expected.to run.with_params('relative_path/to/a/file.ext', '.ext').and_return('file') } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,14 @@ | ||
#! /usr/bin/env ruby -S rspec | ||
require 'spec_helper' | ||
|
||
describe "the bool2num function" do | ||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope } | ||
describe 'bool2num' do | ||
it { is_expected.not_to eq(nil) } | ||
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) } | ||
|
||
it "should exist" do | ||
expect(Puppet::Parser::Functions.function("bool2num")).to eq("function_bool2num") | ||
[ true, 'true', AlsoString.new('true') ].each do |truthy| | ||
it { is_expected.to run.with_params(truthy).and_return(1) } | ||
end | ||
|
||
it "should raise a ParseError if there is less than 1 arguments" do | ||
expect { scope.function_bool2num([]) }.to( raise_error(Puppet::ParseError)) | ||
end | ||
|
||
it "should convert true to 1" do | ||
result = scope.function_bool2num([true]) | ||
expect(result).to(eq(1)) | ||
end | ||
|
||
it "should convert 'true' to 1" do | ||
result = scope.function_bool2num(['true']) | ||
result.should(eq(1)) | ||
end | ||
|
||
it "should convert 'false' to 0" do | ||
result = scope.function_bool2num(['false']) | ||
expect(result).to(eq(0)) | ||
end | ||
|
||
it "should accept objects which extend String" do | ||
class AlsoString < String | ||
end | ||
|
||
value = AlsoString.new('true') | ||
result = scope.function_bool2num([value]) | ||
result.should(eq(1)) | ||
[ false, 'false', AlsoString.new('false') ].each do |falsey| | ||
it { is_expected.to run.with_params(falsey).and_return(0) } | ||
end | ||
end |
Oops, something went wrong.