Convert bare repos to working copy repos and vice-versa
[puppet_vcsrepo.git] / spec / unit / puppet / provider / vcsrepo / svn_spec.rb
1 require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end }
2
3 provider_class = Puppet::Type.type(:vcsrepo).provider(:svn)
4
5 describe provider_class do
6
7   before :each do
8     @resource = stub("resource")
9     @provider = provider_class.new(@resource)
10     @path = '/tmp/vcsrepo'
11   end
12
13   describe 'when creating' do
14     context "when a source is given" do
15       context "and when a revision is given" do
16         it "should execute 'svn checkout' with a revision" do
17           @resource.expects(:value).with(:path).returns(@path).at_least_once
18           @resource.expects(:value).with(:source).returns('svn://example.com/repo').at_least_once
19           @resource.expects(:value).with(:revision).returns('1234').at_least_once
20           @provider.expects(:svn).with('checkout', '-r', '1234', 'svn://example.com/repo', @path)
21           @provider.create
22         end        
23       end
24       context "and when a revision is not given" do
25         it "should just execute 'svn checkout' without a revision" do
26           @resource.expects(:value).with(:path).returns(@path).at_least_once
27           @resource.expects(:value).with(:source).returns('svn://example.com/repo').at_least_once
28           @resource.expects(:value).with(:revision).returns(nil).at_least_once
29           @provider.expects(:svn).with('checkout','svn://example.com/repo', @path)
30           @provider.create
31         end        
32       end
33     end
34     context "when a source is not given" do
35       context "when a fstype is given" do
36         it "should execute 'svnadmin create' with an '--fs-type' option" do
37           @resource.expects(:value).with(:path).returns(@path).at_least_once
38           @resource.expects(:value).with(:fstype).returns('fsfs').at_least_once
39           @resource.expects(:value).with(:source).returns(nil)
40           @provider.expects(:svnadmin).with('create', '--fs-type', 'fsfs', @path)
41           @provider.create
42         end
43       end
44       context "when a fstype is not given" do
45         it "should execute 'svnadmin create' without an '--fs-type' option" do
46           @resource.expects(:value).with(:path).returns(@path).at_least_once
47           @resource.expects(:value).with(:source).returns(nil)
48           @resource.expects(:value).with(:fstype).returns(nil).at_least_once
49           @provider.expects(:svnadmin).with('create', @path)
50           @provider.create
51         end
52       end
53     end
54   end
55
56   describe 'when destroying' do
57     it "it should remove the directory" do
58       @resource.expects(:value).with(:path).returns(@path).at_least_once
59       FileUtils.expects(:rm_rf).with(@path)
60       @provider.destroy
61     end
62   end
63
64   describe "when checking existence" do
65     it "should check for the directory" do
66       @resource.expects(:value).with(:path).returns(@path)
67       File.expects(:directory?).with(@path)
68       @provider.exists?
69     end
70   end
71
72   describe "when checking the revision property" do
73     it "should use 'svn info'" do
74       @resource.expects(:value).with(:path).returns(@path)
75       @provider.expects('svn').with('info').returns(fixture(:svn_info))
76       Dir.expects(:chdir).with(@path).yields
77       @provider.revision.should == '4'
78     end
79   end
80   
81   describe "when setting the revision property" do
82     it "should use 'svn update'" do
83       @resource.expects(:value).with(:path).returns(@path)
84       @provider.expects('svn').with('update', '-r', '30')
85       Dir.expects(:chdir).with(@path).yields
86       @provider.revision = '30'
87     end
88   end
89
90 end