| 1 |
require 'spec_helper' |
| 2 |
|
| 3 |
describe Puppet::Type.type(:vcsrepo).provider(:svn) do |
| 4 |
|
| 5 |
let(:resource) { Puppet::Type.type(:vcsrepo).new({ |
| 6 |
:name => 'test', |
| 7 |
:ensure => :present, |
| 8 |
:provider => :svn, |
| 9 |
:path => '/tmp/vcsrepo', |
| 10 |
})} |
| 11 |
|
| 12 |
let(:provider) { resource.provider } |
| 13 |
|
| 14 |
before :each do |
| 15 |
Puppet::Util.stubs(:which).with('git').returns('/usr/bin/git') |
| 16 |
end |
| 17 |
|
| 18 |
describe 'creating' do |
| 19 |
context 'with source and revision' do |
| 20 |
it "should execute 'svn checkout' with a revision" do |
| 21 |
resource[:source] = 'exists' |
| 22 |
resource[:revision] = '1' |
| 23 |
provider.expects(:svn).with('--non-interactive', 'checkout', '-r', |
| 24 |
resource.value(:revision), |
| 25 |
resource.value(:source), |
| 26 |
resource.value(:path)) |
| 27 |
provider.create |
| 28 |
end |
| 29 |
end |
| 30 |
context 'with source' do |
| 31 |
it "should just execute 'svn checkout' without a revision" do |
| 32 |
resource[:source] = 'exists' |
| 33 |
provider.expects(:svn).with('--non-interactive', 'checkout', |
| 34 |
resource.value(:source), |
| 35 |
resource.value(:path)) |
| 36 |
provider.create |
| 37 |
end |
| 38 |
end |
| 39 |
|
| 40 |
context 'with fstype' do |
| 41 |
it "should execute 'svnadmin create' with an '--fs-type' option" do |
| 42 |
resource[:fstype] = 'ext4' |
| 43 |
provider.expects(:svnadmin).with('create', '--fs-type', |
| 44 |
resource.value(:fstype), |
| 45 |
resource.value(:path)) |
| 46 |
provider.create |
| 47 |
end |
| 48 |
end |
| 49 |
context 'without fstype' do |
| 50 |
it "should execute 'svnadmin create' without an '--fs-type' option" do |
| 51 |
provider.expects(:svnadmin).with('create', resource.value(:path)) |
| 52 |
provider.create |
| 53 |
end |
| 54 |
end |
| 55 |
end |
| 56 |
|
| 57 |
describe 'destroying' do |
| 58 |
it "it should remove the directory" do |
| 59 |
expects_rm_rf |
| 60 |
provider.destroy |
| 61 |
end |
| 62 |
end |
| 63 |
|
| 64 |
describe "checking existence" do |
| 65 |
it "should check for the directory" do |
| 66 |
expects_directory?(true, resource.value(:path)) |
| 67 |
expects_directory?(true, File.join(resource.value(:path), '.svn')) |
| 68 |
provider.exists? |
| 69 |
end |
| 70 |
end |
| 71 |
|
| 72 |
describe "checking the revision property" do |
| 73 |
before do |
| 74 |
provider.expects(:svn).with('--non-interactive', 'info').returns(fixture(:svn_info)) |
| 75 |
end |
| 76 |
it "should use 'svn info'" do |
| 77 |
expects_chdir |
| 78 |
expect(provider.revision).to eq('4') # From 'Revision', not 'Last Changed Rev' |
| 79 |
end |
| 80 |
end |
| 81 |
|
| 82 |
describe "setting the revision property" do |
| 83 |
before do |
| 84 |
@revision = '30' |
| 85 |
end |
| 86 |
context 'with conflict' do |
| 87 |
it "should use 'svn update'" do |
| 88 |
resource[:conflict] = 'theirs-full' |
| 89 |
expects_chdir |
| 90 |
provider.expects(:svn).with('--non-interactive', 'update', |
| 91 |
'-r', @revision, |
| 92 |
'--accept', resource.value(:conflict)) |
| 93 |
provider.revision = @revision |
| 94 |
end |
| 95 |
end |
| 96 |
context 'without conflict' do |
| 97 |
it "should use 'svn update'" do |
| 98 |
expects_chdir |
| 99 |
provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision) |
| 100 |
provider.revision = @revision |
| 101 |
end |
| 102 |
end |
| 103 |
end |
| 104 |
|
| 105 |
describe "setting the revision property and repo source" do |
| 106 |
before do |
| 107 |
@revision = '30' |
| 108 |
end |
| 109 |
context 'with conflict' do |
| 110 |
it "should use 'svn switch'" do |
| 111 |
resource[:source] = 'an-unimportant-value' |
| 112 |
resource[:conflict] = 'theirs-full' |
| 113 |
expects_chdir |
| 114 |
provider.expects(:svn).with('--non-interactive', 'switch', |
| 115 |
'-r', @revision, 'an-unimportant-value', |
| 116 |
'--accept', resource.value(:conflict)) |
| 117 |
provider.revision = @revision |
| 118 |
end |
| 119 |
end |
| 120 |
context 'without conflict' do |
| 121 |
it "should use 'svn switch'" do |
| 122 |
resource[:source] = 'an-unimportant-value' |
| 123 |
expects_chdir |
| 124 |
provider.expects(:svn).with('--non-interactive', 'switch', '-r', @revision, 'an-unimportant-value') |
| 125 |
provider.revision = @revision |
| 126 |
end |
| 127 |
end |
| 128 |
end |
| 129 |
|
| 130 |
end |