| 1 |
require 'spec_helper' |
| 2 |
|
| 3 |
describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do |
| 4 |
|
| 5 |
let(:resource) { Puppet::Type.type(:vcsrepo).new({ |
| 6 |
:name => 'test', |
| 7 |
:ensure => :present, |
| 8 |
:provider => :cvs, |
| 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('cvs').returns('/usr/bin/cvs') |
| 18 |
end |
| 19 |
|
| 20 |
describe 'creating' do |
| 21 |
context "with a source" do |
| 22 |
it "should execute 'cvs checkout'" do |
| 23 |
resource[:source] = ':ext:[email protected]:/foo/bar' |
| 24 |
resource[:revision] = 'an-unimportant-value' |
| 25 |
expects_chdir('/tmp') |
| 26 |
Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', 'bar'], :custom_environment => {}) |
| 27 |
provider.create |
| 28 |
end |
| 29 |
|
| 30 |
it "should execute 'cvs checkout' as user 'muppet'" do |
| 31 |
resource[:source] = ':ext:[email protected]:/foo/bar' |
| 32 |
resource[:revision] = 'an-unimportant-value' |
| 33 |
resource[:user] = 'muppet' |
| 34 |
expects_chdir('/tmp') |
| 35 |
Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', 'bar'], :uid => 'muppet', :custom_environment => {}) |
| 36 |
provider.create |
| 37 |
end |
| 38 |
|
| 39 |
it "should just execute 'cvs checkout' without a revision" do |
| 40 |
resource[:source] = ':ext:[email protected]:/foo/bar' |
| 41 |
resource.delete(:revision) |
| 42 |
Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))], :custom_environment => {}) |
| 43 |
provider.create |
| 44 |
end |
| 45 |
|
| 46 |
context "with a compression" do |
| 47 |
it "should just execute 'cvs checkout' without a revision" do |
| 48 |
resource[:source] = ':ext:[email protected]:/foo/bar' |
| 49 |
resource[:compression] = '3' |
| 50 |
resource.delete(:revision) |
| 51 |
Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))], :custom_environment => {}) |
| 52 |
provider.create |
| 53 |
end |
| 54 |
end |
| 55 |
end |
| 56 |
|
| 57 |
context "when a source is not given" do |
| 58 |
it "should execute 'cvs init'" do |
| 59 |
resource.delete(:source) |
| 60 |
Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:path), 'init'], :custom_environment => {}) |
| 61 |
provider.create |
| 62 |
end |
| 63 |
end |
| 64 |
end |
| 65 |
|
| 66 |
describe 'destroying' do |
| 67 |
it "it should remove the directory" do |
| 68 |
provider.destroy |
| 69 |
end |
| 70 |
end |
| 71 |
|
| 72 |
describe "checking existence" do |
| 73 |
it "should check for the CVS directory with source" do |
| 74 |
resource[:source] = ':ext:[email protected]:/foo/bar' |
| 75 |
File.expects(:directory?).with(File.join(resource.value(:path), 'CVS')) |
| 76 |
provider.exists? |
| 77 |
end |
| 78 |
|
| 79 |
it "should check for the CVSROOT directory without source" do |
| 80 |
resource.delete(:source) |
| 81 |
File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT')) |
| 82 |
provider.exists? |
| 83 |
end |
| 84 |
end |
| 85 |
|
| 86 |
describe "checking the revision property" do |
| 87 |
before do |
| 88 |
@tag_file = File.join(resource.value(:path), 'CVS', 'Tag') |
| 89 |
end |
| 90 |
|
| 91 |
context "when CVS/Tag exists" do |
| 92 |
before do |
| 93 |
@tag = 'TAG' |
| 94 |
File.expects(:exist?).with(@tag_file).returns(true) |
| 95 |
end |
| 96 |
it "should read CVS/Tag" do |
| 97 |
File.expects(:read).with(@tag_file).returns("T#{@tag}") |
| 98 |
expect(provider.revision).to eq(@tag) |
| 99 |
end |
| 100 |
end |
| 101 |
|
| 102 |
context "when CVS/Tag does not exist" do |
| 103 |
before do |
| 104 |
File.expects(:exist?).with(@tag_file).returns(false) |
| 105 |
end |
| 106 |
it "assumes HEAD" do |
| 107 |
expect(provider.revision).to eq('HEAD') |
| 108 |
end |
| 109 |
end |
| 110 |
end |
| 111 |
|
| 112 |
describe "when setting the revision property" do |
| 113 |
before do |
| 114 |
@tag = 'SOMETAG' |
| 115 |
end |
| 116 |
|
| 117 |
it "should use 'cvs update -dr'" do |
| 118 |
expects_chdir |
| 119 |
Puppet::Util::Execution.expects(:execute).with([:cvs, 'update', '-dr', @tag, '.'], :custom_environment => {}) |
| 120 |
provider.revision = @tag |
| 121 |
end |
| 122 |
end |
| 123 |
|
| 124 |
end |