adding fake driver

This commit is contained in:
2013-07-25 16:14:38 -04:00
parent 266b0722f1
commit 5a69517c0b
24 changed files with 1740 additions and 1230 deletions

View File

@@ -1,180 +1,180 @@
require 'pathname'
Puppet::Type.newtype(:vcsrepo) do
desc "A local version control repository"
feature :gzip_compression,
"The provider supports explicit GZip compression levels"
feature :basic_auth,
"The provider supports HTTP Basic Authentication"
feature :bare_repositories,
"The provider differentiates between bare repositories
and those with working copies",
:methods => [:bare_exists?, :working_copy_exists?]
feature :filesystem_types,
"The provider supports different filesystem types"
feature :reference_tracking,
"The provider supports tracking revision references that can change
over time (eg, some VCS tags and branch names)"
feature :ssh_identity,
"The provider supports a configurable SSH identity file"
feature :user,
"The provider can run as a different user"
feature :modules,
"The repository contains modules that can be chosen of"
feature :multiple_remotes,
"The repository tracks multiple remote repositories"
ensurable do
attr_accessor :latest
def insync?(is)
@should ||= []
case should
when :present
return true unless [:absent, :purged, :held].include?(is)
when :latest
if is == :latest
return true
else
return false
end
when :bare
return is == :bare
end
end
newvalue :present do
notice "Creating repository from present"
provider.create
end
newvalue :bare, :required_features => [:bare_repositories] do
if !provider.exists?
provider.create
end
end
newvalue :absent do
provider.destroy
end
newvalue :latest, :required_features => [:reference_tracking] do
if provider.exists?
if provider.respond_to?(:update_references)
provider.update_references
end
if provider.respond_to?(:latest?)
reference = provider.latest || provider.revision
else
reference = resource.value(:revision) || provider.revision
end
notice "Updating to latest '#{reference}' revision"
provider.revision = reference
else
notice "Creating repository from latest"
provider.create
end
end
def retrieve
prov = @resource.provider
if prov
if prov.working_copy_exists?
(@should.include?(:latest) && prov.latest?) ? :latest : :present
elsif prov.class.feature?(:bare_repositories) and prov.bare_exists?
:bare
else
:absent
end
else
raise Puppet::Error, "Could not find provider"
end
end
end
newparam :path do
desc "Absolute path to repository"
isnamevar
validate do |value|
path = Pathname.new(value)
unless path.absolute?
raise ArgumentError, "Path must be absolute: #{path}"
end
end
end
newparam :source do
desc "The source URI for the repository"
end
newparam :fstype, :required_features => [:filesystem_types] do
desc "Filesystem type"
end
newproperty :revision do
desc "The revision of the repository"
newvalue(/^\S+$/)
end
newparam :owner do
desc "The user/uid that owns the repository files"
end
newparam :group do
desc "The group/gid that owns the repository files"
end
newparam :user do
desc "The user to run for repository operations"
end
newparam :excludes do
desc "Files to be excluded from the repository"
end
newparam :force do
desc "Force repository creation, destroying any files on the path in the process."
newvalues(:true, :false)
defaultto false
end
newparam :compression, :required_features => [:gzip_compression] do
desc "Compression level"
validate do |amount|
unless Integer(amount).between?(0, 6)
raise ArgumentError, "Unsupported compression level: #{amount} (expected 0-6)"
end
end
end
newparam :basic_auth_username, :required_features => [:basic_auth] do
desc "HTTP Basic Auth username"
end
newparam :basic_auth_password, :required_features => [:basic_auth] do
desc "HTTP Basic Auth password"
end
newparam :identity, :required_features => [:ssh_identity] do
desc "SSH identity file"
end
newparam :module, :required_features => [:modules] do
desc "The repository module to manage"
end
newparam :remote, :required_features => [:multiple_remotes] do
desc "The remote repository to track"
defaultto "origin"
end
end
require 'pathname'
Puppet::Type.newtype(:vcsrepo) do
desc "A local version control repository"
feature :gzip_compression,
"The provider supports explicit GZip compression levels"
feature :basic_auth,
"The provider supports HTTP Basic Authentication"
feature :bare_repositories,
"The provider differentiates between bare repositories
and those with working copies",
:methods => [:bare_exists?, :working_copy_exists?]
feature :filesystem_types,
"The provider supports different filesystem types"
feature :reference_tracking,
"The provider supports tracking revision references that can change
over time (eg, some VCS tags and branch names)"
feature :ssh_identity,
"The provider supports a configurable SSH identity file"
feature :user,
"The provider can run as a different user"
feature :modules,
"The repository contains modules that can be chosen of"
feature :multiple_remotes,
"The repository tracks multiple remote repositories"
ensurable do
attr_accessor :latest
def insync?(is)
@should ||= []
case should
when :present
return true unless [:absent, :purged, :held].include?(is)
when :latest
if is == :latest
return true
else
return false
end
when :bare
return is == :bare
end
end
newvalue :present do
notice "Creating repository from present"
provider.create
end
newvalue :bare, :required_features => [:bare_repositories] do
if !provider.exists?
provider.create
end
end
newvalue :absent do
provider.destroy
end
newvalue :latest, :required_features => [:reference_tracking] do
if provider.exists?
if provider.respond_to?(:update_references)
provider.update_references
end
if provider.respond_to?(:latest?)
reference = provider.latest || provider.revision
else
reference = resource.value(:revision) || provider.revision
end
notice "Updating to latest '#{reference}' revision"
provider.revision = reference
else
notice "Creating repository from latest"
provider.create
end
end
def retrieve
prov = @resource.provider
if prov
if prov.working_copy_exists?
(@should.include?(:latest) && prov.latest?) ? :latest : :present
elsif prov.class.feature?(:bare_repositories) and prov.bare_exists?
:bare
else
:absent
end
else
raise Puppet::Error, "Could not find provider"
end
end
end
newparam :path do
desc "Absolute path to repository"
isnamevar
validate do |value|
path = Pathname.new(value)
unless path.absolute?
raise ArgumentError, "Path must be absolute: #{path}"
end
end
end
newparam :source do
desc "The source URI for the repository"
end
newparam :fstype, :required_features => [:filesystem_types] do
desc "Filesystem type"
end
newproperty :revision do
desc "The revision of the repository"
newvalue(/^\S+$/)
end
newparam :owner do
desc "The user/uid that owns the repository files"
end
newparam :group do
desc "The group/gid that owns the repository files"
end
newparam :user do
desc "The user to run for repository operations"
end
newparam :excludes do
desc "Files to be excluded from the repository"
end
newparam :force do
desc "Force repository creation, destroying any files on the path in the process."
newvalues(:true, :false)
defaultto false
end
newparam :compression, :required_features => [:gzip_compression] do
desc "Compression level"
validate do |amount|
unless Integer(amount).between?(0, 6)
raise ArgumentError, "Unsupported compression level: #{amount} (expected 0-6)"
end
end
end
newparam :basic_auth_username, :required_features => [:basic_auth] do
desc "HTTP Basic Auth username"
end
newparam :basic_auth_password, :required_features => [:basic_auth] do
desc "HTTP Basic Auth password"
end
newparam :identity, :required_features => [:ssh_identity] do
desc "SSH identity file"
end
newparam :module, :required_features => [:modules] do
desc "The repository module to manage"
end
newparam :remote, :required_features => [:multiple_remotes] do
desc "The remote repository to track"
defaultto "origin"
end
end

