| 1 |
require 'spec_helper' |
| 2 |
|
| 3 |
describe Puppet::Type.type(:vcsrepo).provider(:hg) do |
| 4 |
|
| 5 |
let(:resource) { Puppet::Type.type(:vcsrepo).new({ |
| 6 |
:name => 'test', |
| 7 |
:ensure => :present, |
| 8 |
:provider => :hg, |
| 9 |
:path => '/tmp/vcsrepo', |
| 10 |
})} |
| 11 |
|
| 12 |
let(:provider) { resource.provider } |
| 13 |
|
| 14 |
before :each do |
| 15 |
Puppet::Util.stubs(:which).with('hg').returns('/usr/bin/hg') |
| 16 |
end |
| 17 |
|
| 18 |
describe 'creating' do |
| 19 |
context 'with source and revision' do |
| 20 |
it "should execute 'hg clone -u' with the revision" do |
| 21 |
resource[:source] = 'something' |
| 22 |
resource[:revision] = '1' |
| 23 |
provider.expects(:hg).with('clone', '-u', |
| 24 |
resource.value(:revision), |
| 25 |
resource.value(:source), |
| 26 |
resource.value(:path)) |
| 27 |
provider.create |
| 28 |
end |
| 29 |
end |
| 30 |
|
| 31 |
context 'without revision' do |
| 32 |
it "should just execute 'hg clone' without a revision" do |
| 33 |
resource[:source] = 'something' |
| 34 |
provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path)) |
| 35 |
provider.create |
| 36 |
end |
| 37 |
end |
| 38 |
|
| 39 |
context "when a source is not given" do |
| 40 |
it "should execute 'hg init'" do |
| 41 |
provider.expects(:hg).with('init', resource.value(:path)) |
| 42 |
provider.create |
| 43 |
end |
| 44 |
end |
| 45 |
|
| 46 |
context "when basic auth is used" do |
| 47 |
it "should execute 'hg clone'" do |
| 48 |
resource[:source] = 'something' |
| 49 |
resource[:basic_auth_username] = 'user' |
| 50 |
resource[:basic_auth_password] = 'pass' |
| 51 |
provider.expects(:hg).with('clone', |
| 52 |
resource.value(:source), |
| 53 |
resource.value(:path), |
| 54 |
"--config","\"auth.x.prefix=" + resource.value(:source) + "\"", |
| 55 |
"--config","\"auth.x.username=" + resource.value(:basic_auth_username) + "\"", |
| 56 |
"--config","\"auth.x.password=" + resource.value(:basic_auth_password) + "\"", |
| 57 |
"--config","\"auth.x.schemes=http https" + "\"") |
| 58 |
provider.create |
| 59 |
end |
| 60 |
end |
| 61 |
end |
| 62 |
|
| 63 |
describe 'destroying' do |
| 64 |
it "it should remove the directory" do |
| 65 |
expects_rm_rf |
| 66 |
provider.destroy |
| 67 |
end |
| 68 |
end |
| 69 |
|
| 70 |
describe "checking existence" do |
| 71 |
it "should check for the directory" do |
| 72 |
expects_directory?(true, File.join(resource.value(:path), '.hg')) |
| 73 |
provider.exists? |
| 74 |
end |
| 75 |
end |
| 76 |
|
| 77 |
describe "checking the revision property" do |
| 78 |
before do |
| 79 |
expects_chdir |
| 80 |
end |
| 81 |
|
| 82 |
context "when given a non-SHA as the resource revision" do |
| 83 |
before do |
| 84 |
provider.expects(:hg).with('parents').returns(fixture(:hg_parents)) |
| 85 |
provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) |
| 86 |
end |
| 87 |
|
| 88 |
context "when its SHA is not different than the current SHA" do |
| 89 |
it "should return the ref" do |
| 90 |
resource[:revision] = '0.6' |
| 91 |
expect(provider.revision).to eq('0.6') |
| 92 |
end |
| 93 |
end |
| 94 |
|
| 95 |
context "when its SHA is different than the current SHA" do |
| 96 |
it "should return the current SHA" do |
| 97 |
resource[:revision] = '0.5.3' |
| 98 |
expect(provider.revision).to eq('34e6012c783a') |
| 99 |
end |
| 100 |
end |
| 101 |
end |
| 102 |
context "when given a SHA as the resource revision" do |
| 103 |
before do |
| 104 |
provider.expects(:hg).with('parents').returns(fixture(:hg_parents)) |
| 105 |
end |
| 106 |
|
| 107 |
context "when it is the same as the current SHA", :resource => {:revision => '34e6012c783a'} do |
| 108 |
it "should return it" do |
| 109 |
resource[:revision] = '34e6012c783a' |
| 110 |
provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) |
| 111 |
expect(provider.revision).to eq(resource.value(:revision)) |
| 112 |
end |
| 113 |
end |
| 114 |
|
| 115 |
context "when it is not the same as the current SHA", :resource => {:revision => 'not-the-same'} do |
| 116 |
it "should return the current SHA" do |
| 117 |
resource[:revision] = 'not-the-same' |
| 118 |
provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) |
| 119 |
expect(provider.revision).to eq('34e6012c783a') |
| 120 |
end |
| 121 |
end |
| 122 |
end |
| 123 |
end |
| 124 |
|
| 125 |
describe "setting the revision property" do |
| 126 |
before do |
| 127 |
@revision = '6aa99e9b3ab1' |
| 128 |
end |
| 129 |
it "should use 'hg update ---clean -r'" do |
| 130 |
expects_chdir |
| 131 |
provider.expects(:hg).with('pull') |
| 132 |
provider.expects(:hg).with('merge') |
| 133 |
provider.expects(:hg).with('update', '--clean', '-r', @revision) |
| 134 |
provider.revision = @revision |
| 135 |
end |
| 136 |
end |
| 137 |
|
| 138 |
end |