summaryrefslogtreecommitdiff
path: root/spec/unit/puppet/provider/vcsrepo/svn_spec.rb
blob: 6a37c205b78eff78a6dff7a79588700a4dbc3959 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
require 'spec_helper'

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

  let(:resource) { Puppet::Type.type(:vcsrepo).new({
    :name     => 'test',
    :ensure   => :present,
    :provider => :svn,
    :path     => '/tmp/vcsrepo',
  })}

  let(:provider) { resource.provider }

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

  describe 'creating' do
    context 'with source and revision' do
      it "should execute 'svn checkout' with a revision" do
        resource[:source] = 'exists'
        resource[:revision] = '1'
        provider.expects(:svn).with('--non-interactive', 'checkout', '-r',
          resource.value(:revision),
          resource.value(:source),
          resource.value(:path))
        provider.create
      end
    end
    context 'with source' do
      it "should just execute 'svn checkout' without a revision" do
        resource[:source] = 'exists'
        provider.expects(:svn).with('--non-interactive', 'checkout',
          resource.value(:source),
          resource.value(:path))
        provider.create
      end
    end

    context 'with fstype' do
      it "should execute 'svnadmin create' with an '--fs-type' option" do
        resource[:fstype] = 'ext4'
        provider.expects(:svnadmin).with('create', '--fs-type',
                                          resource.value(:fstype),
                                          resource.value(:path))
        provider.create
      end
    end
    context 'without fstype' do
      it "should execute 'svnadmin create' without an '--fs-type' option" do
        provider.expects(:svnadmin).with('create', resource.value(:path))
        provider.create
      end
    end
    
    context "with depth" do
      it "should execute 'svn checkout' with a depth" do
        resource[:source] = 'exists'
        resource[:depth] = 'infinity'
        provider.expects(:svn).with('--non-interactive', 'checkout', '--depth', 'infinity',
          resource.value(:source),
          resource.value(:path))
        provider.create
      end
    end
    
    context "with trust_server_cert" do
      it "should execute 'svn checkout' without a trust-server-cert" do
        resource[:source] = 'exists'
        resource[:trust_server_cert] = :false
        provider.expects(:svn).with('--non-interactive', 'checkout',
          resource.value(:source),
          resource.value(:path))
        provider.create
      end
      it "should execute 'svn checkout' with a trust-server-cert" do
        resource[:source] = 'exists'
        resource[:trust_server_cert] = :true
        provider.expects(:svn).with('--non-interactive', '--trust-server-cert', 'checkout',
          resource.value(:source),
          resource.value(:path))
        provider.create
      end
    end
  end

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

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

  describe "checking the revision property" do
    before do
      provider.expects(:svn).with('--non-interactive', 'info').returns(fixture(:svn_info))
    end
    it "should use 'svn info'" do
      expects_chdir
      expect(provider.revision).to eq('4') # From 'Revision', not 'Last Changed Rev'
    end
  end

  describe "setting the revision property" do
    before do
      @revision = '30'
    end
    context 'with conflict' do
      it "should use 'svn update'" do
        resource[:conflict] = 'theirs-full'
        expects_chdir
        provider.expects(:svn).with('--non-interactive', 'update',
                                    '-r', @revision,
                                    '--accept', resource.value(:conflict))
        provider.revision = @revision
      end
    end
    context 'without conflict' do
      it "should use 'svn update'" do
        expects_chdir
        provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision)
        provider.revision = @revision
      end
    end
  end

  describe "setting the revision property and repo source" do
    before do
      @revision = '30'
    end
    context 'with conflict' do
      it "should use 'svn switch'" do
        resource[:source] = 'an-unimportant-value'
        resource[:conflict] = 'theirs-full'
        expects_chdir
        provider.expects(:svn).with('--non-interactive', 'switch',
                                    '-r', @revision, 'an-unimportant-value',
                                    '--accept', resource.value(:conflict))
        provider.revision = @revision
      end
    end
    context 'without conflict' do
      it "should use 'svn switch'" do
        resource[:source] = 'an-unimportant-value'
        expects_chdir
        provider.expects(:svn).with('--non-interactive', 'switch', '-r', @revision, 'an-unimportant-value')
        provider.revision = @revision
      end
    end
  end

end