View File

@@ -1,5 +1,5 @@
revision-id: menesis@pov.lt-20100309191856-4wmfqzc803fj300x
date: 2010-03-09 21:18:56 +0200
build-date: 2010-03-14 00:42:43 -0800
revno: 2634
branch-nick: mytest
revision-id: menesis@pov.lt-20100309191856-4wmfqzc803fj300x
date: 2010-03-09 21:18:56 +0200
build-date: 2010-03-14 00:42:43 -0800
revno: 2634
branch-nick: mytest

View File

@@ -1,14 +1,14 @@
feature/foo
feature/bar
feature/baz
feature/quux
only/local
* master
refactor/foo
origin/HEAD
origin/feature/foo
origin/feature/bar
origin/feature/baz
origin/feature/quux
origin/only/remote
origin/master
feature/foo
feature/bar
feature/baz
feature/quux
only/local
* master
refactor/foo
origin/HEAD
origin/feature/foo
origin/feature/bar
origin/feature/baz
origin/feature/quux
origin/only/remote
origin/master

View File

@@ -1,6 +1,6 @@
changeset: 3:34e6012c783a
parent: 2:21ea4598c962
parent: 1:9d0ff0028458
user: Test User <test.user@example.com>
date: Fri Aug 07 13:13:02 2009 -0400
summary: merge
changeset: 3:34e6012c783a
parent: 2:21ea4598c962
parent: 1:9d0ff0028458
user: Test User <test.user@example.com>
date: Fri Aug 07 13:13:02 2009 -0400
summary: merge

View File

@@ -1,18 +1,18 @@
tip 1019:bca3f20b249b
0.9.1 1017:76ce7cca95d8
0.9 1001:dbaa6f4ec585
0.8 839:65b66ac0fc83
0.7.1 702:e1357f00129f
0.7 561:7b2af3b4c968
0.6.3 486:e38077f4e4aa
0.6.2 405:07bb099b7b10
0.6.1 389:93750f3fbbe2
0.6 369:34e6012c783a
0.5.3 321:5ffa6ae7e699
0.5.2 318:fdc2c2e4cebe
0.5.1 315:33a5ea0cbe7a
0.5 313:47490716f4c9
0.4 240:47fa3a14cc63
0.3.1 132:bc231db18e1c
0.3 130:661615e510dd
0.2 81:f98d13b442f6
tip 1019:bca3f20b249b
0.9.1 1017:76ce7cca95d8
0.9 1001:dbaa6f4ec585
0.8 839:65b66ac0fc83
0.7.1 702:e1357f00129f
0.7 561:7b2af3b4c968
0.6.3 486:e38077f4e4aa
0.6.2 405:07bb099b7b10
0.6.1 389:93750f3fbbe2
0.6 369:34e6012c783a
0.5.3 321:5ffa6ae7e699
0.5.2 318:fdc2c2e4cebe
0.5.1 315:33a5ea0cbe7a
0.5 313:47490716f4c9
0.4 240:47fa3a14cc63
0.3.1 132:bc231db18e1c
0.3 130:661615e510dd
0.2 81:f98d13b442f6

View File

@@ -1,10 +1,10 @@
Path: .
URL: http://example.com/svn/trunk
Repository Root: http://example.com/svn
Repository UUID: 75246ace-e253-0410-96dd-a7613ca8dc81
Revision: 4
Node Kind: directory
Schedule: normal
Last Changed Author: jon
Last Changed Rev: 3
Last Changed Date: 2008-08-07 11:34:25 -0700 (Thu, 07 Aug 2008)
Path: .
URL: http://example.com/svn/trunk
Repository Root: http://example.com/svn
Repository UUID: 75246ace-e253-0410-96dd-a7613ca8dc81
Revision: 4
Node Kind: directory
Schedule: normal
Last Changed Author: jon
Last Changed Rev: 3
Last Changed Date: 2008-08-07 11:34:25 -0700 (Thu, 07 Aug 2008)

View File

@@ -1,6 +1,6 @@
--format
s
--colour
--loadby
mtime
--backtrace
--format
s
--colour
--loadby
mtime
--backtrace

View File

