Debian Codegraph @

spec/unit/puppet/provider/vcsrepo/bzr_spec.rb

raw
1 require 'spec_helper'
2
3 describe Puppet::Type.type(:vcsrepo).provider(:bzr_provider) do
4
5 let(:resource) { Puppet::Type.type(:vcsrepo).new({
6 :name => 'test',
7 :ensure => :present,
8 :provider => :bzr,
9 :revision => '2634',
10 :source => 'lp:do',
11 :path => '/tmp/test',
12 })}
13
14 let(:provider) { resource.provider }
15
16 before :each do
17 Puppet::Util.stubs(:which).with('bzr').returns('/usr/bin/bzr')
18 end
19
20 describe 'creating' do
21 context 'with defaults' do
22 it "should execute 'bzr clone -r' with the revision" do
23 provider.expects(:bzr).with('branch', '-r', resource.value(:revision), resource.value(:source), resource.value(:path))
24 provider.create
25 end
26 end
27
28 context 'without revision' do
29 it "should just execute 'bzr clone' without a revision" do
30 resource.delete(:revision)
31 provider.expects(:bzr).with('branch', resource.value(:source), resource.value(:path))
32 provider.create
33 end
34 end
35
36 context 'without source' do
37 it "should execute 'bzr init'" do
38 resource.delete(:source)
39 provider.expects(:bzr).with('init', resource.value(:path))
40 provider.create
41 end
42 end
43 end
44
45 describe 'destroying' do
46 it "it should remove the directory" do
47 provider.destroy
48 end
49 end
50
51 describe "checking existence" do
52 it "should check for the directory" do
53 File.expects(:directory?).with(File.join(resource.value(:path), '.bzr')).returns(true)
54 provider.exists?
55 end
56 end
57
58 describe "checking the revision property" do
59 before do
60 expects_chdir
61 provider.expects(:bzr).with('version-info').returns(File.read(fixtures('bzr_version_info.txt')))
62 @current_revid = '[email protected]'
63 end
64
65 context "when given a non-revid as the resource revision" do
66 context "when its revid is not different than the current revid" do
67 it "should return the ref" do
68 resource[:revision] = '2634'
69 provider.expects(:bzr).with('revision-info', '2634').returns("2634 [email protected]\n")
70 expect(provider.revision).to eq(resource.value(:revision))
71 end
72 end
73 context "when its revid is different than the current revid" do
74 it "should return the current revid" do
75 resource[:revision] = '2636'
76 provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2635 foo\n")
77 expect(provider.revision).to eq(@current_revid)
78 end
79 end
80 end
81
82 context "when given a revid as the resource revision" do
83 context "when it is the same as the current revid" do
84 it "should return it" do
85 resource[:revision] = '[email protected]'
86 provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n")
87 expect(provider.revision).to eq(resource.value(:revision))
88 end
89 end
90 context "when it is not the same as the current revid" do
91 it "should return the current revid" do
92 resource[:revision] = '[email protected]'
93 provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2636 foo\n")
94 expect(provider.revision).to eq(@current_revid)
95 end
96 end
97
98 end
99 end
100
101 describe "setting the revision property" do
102 it "should use 'bzr update -r' with the revision" do
103 Dir.expects(:chdir).with('/tmp/test').at_least_once.yields
104 provider.expects(:bzr).with('update', '-r', 'somerev')
105 provider.revision = 'somerev'
106 end
107 end
108
109 end