summaryrefslogtreecommitdiff
path: root/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb
blob: b5e2f73168edb0509cc539019b0b7df3bdee68be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require 'spec_helper'

describe Puppet::Type.type(:vcsrepo).provider(:bzr_provider) do

  let(:resource) { Puppet::Type.type(:vcsrepo).new({
    :name     => 'test',
    :ensure   => :present,
    :provider => :bzr,
    :revision => '2634',
    :source   => 'lp:do',
    :path     => '/tmp/test',
  })}

  let(:provider) { resource.provider }

  before :each do
    Puppet::Util.stubs(:which).with('bzr').returns('/usr/bin/bzr')
  end

  describe 'creating' do
    context 'with defaults' 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

    context 'without revision' do
      it "should just execute 'bzr clone' without a revision" do
        resource.delete(:revision)
        provider.expects(:bzr).with('branch', resource.value(:source), resource.value(:path))
        provider.create
      end
    end

    context 'without source' do
      it "should execute 'bzr init'" do
        resource.delete(:source)
        provider.expects(:bzr).with('init', resource.value(:path))
        provider.create
      end
    end
  end

  describe 'destroying' do
    it "it should remove the directory" do
      provider.destroy
    end
  end

  describe "checking existence" do
    it "should check for the directory" do
      File.expects(:directory?).with(File.join(resource.value(:path), '.bzr')).returns(true)
      provider.exists?
    end
  end

  describe "checking the revision property" do
    before do
      expects_chdir
      provider.expects(:bzr).with('version-info').returns(File.read(fixtures('bzr_version_info.txt')))
      @current_revid = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'
    end

    context "when given a non-revid as the resource revision" do
      context "when its revid is not different than the current revid" do
        it "should return the ref" do
          resource[:revision] = '2634'
          provider.expects(:bzr).with('revision-info', '2634').returns("2634 menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n")
          expect(provider.revision).to eq(resource.value(:revision))
        end
      end
      context "when its revid is different than the current revid" do
        it "should return the current revid" do
          resource[:revision] = '2636'
          provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2635 foo\n")
          expect(provider.revision).to eq(@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" do
        it "should return it" do
          resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'
          provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n")
          expect(provider.revision).to eq(resource.value(:revision))
        end
      end
      context "when it is not the same as the current revid" do
        it "should return the current revid" do
          resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y'
          provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2636 foo\n")
          expect(provider.revision).to eq(@current_revid)
        end
      end

    end
  end

  describe "setting the revision property" do
    it "should use 'bzr update -r' with the revision" do
      Dir.expects(:chdir).with('/tmp/test').at_least_once.yields
      provider.expects(:bzr).with('update', '-r', 'somerev')
      provider.revision = 'somerev'
    end
  end

end