@@ -1,25 +1,25 @@
require 'pathname'
dir = Pathname.new(__FILE__).parent
$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib')
require 'test/unit'
require 'mocha'
require 'puppet'
gem 'rspec', '>= 1.2.9'
require 'spec/autorun'
Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each do |support_file|
require support_file
end
Spec::Runner.configure do |config|
config.mock_with :mocha
config.include(FixtureHelpers)
config.include(FilesystemHelpers)
end
# We need this because the RAL uses 'should' as a method. This
# allows us the same behaviour but with a different method name.
class Object
alias :must :should
end
require 'pathname'
dir = Pathname.new(__FILE__).parent
$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib')
require 'test/unit'
require 'mocha'
require 'puppet'
gem 'rspec', '>= 1.2.9'
require 'spec/autorun'
Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each do |support_file|
require support_file
end
Spec::Runner.configure do |config|
config.mock_with :mocha
config.include(FixtureHelpers)
config.include(FilesystemHelpers)
end
# We need this because the RAL uses 'should' as a method. This
# allows us the same behaviour but with a different method name.
class Object
alias :must :should
end

View File

@@ -1,18 +1,18 @@
module FilesystemHelpers
def expects_chdir(path = resource.value(:path))
Dir.expects(:chdir).with(path).at_least_once.yields
end
def expects_mkdir(path = resource.value(:path))
Dir.expects(:mkdir).with(path).at_least_once
end
def expects_rm_rf(path = resource.value(:path))
FileUtils.expects(:rm_rf).with(path)
end
def expects_directory?(returns = true, path = resource.value(:path))
File.expects(:directory?).with(path).returns(returns)
end
end
module FilesystemHelpers
def expects_chdir(path = resource.value(:path))
Dir.expects(:chdir).with(path).at_least_once.yields
end
def expects_mkdir(path = resource.value(:path))
Dir.expects(:mkdir).with(path).at_least_once
end
def expects_rm_rf(path = resource.value(:path))
FileUtils.expects(:rm_rf).with(path)
end
def expects_directory?(returns = true, path = resource.value(:path))
File.expects(:directory?).with(path).returns(returns)
end
end

View File

@@ -1,7 +1,7 @@
module FixtureHelpers
def fixture(name, ext = '.txt')
File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', name.to_s + ext))
end
end
module FixtureHelpers
def fixture(name, ext = '.txt')
File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', name.to_s + ext))
end
end

View File

@@ -1,80 +1,80 @@
class ProviderExampleGroup < Spec::Example::ExampleGroup
# Allow access to the current resource
attr_reader :resource
# Build up the values for the resource in this scope
before :each do
resource_hash = example_group_hierarchy.inject({}) do |memo, klass|
memo.merge(klass.options[:resource] || {})
end
full_hash = resource_hash.merge(:provider => described_class.name)
@resource = described_class.resource_type.new(full_hash)
end
# Build the provider
subject { described_class.new(@resource) }
# Allow access to it via +provider+
alias :provider :subject
# Generate a context for a provider operating on a resource with:
#
# call-seq:
#
# # A parameter/property set (when the value isn't important)
# resource_with :source do
# # ...
# end
#
# # A parameter/property set to a specific value
# resource_with :source => 'a-specific-value' do
# # ...
# end
#
# Note: Choose one or the other (mixing will create two separate contexts)
#
def self.resource_with(*params, &block)
params_with_values = params.last.is_a?(Hash) ? params.pop : {}
build_value_context(params_with_values, &block)
build_existence_context(*params, &block)
end
def self.build_existence_context(*params, &block) #:nodoc:
unless params.empty?
text = params.join(', ')
placeholders = params.inject({}) { |memo, key| memo.merge(key => 'an-unimportant-value') }
context("and with a #{text}", {:resource => placeholders}, &block)
end
end
def self.build_value_context(params = {}, &block) #:nodoc:
unless params.empty?
text = params.map { |k, v| "#{k} => #{v.inspect}" }.join(' and with ')
context("and with #{text}", {:resource => params}, &block)
end
end
# Generate a context for a provider operating on a resource without
# a given parameter/property.
#
# call-seq:
#
# resource_without :source do
# # ...
# end
#
def self.resource_without(field, &block)
context("and without a #{field}", &block)
end
end
Spec::Example::ExampleGroupFactory.register(:provider, ProviderExampleGroup)
# Outside wrapper to lookup a provider and start the spec using ProviderExampleGroup
def describe_provider(type_name, provider_name, options = {}, &block)
provider_class = Puppet::Type.type(type_name).provider(provider_name)
describe(provider_class, options.merge(:type => :provider), &block)
end
class ProviderExampleGroup < Spec::Example::ExampleGroup
# Allow access to the current resource
attr_reader :resource
# Build up the values for the resource in this scope
before :each do
resource_hash = example_group_hierarchy.inject({}) do |memo, klass|
memo.merge(klass.options[:resource] || {})
end
full_hash = resource_hash.merge(:provider => described_class.name)
@resource = described_class.resource_type.new(full_hash)
end
# Build the provider
subject { described_class.new(@resource) }
# Allow access to it via +provider+
alias :provider :subject
# Generate a context for a provider operating on a resource with:
#
# call-seq:
#
# # A parameter/property set (when the value isn't important)
# resource_with :source do
# # ...
# end
#
# # A parameter/property set to a specific value
# resource_with :source => 'a-specific-value' do
# # ...
# end
#
# Note: Choose one or the other (mixing will create two separate contexts)
#
def self.resource_with(*params, &block)
params_with_values = params.last.is_a?(Hash) ? params.pop : {}
build_value_context(params_with_values, &block)
build_existence_context(*params, &block)
end
def self.build_existence_context(*params, &block) #:nodoc:
unless params.empty?
text = params.join(', ')
placeholders = params.inject({}) { |memo, key| memo.merge(key => 'an-unimportant-value') }
context("and with a #{text}", {:resource => placeholders}, &block)
end
end
def self.build_value_context(params = {}, &block) #:nodoc:
unless params.empty?
text = params.map { |k, v| "#{k} => #{v.inspect}" }.join(' and with ')
context("and with #{text}", {:resource => params}, &block)
end
end
# Generate a context for a provider operating on a resource without
# a given parameter/property.
#
# call-seq:
#
# resource_without :source do
# # ...
# end
#
def self.resource_without(field, &block)
context("and without a #{field}", &block)
end
end
Spec::Example::ExampleGroupFactory.register(:provider, ProviderExampleGroup)
# Outside wrapper to lookup a provider and start the spec using ProviderExampleGroup
def describe_provider(type_name, provider_name, options = {}, &block)
provider_class = Puppet::Type.type(type_name).provider(provider_name)
describe(provider_class, options.merge(:type => :provider), &block)
end

