summaryrefslogtreecommitdiff
path: root/spec/unit/puppet/provider/vcsrepo/svn_spec.rb
blob: 3af06f292f2c05c491aa7130b44e7fc945f51988 (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
require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end }

provider_class = Puppet::Type.type(:vcsrepo).provider(:svn)

describe provider_class do

  before :each do
    @resource = stub("resource")
    @provider = provider_class.new(@resource)
    @path = '/tmp/vcsrepo'
  end

  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