Basic Bazaar support
[puppet_vcsrepo.git] / spec / unit / puppet / provider / vcsrepo / bzr_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(:bzr)
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     before do
15       @resource.expects(:value).with(:path).returns(@path).at_least_once
16     end
17     context "when a source is given" do
18       before do
19         @source = 'http://example.com/bzr/repo'
20         @resource.expects(:value).with(:source).returns(@source).at_least_once
21       end
22       context "and when a revision is given" do
23         before do
24           @revision = 'somerev'
25           @resource.expects(:value).with(:revision).returns(@revision).at_least_once
26         end
27         it "should execute 'bzr clone -r' with the revision" do
28           @provider.expects(:bzr).with('branch', '-r', @revision, @source, @path)
29           @provider.create
30         end
31       end
32       context "and when a revision is not given" do
33         before do
34           @resource.expects(:value).with(:revision).returns(nil).at_least_once
35         end
36         it "should just execute 'bzr clone' without a revision" do
37           @provider.expects(:bzr).with('branch', @source, @path)
38           @provider.create
39         end
40       end
41     end
42     context "when a source is not given" do
43       before do
44         @resource.expects(:value).with(:source).returns(nil).at_least_once
45       end
46       it "should execute 'bzr init'" do
47         @provider.expects(:bzr).with('init', @path)
48         @provider.create
49       end
50     end
51   end
52
53   describe 'when destroying' do
54     it "it should remove the directory" do
55       @resource.expects(:value).with(:path).returns(@path).at_least_once
56       FileUtils.expects(:rm_rf).with(@path)
57       @provider.destroy
58     end
59   end
60
61   describe "when checking existence" do
62     before do
63       @resource.expects(:value).with(:path).returns(@path)
64     end
65     it "should check for the directory" do
66       File.expects(:directory?).with(File.join(@path, '.bzr'))
67       @provider.exists?
68     end
69   end
70
71   describe "when checking the revision property" do
72     before do
73       @resource.expects(:value).with(:path).returns(@path).at_least_once
74       Dir.expects(:chdir).with(@path).yields
75       @provider.expects(:bzr).with('version-info').returns(fixture(:bzr_version_info))
76       @current_revid = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'
77       @current_revno = '2634'
78     end
79     context "when given a non-revid as the resource revision" do
80       context "when its revid is not different than the current revid" do
81         before do
82           @revision = @current_revno
83           @resource.expects(:value).with(:revision).returns(@revision).at_least_once
84         end
85         it "should return the ref" do
86           @provider.expects(:bzr).with('revision-info', @revision).returns("#{@current_revno} #{@current_revid}\n")
87           @provider.revision.should == @revision
88         end
89       end
90       context "when its revid is different than the current revid" do
91         before do
92           @revision = '2636'
93           @resource.expects(:value).with(:revision).returns(@revision).at_least_once
94         end
95         it "should return the current revid" do
96           @provider.expects(:bzr).with('revision-info', @revision).returns("#{@revision} menesis@pov.lt-20100309191856-4wmfqzc803fj300y\n")
97           @provider.revision.should == @current_revid
98         end          
99       end
100     end
101     context "when given a revid as the resource revision" do
102       context "when it is the same as the current revid" do
103         before do
104           @revision = @current_revid
105           @resource.expects(:value).with(:revision).returns(@revision).at_least_once
106         end
107         it "should return it" do
108           @provider.expects(:bzr).with('revision-info', @revision).returns("#{@current_revno} #{@current_revid}\n")
109           @provider.revision.should == @revision
110         end
111       end
112       context "when it is not the same as the current revid" do
113         before do
114           @revision = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y'
115           @resource.expects(:value).with(:revision).returns(@revision).at_least_once
116         end
117         it "should return the current revid" do
118           @provider.expects(:bzr).with('revision-info', @revision).returns("2636 #{@revision}\n")
119           @provider.revision.should == @current_revid
120         end
121       end
122     end
123   end
124   
125   describe "when setting the revision property" do
126     before do
127       @resource.expects(:value).with(:path).returns(@path).at_least_once
128       @revision = 'somerev'
129     end
130     it "should use 'bzr update -r' with the revision" do
131       @provider.expects('bzr').with('update', '-r', @revision, @path)
132       @provider.revision = @revision
133     end
134   end
135
136 end