View File

@@ -1,90 +1,90 @@
require 'spec_helper'
describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do
describe 'creating' do
resource_with :source do
resource_with :revision do
it "should execute 'bzr clone -r' with the revision" do
provider.expects(:bzr).with('branch', '-r', resource.value(:revision), resource.value(:source), resource.value(:path))
provider.create
end
end
resource_without :revision do
it "should just execute 'bzr clone' without a revision" do
provider.expects(:bzr).with('branch', resource.value(:source), resource.value(:path))
provider.create
end
end
end
resource_without :source do
it "should execute 'bzr init'" do
provider.expects(:bzr).with('init', resource.value(:path))
provider.create
end
end
end
describe 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
it "should check for the directory" do
expects_directory?(true, File.join(resource.value(:path), '.bzr'))
provider.exists?
end
end
describe "checking the revision property" do
before do
expects_chdir
provider.expects(:bzr).with('version-info').returns(fixture(:bzr_version_info))
@current_revid = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'
end
context "when given a non-revid as the resource revision", :resource => {:revision => '2634'} do
context "when its revid is not different than the current revid" do
before do
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("#{resource.value(:revision)} menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n")
end
it "should return the ref" do
provider.revision.should == resource.value(:revision)
end
end
context "when its revid is different than the current revid", :resource => {:revision => '2636'} do
it "should return the current revid" do
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2635 foo\n")
provider.revision.should == @current_revid
end
end
end
context "when given a revid as the resource revision" do
context "when it is the same as the current revid", :resource => {:revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'} do
before do
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n")
end
it "should return it" do
provider.revision.should == resource.value(:revision)
end
end
context "when it is not the same as the current revid", :resource => {:revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y'} do
it "should return the current revid" do
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2636 foo\n")
provider.revision.should == @current_revid
end
end
end
end
describe "setting the revision property" do
it "should use 'bzr update -r' with the revision" do
expects_chdir
provider.expects(:bzr).with('update', '-r', 'somerev')
provider.revision = 'somerev'
end
end
end
require 'spec_helper'
describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do
describe 'creating' do
resource_with :source do
resource_with :revision do
it "should execute 'bzr clone -r' with the revision" do
provider.expects(:bzr).with('branch', '-r', resource.value(:revision), resource.value(:source), resource.value(:path))
provider.create
end
end
resource_without :revision do
it "should just execute 'bzr clone' without a revision" do
provider.expects(:bzr).with('branch', resource.value(:source), resource.value(:path))
provider.create
end
end
end
resource_without :source do
it "should execute 'bzr init'" do
provider.expects(:bzr).with('init', resource.value(:path))
provider.create
end
end
end
describe 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
it "should check for the directory" do
expects_directory?(true, File.join(resource.value(:path), '.bzr'))
provider.exists?
end
end
describe "checking the revision property" do
before do
expects_chdir
provider.expects(:bzr).with('version-info').returns(fixture(:bzr_version_info))
@current_revid = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'
end
context "when given a non-revid as the resource revision", :resource => {:revision => '2634'} do
context "when its revid is not different than the current revid" do
before do
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("#{resource.value(:revision)} menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n")
end
it "should return the ref" do
provider.revision.should == resource.value(:revision)
end
end
context "when its revid is different than the current revid", :resource => {:revision => '2636'} do
it "should return the current revid" do
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2635 foo\n")
provider.revision.should == @current_revid
end
end
end
context "when given a revid as the resource revision" do
context "when it is the same as the current revid", :resource => {:revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'} do
before do
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n")
end
it "should return it" do
provider.revision.should == resource.value(:revision)
end
end
context "when it is not the same as the current revid", :resource => {:revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y'} do
it "should return the current revid" do
provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2636 foo\n")
provider.revision.should == @current_revid
end
end
end
end
describe "setting the revision property" do
it "should use 'bzr update -r' with the revision" do
expects_chdir
provider.expects(:bzr).with('update', '-r', 'somerev')
provider.revision = 'somerev'
end
end
end

View File

@@ -1,100 +1,100 @@
require 'spec_helper'
describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do
describe 'creating' do
context "with a source", :resource => {:source => ':ext:source@example.com:/foo/bar'} do
resource_with :revision do
it "should execute 'cvs checkout' and 'cvs update -r'" do
provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'vcsrepo', 'bar')
expects_chdir(File.dirname(resource.value(:path)))
#provider.expects(:cvs).with('update', '-r', resource.value(:revision), '.')
provider.create
end
end
resource_without :revision do
it "should just execute 'cvs checkout' without a revision" do
provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
provider.create
end
end
context "with a compression", :resource => {:compression => '3'} do
it "should just execute 'cvs checkout' without a revision" do
provider.expects(:cvs).with('-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
provider.create
end
end
end
context "when a source is not given" do
it "should execute 'cvs init'" do
provider.expects(:cvs).with('-d', resource.value(:path), 'init')
provider.create
end
end
end
describe 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
resource_with :source do
it "should check for the CVS directory" do
File.expects(:directory?).with(File.join(resource.value(:path), 'CVS'))
provider.exists?
end
end
resource_without :source do
it "should check for the CVSROOT directory" do
File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT'))
provider.exists?
end
end
end
describe "checking the revision property" do
before do
@tag_file = File.join(resource.value(:path), 'CVS', 'Tag')
end
context "when CVS/Tag exists" do
before do
@tag = 'TAG'
File.expects(:exist?).with(@tag_file).returns(true)
end
it "should read CVS/Tag" do
File.expects(:read).with(@tag_file).returns("T#{@tag}")
provider.revision.should == @tag
end
end
context "when CVS/Tag does not exist" do
before do
File.expects(:exist?).with(@tag_file).returns(false)
end
it "assumes HEAD" do
provider.revision.should == 'HEAD'
end
end
end
describe "when setting the revision property" do
before do
@tag = 'SOMETAG'
end
it "should use 'cvs update -dr'" do
expects_chdir
provider.expects(:cvs).with('update', '-dr', @tag, '.')
provider.revision = @tag
end
end
end
require 'spec_helper'
describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do
describe 'creating' do
context "with a source", :resource => {:source => ':ext:source@example.com:/foo/bar'} do
resource_with :revision do
it "should execute 'cvs checkout' and 'cvs update -r'" do
provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'vcsrepo', 'bar')
expects_chdir(File.dirname(resource.value(:path)))
#provider.expects(:cvs).with('update', '-r', resource.value(:revision), '.')
provider.create
end
end
resource_without :revision do
it "should just execute 'cvs checkout' without a revision" do
provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
provider.create
end
end
context "with a compression", :resource => {:compression => '3'} do
it "should just execute 'cvs checkout' without a revision" do
provider.expects(:cvs).with('-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
provider.create
end
end
end
context "when a source is not given" do
it "should execute 'cvs init'" do
provider.expects(:cvs).with('-d', resource.value(:path), 'init')
provider.create
end
end
end
describe 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
resource_with :source do
it "should check for the CVS directory" do
File.expects(:directory?).with(File.join(resource.value(:path), 'CVS'))
provider.exists?
end
end
resource_without :source do
it "should check for the CVSROOT directory" do
File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT'))
provider.exists?
end
end
end
describe "checking the revision property" do
before do
@tag_file = File.join(resource.value(:path), 'CVS', 'Tag')
end
context "when CVS/Tag exists" do
before do
@tag = 'TAG'
File.expects(:exist?).with(@tag_file).returns(true)
end
it "should read CVS/Tag" do
File.expects(:read).with(@tag_file).returns("T#{@tag}")
provider.revision.should == @tag
end
end
context "when CVS/Tag does not exist" do
before do
File.expects(:exist?).with(@tag_file).returns(false)
end
it "assumes HEAD" do
provider.revision.should == 'HEAD'
end
end
end
describe "when setting the revision property" do
before do
@tag = 'SOMETAG'
end
it "should use 'cvs update -dr'" do
expects_chdir
provider.expects(:cvs).with('update', '-dr', @tag, '.')
provider.revision = @tag
end
end
end

View File

@@ -1,17 +1,17 @@
require 'spec_helper'
describe_provider :vcsrepo, :dummy, :resource => {:path => '/tmp/vcsrepo'} do
context 'dummy' do
resource_with :source do
resource_with :ensure => :present do
context "with nothing doing", :resource => {:revision => 'foo'} do
it "should raise an exception" do
proc { provider.working_copy_exists? }.should raise_error(RuntimeError)
end
end
end
end
end
end
require 'spec_helper'
describe_provider :vcsrepo, :dummy, :resource => {:path => '/tmp/vcsrepo'} do
context 'dummy' do
resource_with :source do
resource_with :ensure => :present do
context "with nothing doing", :resource => {:revision => 'foo'} do
it "should raise an exception" do
proc { provider.working_copy_exists? }.should raise_error(RuntimeError)
end
end
end
end
end
end

View File

@@ -1,248 +1,248 @@
require 'spec_helper'
describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do
context 'creating' do
resource_with :source do
resource_with :ensure => :present do
context "with a revision that is a remote branch", :resource => {:revision => 'only/remote'} do
it "should execute 'git clone' and 'git checkout -b'" do
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
expects_chdir('/')
expects_chdir
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
end
end
context "with a revision that is not a remote branch", :resource => {:revision => 'a-commit-or-tag'} do
it "should execute 'git clone' and 'git reset --hard'" do
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
expects_chdir('/')
expects_chdir
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
end
end
resource_without :revision do
it "should execute 'git clone' and submodule commands" do
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
provider.create
end
end
end
resource_with :ensure => :bare do
resource_with :revision do
it "should just execute 'git clone --bare'" do
provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path))
provider.create
end
end
resource_without :revision do
it "should just execute 'git clone --bare'" do
provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path))
provider.create
end
end
end
end
context "when a source is not given" do
resource_with :ensure => :present do
context "when the path does not exist" do
it "should execute 'git init'" do
expects_mkdir
expects_chdir
expects_directory?(false)
provider.expects(:bare_exists?).returns(false)
provider.expects(:git).with('init')
provider.create
end
end
context "when the path is a bare repository" do
it "should convert it to a working copy" do
provider.expects(:bare_exists?).returns(true)
provider.expects(:convert_bare_to_working_copy)
provider.create
end
end
context "when the path is not a repository" do
it "should raise an exception" do
provider.expects(:path_exists?).returns(true)
proc { provider.create }.should raise_error(Puppet::Error)
end
end
end
resource_with :ensure => :bare do
context "when the path does not exist" do
it "should execute 'git init --bare'" do
expects_chdir
expects_mkdir
expects_directory?(false)
provider.expects(:working_copy_exists?).returns(false)
provider.expects(:git).with('init', '--bare')
provider.create
end
end
context "when the path is a working copy repository" do
it "should convert it to a bare repository" do
provider.expects(:working_copy_exists?).returns(true)
provider.expects(:convert_working_copy_to_bare)
provider.create
end
end
context "when the path is not a repository" do
it "should raise an exception" do
expects_directory?(true)
proc { provider.create }.should raise_error(Puppet::Error)
end
end
end
end
end
context 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
context "checking the revision property" do
resource_with :revision do
before do
expects_chdir
provider.expects(:git).with('rev-parse', 'HEAD').returns('currentsha')
end
context "when its SHA is not different than the current SHA" do
it "should return the ref" do
provider.expects(:git).with('config', 'remote.origin.url').returns('')
provider.expects(:git).with('fetch', 'origin') # FIXME
provider.expects(:git).with('fetch', '--tags', 'origin')
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
provider.expects(:git).with('tag', '-l').returns("Hello")
provider.revision.should == resource.value(:revision)
end
end
context "when its SHA is different than the current SHA" do
it "should return the current SHA" do
provider.expects(:git).with('config', 'remote.origin.url').returns('')
provider.expects(:git).with('fetch', 'origin') # FIXME
provider.expects(:git).with('fetch', '--tags', 'origin')
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha')
provider.expects(:git).with('tag', '-l').returns("Hello")
provider.revision.should == 'currentsha'
end
end
context "when the source is modified" do
resource_with :source => 'git://git@foo.com/bar.git' do
it "should update the origin url" do
provider.expects(:git).with('config', 'remote.origin.url').returns('old')
provider.expects(:git).with('config', 'remote.origin.url', 'git://git@foo.com/bar.git')
provider.expects(:git).with('fetch', 'origin') # FIXME
provider.expects(:git).with('fetch', '--tags', 'origin')
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
provider.expects(:git).with('tag', '-l').returns("Hello")
provider.revision.should == resource.value(:revision)
end
end
end
end
end
context "setting the revision property" do
before do
expects_chdir
end
context "when it's an existing local branch", :resource => {:revision => 'feature/foo'} do
it "should use 'git fetch' and 'git reset'" do
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
provider.revision = resource.value(:revision)
end
end
context "when it's a remote branch", :resource => {:revision => 'only/remote'} do
it "should use 'git fetch' and 'git reset'" do
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
provider.revision = resource.value(:revision)
end
end
context "when it's a commit or tag", :resource => {:revision => 'a-commit-or-tag'} do
it "should use 'git fetch' and 'git reset'" do
provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
provider.expects(:git).with('submodule', 'init')
provider.expects(:git).with('submodule', 'update')
provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
provider.expects(:git).with('submodule', 'foreach', 'git', 'submodule', 'init')
provider.expects(:git).with('submodule', 'foreach', 'git', 'submodule', 'update')
provider.revision = resource.value(:revision)
end
end
end
context "updating references" do
it "should use 'git fetch --tags'" do
expects_chdir
provider.expects(:git).with('config', 'remote.origin.url').returns('')
provider.expects(:git).with('fetch', 'origin')
provider.expects(:git).with('fetch', '--tags', 'origin')
provider.update_references
end
end
context "checking if revision" do
before do
expects_chdir
provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
end
context "is a local branch" do
context "when it's listed in 'git branch -a'", :resource => {:revision => 'feature/foo'} do
it "should return true" do
provider.should be_local_branch_revision
end
end
context "when it's not listed in 'git branch -a'" , :resource => {:revision => 'feature/notexist'}do
it "should return false" do
provider.should_not be_local_branch_revision
end
end
end
context "is a remote branch" do
context "when it's listed in 'git branch -a' with an 'origin/' prefix", :resource => {:revision => 'only/remote'} do
it "should return true" do
provider.should be_remote_branch_revision
end
end
context "when it's not listed in 'git branch -a' with an 'origin/' prefix" , :resource => {:revision => 'only/local'}do
it "should return false" do
provider.should_not be_remote_branch_revision
end
end
end
end
end
require 'spec_helper'
describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do
context 'creating' do
resource_with :source do
resource_with :ensure => :present do
context "with a revision that is a remote branch", :resource => {:revision => 'only/remote'} do
it "should execute 'git clone' and 'git checkout -b'" do
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
expects_chdir('/')
expects_chdir
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
end
end
context "with a revision that is not a remote branch", :resource => {:revision => 'a-commit-or-tag'} do
it "should execute 'git clone' and 'git reset --hard'" do
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
expects_chdir('/')
expects_chdir
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
end
end
resource_without :revision do
it "should execute 'git clone' and submodule commands" do
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
provider.create
end
end
end
resource_with :ensure => :bare do
resource_with :revision do
it "should just execute 'git clone --bare'" do
provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path))
provider.create
end
end
resource_without :revision do
it "should just execute 'git clone --bare'" do
provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path))
provider.create
end
end
end
end
context "when a source is not given" do
resource_with :ensure => :present do
context "when the path does not exist" do
it "should execute 'git init'" do
expects_mkdir
expects_chdir
expects_directory?(false)
provider.expects(:bare_exists?).returns(false)
provider.expects(:git).with('init')
provider.create
end
end
context "when the path is a bare repository" do
it "should convert it to a working copy" do
provider.expects(:bare_exists?).returns(true)
provider.expects(:convert_bare_to_working_copy)
provider.create
end
end
context "when the path is not a repository" do
it "should raise an exception" do
provider.expects(:path_exists?).returns(true)
proc { provider.create }.should raise_error(Puppet::Error)
end
end
end
resource_with :ensure => :bare do
context "when the path does not exist" do
it "should execute 'git init --bare'" do
expects_chdir
expects_mkdir
expects_directory?(false)
provider.expects(:working_copy_exists?).returns(false)
provider.expects(:git).with('init', '--bare')
provider.create
end
end
context "when the path is a working copy repository" do
it "should convert it to a bare repository" do
provider.expects(:working_copy_exists?).returns(true)
provider.expects(:convert_working_copy_to_bare)
provider.create
end
end
context "when the path is not a repository" do
it "should raise an exception" do
expects_directory?(true)
proc { provider.create }.should raise_error(Puppet::Error)
end
end
end
end
end
context 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
context "checking the revision property" do
resource_with :revision do
before do
expects_chdir
provider.expects(:git).with('rev-parse', 'HEAD').returns('currentsha')
end
context "when its SHA is not different than the current SHA" do
it "should return the ref" do
provider.expects(:git).with('config', 'remote.origin.url').returns('')
provider.expects(:git).with('fetch', 'origin') # FIXME
provider.expects(:git).with('fetch', '--tags', 'origin')
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
provider.expects(:git).with('tag', '-l').returns("Hello")
provider.revision.should == resource.value(:revision)
end
end
context "when its SHA is different than the current SHA" do
it "should return the current SHA" do
provider.expects(:git).with('config', 'remote.origin.url').returns('')
provider.expects(:git).with('fetch', 'origin') # FIXME
provider.expects(:git).with('fetch', '--tags', 'origin')
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha')
provider.expects(:git).with('tag', '-l').returns("Hello")
provider.revision.should == 'currentsha'
end
end
context "when the source is modified" do
resource_with :source => 'git://git@foo.com/bar.git' do
it "should update the origin url" do
provider.expects(:git).with('config', 'remote.origin.url').returns('old')
provider.expects(:git).with('config', 'remote.origin.url', 'git://git@foo.com/bar.git')
provider.expects(:git).with('fetch', 'origin') # FIXME
provider.expects(:git).with('fetch', '--tags', 'origin')
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
provider.expects(:git).with('tag', '-l').returns("Hello")
provider.revision.should == resource.value(:revision)
end
end
end
end
end
context "setting the revision property" do
before do
expects_chdir
end
context "when it's an existing local branch", :resource => {:revision => 'feature/foo'} do
it "should use 'git fetch' and 'git reset'" do
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
provider.revision = resource.value(:revision)
end
end
context "when it's a remote branch", :resource => {:revision => 'only/remote'} do
it "should use 'git fetch' and 'git reset'" do
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.expects(:git).with('branch', '-a').returns(resource.value(:revision))
provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
provider.revision = resource.value(:revision)
end
end
context "when it's a commit or tag", :resource => {:revision => 'a-commit-or-tag'} do
it "should use 'git fetch' and 'git reset'" do
provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
provider.expects(:git).with('submodule', 'init')
provider.expects(:git).with('submodule', 'update')
provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
provider.expects(:git).with('submodule', 'foreach', 'git', 'submodule', 'init')
provider.expects(:git).with('submodule', 'foreach', 'git', 'submodule', 'update')
provider.revision = resource.value(:revision)
end
end
end
context "updating references" do
it "should use 'git fetch --tags'" do
expects_chdir
provider.expects(:git).with('config', 'remote.origin.url').returns('')
provider.expects(:git).with('fetch', 'origin')
provider.expects(:git).with('fetch', '--tags', 'origin')
provider.update_references
end
end
context "checking if revision" do
before do
expects_chdir
provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
end
context "is a local branch" do
context "when it's listed in 'git branch -a'", :resource => {:revision => 'feature/foo'} do
it "should return true" do
provider.should be_local_branch_revision
end
end
context "when it's not listed in 'git branch -a'" , :resource => {:revision => 'feature/notexist'}do
it "should return false" do
provider.should_not be_local_branch_revision
end
end
end
context "is a remote branch" do
context "when it's listed in 'git branch -a' with an 'origin/' prefix", :resource => {:revision => 'only/remote'} do
it "should return true" do
provider.should be_remote_branch_revision
end
end
context "when it's not listed in 'git branch -a' with an 'origin/' prefix" , :resource => {:revision => 'only/local'}do
it "should return false" do
provider.should_not be_remote_branch_revision
end
end
end
end
end

