summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorBruce Williams <bruce@codefluency.com>2010-03-12 17:44:19 -0800
committerBruce Williams <bruce@codefluency.com>2010-03-12 17:44:19 -0800
commit350972d6be26cacdcb18875055f9723574312966 (patch)
tree88a2fa8aca3788e17f67691cce66462767bd89ae /spec
parent176b1ec7a4620cae24996609ada33f21cc2eef84 (diff)
Basic SVN provider
Diffstat (limited to 'spec')
-rw-r--r--spec/fixtures/svn_info.txt10
-rw-r--r--spec/spec_helper.rb11
-rw-r--r--spec/unit/puppet/provider/vcsrepo/svn_spec.rb84
3 files changed, 100 insertions, 5 deletions
diff --git a/spec/fixtures/svn_info.txt b/spec/fixtures/svn_info.txt
new file mode 100644
index 0000000..d2a975b
--- /dev/null
+++ b/spec/fixtures/svn_info.txt
@@ -0,0 +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)
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index a4aeeae..1938658 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -7,8 +7,17 @@ require 'puppet'
gem 'rspec', '=1.2.9'
require 'spec/autorun'
+module Helpers
+
+ def fixture(name, ext = '.txt')
+ File.read(File.join(File.dirname(__FILE__), 'fixtures', name.to_s + ext))
+ end
+
+end
+
Spec::Runner.configure do |config|
- config.mock_with :mocha
+ config.mock_with :mocha
+ config.include(Helpers)
end
# We need this because the RAL uses 'should' as a method. This
diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb
index 657913b..3af06f2 100644
--- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb
@@ -4,13 +4,89 @@ provider_class = Puppet::Type.type(:vcsrepo).provider(:svn)
describe provider_class do
- before do
+ before :each do
@resource = stub("resource")
@provider = provider_class.new(@resource)
+ @path = '/tmp/vcsrepo'
end
- describe 'when creating'
- describe 'when updating'
- describe 'when destroying'
+ context 'when creating' do
+ context "when a source is given" do
+ context "and when a revision is given" do
+ it "should execute 'svn checkout' with a revision" do
+ @resource.expects(:value).with(:path).returns(@path).at_least_once
+ @resource.expects(:value).with(:source).returns('svn://example.com/repo').at_least_once
+ @resource.expects(:value).with(:revision).returns('1234').at_least_once
+ @provider.expects(:svn).with('checkout', '-r', '1234', 'svn://example.com/repo', @path)
+ @provider.create
+ end
+ end
+ context "and when a revision is not given" do
+ it "should just execute 'svn checkout' without a revision" do
+ @resource.expects(:value).with(:path).returns(@path).at_least_once
+ @resource.expects(:value).with(:source).returns('svn://example.com/repo').at_least_once
+ @resource.expects(:value).with(:revision).returns(nil).at_least_once
+ @provider.expects(:svn).with('checkout','svn://example.com/repo', @path)
+ @provider.create
+ end
+ end
+ end
+ context "when a source is not given" do
+ context "when a fstype is given" do
+ it "should execute 'svnadmin create' with an '--fs-type' option" do
+ @resource.expects(:value).with(:path).returns(@path).at_least_once
+ @resource.expects(:value).with(:fstype).returns('fsfs').at_least_once
+ @resource.expects(:value).with(:source).returns(nil)
+ @provider.expects(:svnadmin).with('create', '--fs-type', 'fsfs', @path)
+ @provider.create
+ end
+ end
+ context "when a fstype is not given" do
+ it "should execute 'svnadmin create' without an '--fs-type' option" do
+ @resource.expects(:value).with(:path).returns(@path).at_least_once
+ @resource.expects(:value).with(:source).returns(nil)
+ @resource.expects(:value).with(:fstype).returns(nil).at_least_once
+ @provider.expects(:svnadmin).with('create', @path)
+ @provider.create
+ end
+ end
+ end
+ end
+
+ context 'when destroying' do
+ it "it should remove the directory" do
+ @resource.expects(:value).with(:path).returns(@path).at_least_once
+ FileUtils.expects(:rm_rf).with(@path)
+ @provider.destroy
+ end
+ end
+
+ context "when checking existence" do
+ it "should check for the directory" do
+ @resource.expects(:value).with(:path).returns(@path)
+ File.expects(:directory?).with(@path)
+ @provider.exists?
+ end
+ end
+
+ describe "revision property" do
+ context "when checking" do
+ it "should use 'svn info'" do
+ @resource.expects(:value).with(:path).returns(@path)
+ p fixture(:svn_info)[/^Revision:\s+(\d+)/m, 1]
+ @provider.expects('svn').with('info').returns(fixture(:svn_info))
+ Dir.expects(:chdir).with(@path).yields
+ @provider.revision.should == '4'
+ end
+ end
+ context "when setting" do
+ it "should use 'svn update'" do
+ @resource.expects(:value).with(:path).returns(@path)
+ @provider.expects('svn').with('update', '-r', '30')
+ Dir.expects(:chdir).with(@path).yields
+ @provider.revision = '30'
+ end
+ end
+ end
end