3 describe Puppet::Type.type(:vcsrepo).provider(:hg) do
5 let(:resource) { Puppet::Type.type(:vcsrepo).new({
9 :path => '/tmp/vcsrepo',
12 let(:provider) { resource.provider }
15 Puppet::Util.stubs(:which).with('hg').returns('/usr/bin/hg')
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))
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))
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))
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" + "\"")
63 describe 'destroying' do
64 it "it should remove the directory" do
70 describe "checking existence" do
71 it "should check for the directory" do
72 expects_directory?(true, File.join(resource.value(:path), '.hg'))
77 describe "checking the revision property" do
82 context "when given a non-SHA as the resource revision" do
84 provider.expects(:hg).with('parents').returns(fixture(:hg_parents))
85 provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
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 provider.revision.should == '0.6'
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 provider.revision.should == '34e6012c783a'
102 context "when given a SHA as the resource revision" do
104 provider.expects(:hg).with('parents').returns(fixture(:hg_parents))
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 provider.revision.should == resource.value(:revision)
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 provider.revision.should == '34e6012c783a'
125 describe "setting the revision property" do
127 @revision = '6aa99e9b3ab1'
129 it "should use 'hg update ---clean -r'" do
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