View File

@@ -1,104 +1,104 @@
require 'spec_helper'
describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do
describe 'creating' do
resource_with :source do
resource_with :revision do
it "should execute 'hg clone -u' with the revision" do
provider.expects(:hg).with('clone', '-u',
resource.value(:revision),
resource.value(:source),
resource.value(:path))
provider.create
end
end
resource_without :revision do
it "should just execute 'hg clone' without a revision" do
provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path))
provider.create
end
end
end
context "when a source is not given" do
it "should execute 'hg init'" do
provider.expects(:hg).with('init', resource.value(:path))
provider.create
end
end
end
describe 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
it "should check for the directory" do
expects_directory?(true, File.join(resource.value(:path), '.hg'))
provider.exists?
end
end
describe "checking the revision property" do
before do
expects_chdir
end
context "when given a non-SHA as the resource revision" do
before do
provider.expects(:hg).with('parents').returns(fixture(:hg_parents))
provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
end
context "when its SHA is not different than the current SHA", :resource => {:revision => '0.6'} do
it "should return the ref" do
provider.revision.should == '0.6'
end
end
context "when its SHA is different than the current SHA", :resource => {:revision => '0.5.3'} do
it "should return the current SHA" do
provider.revision.should == '34e6012c783a'
end
end
end
context "when given a SHA as the resource revision" do
before do
provider.expects(:hg).with('parents').returns(fixture(:hg_parents))
end
context "when it is the same as the current SHA", :resource => {:revision => '34e6012c783a'} do
it "should return it" do
provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
provider.revision.should == resource.value(:revision)
end
end
context "when it is not the same as the current SHA", :resource => {:revision => 'not-the-same'} do
it "should return the current SHA" do
provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
provider.revision.should == '34e6012c783a'
end
end
end
end
describe "setting the revision property" do
before do
@revision = '6aa99e9b3ab1'
end
it "should use 'hg update ---clean -r'" do
expects_chdir
provider.expects(:hg).with('pull')
provider.expects(:hg).with('merge')
provider.expects(:hg).with('update', '--clean', '-r', @revision)
provider.revision = @revision
end
end
end
require 'spec_helper'
describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do
describe 'creating' do
resource_with :source do
resource_with :revision do
it "should execute 'hg clone -u' with the revision" do
provider.expects(:hg).with('clone', '-u',
resource.value(:revision),
resource.value(:source),
resource.value(:path))
provider.create
end
end
resource_without :revision do
it "should just execute 'hg clone' without a revision" do
provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path))
provider.create
end
end
end
context "when a source is not given" do
it "should execute 'hg init'" do
provider.expects(:hg).with('init', resource.value(:path))
provider.create
end
end
end
describe 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
it "should check for the directory" do
expects_directory?(true, File.join(resource.value(:path), '.hg'))
provider.exists?
end
end
describe "checking the revision property" do
before do
expects_chdir
end
context "when given a non-SHA as the resource revision" do
before do
provider.expects(:hg).with('parents').returns(fixture(:hg_parents))
provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
end
context "when its SHA is not different than the current SHA", :resource => {:revision => '0.6'} do
it "should return the ref" do
provider.revision.should == '0.6'
end
end
context "when its SHA is different than the current SHA", :resource => {:revision => '0.5.3'} do
it "should return the current SHA" do
provider.revision.should == '34e6012c783a'
end
end
end
context "when given a SHA as the resource revision" do
before do
provider.expects(:hg).with('parents').returns(fixture(:hg_parents))
end
context "when it is the same as the current SHA", :resource => {:revision => '34e6012c783a'} do
it "should return it" do
provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
provider.revision.should == resource.value(:revision)
end
end
context "when it is not the same as the current SHA", :resource => {:revision => 'not-the-same'} do
it "should return the current SHA" do
provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
provider.revision.should == '34e6012c783a'
end
end
end
end
describe "setting the revision property" do
before do
@revision = '6aa99e9b3ab1'
end
it "should use 'hg update ---clean -r'" do
expects_chdir
provider.expects(:hg).with('pull')
provider.expects(:hg).with('merge')
provider.expects(:hg).with('update', '--clean', '-r', @revision)
provider.revision = @revision
end
end
end

View File

@@ -1,78 +1,78 @@
require 'spec_helper'
describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do
describe 'creating' do
resource_with :source do
resource_with :revision do
it "should execute 'svn checkout' with a revision" do
provider.expects(:svn).with('--non-interactive', 'checkout', '-r',
resource.value(:revision),
resource.value(:source),
resource.value(:path))
provider.create
end
end
resource_without :revision do
it "should just execute 'svn checkout' without a revision" do
provider.expects(:svn).with('--non-interactive', 'checkout',
resource.value(:source),
resource.value(:path))
provider.create
end
end
end
resource_without :source do
resource_with :fstype do
it "should execute 'svnadmin create' with an '--fs-type' option" do
provider.expects(:svnadmin).with('create', '--fs-type',
resource.value(:fstype),
resource.value(:path))
provider.create
end
end
resource_without :fstype do
it "should execute 'svnadmin create' without an '--fs-type' option" do
provider.expects(:svnadmin).with('create', resource.value(:path))
provider.create
end
end
end
end
describe 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
it "should check for the directory" do
expects_directory?(true, File.join(resource.value(:path), '.svn'))
provider.exists?
end
end
describe "checking the revision property" do
before do
provider.expects(:svn).with('--non-interactive', 'info').returns(fixture(:svn_info))
end
it "should use 'svn info'" do
expects_chdir
provider.revision.should == '3' # From 'Last Changed Rev', not 'Revision'
end
end
describe "setting the revision property" do
before do
@revision = '30'
end
it "should use 'svn update'" do
expects_chdir
provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision)
provider.revision = @revision
end
end
end
require 'spec_helper'
describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do
describe 'creating' do
resource_with :source do
resource_with :revision do
it "should execute 'svn checkout' with a revision" do
provider.expects(:svn).with('--non-interactive', 'checkout', '-r',
resource.value(:revision),
resource.value(:source),
resource.value(:path))
provider.create
end
end
resource_without :revision do
it "should just execute 'svn checkout' without a revision" do
provider.expects(:svn).with('--non-interactive', 'checkout',
resource.value(:source),
resource.value(:path))
provider.create
end
end
end
resource_without :source do
resource_with :fstype do
it "should execute 'svnadmin create' with an '--fs-type' option" do
provider.expects(:svnadmin).with('create', '--fs-type',
resource.value(:fstype),
resource.value(:path))
provider.create
end
end
resource_without :fstype do
it "should execute 'svnadmin create' without an '--fs-type' option" do
provider.expects(:svnadmin).with('create', resource.value(:path))
provider.create
end
end
end
end
describe 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
describe "checking existence" do
it "should check for the directory" do
expects_directory?(true, File.join(resource.value(:path), '.svn'))
provider.exists?
end
end
describe "checking the revision property" do
before do
provider.expects(:svn).with('--non-interactive', 'info').returns(fixture(:svn_info))
end
it "should use 'svn info'" do
expects_chdir
provider.revision.should == '3' # From 'Last Changed Rev', not 'Revision'
end
end
describe "setting the revision property" do
before do
@revision = '30'
end
it "should use 'svn update'" do
expects_chdir
provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision)
provider.revision = @revision
end
end
end

View File

@@ -1,4 +1,4 @@
Resource Type Specs
===================
Define specs for your resource types in this directory.
Resource Type Specs
===================
Define specs for your resource types in this directory.