summaryrefslogtreecommitdiff
path: root/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb
blob: cc195eb0116a4910029a8b04df5039063cf1b59f (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
require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end }

describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do

  describe 'creating' do
    context "with a source", :resource => {:source => ':ext:source@example.com:/foo/bar'} do
      resource_with :revision do
        it "should execute 'cvs checkout' and 'cvs update -r'" do
          expects_chdir
          expects_chdir(File.dirname(resource.value(:path)))
          provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
          provider.expects(:cvs).with('update', '-r', resource.value(:revision), '.')
          provider.create
        end        
      end
      
      resource_without :revision do
        it "should just execute 'cvs checkout' without a revision" do
          provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
          provider.create
        end        
      end
      
      context "with a compression", :resource => {:compression => '3'} do
        it "should just execute 'cvs checkout' without a revision" do
          provider.expects(:cvs).with('-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
          provider.create
        end        
      end
    end
    
    context "when a source is not given" do
      it "should execute 'cvs init'" do
        provider.expects(:cvs).with('-d', resource.value(:path), 'init')
        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
    resource_with :source do
      it "should check for the CVS directory" do
        File.expects(:directory?).with(File.join(resource.value(:path), 'CVS'))
        provider.exists?
      end
    end
    
    resource_without :source do
      it "should check for the CVSROOT directory" do
        File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT'))
        provider.exists?
      end
    end
  end

  describe "checking the revision property" do
    before do
      @tag_file = File.join(resource.value(:path), 'CVS', 'Tag')
    end
    
    context "when CVS/Tag exists" do
      before do
        @tag = 'HEAD'
        File.expects(:exist?).with(@tag_file).returns(true)
      end
      it "should read CVS/Tag" do
        File.expects(:read).with(@tag_file).returns("T#{@tag}")
        provider.revision.should == @tag
      end
    end
    
    context "when CVS/Tag does not exist" do
      before do
        File.expects(:exist?).with(@tag_file).returns(false)
      end
      it "assumes MAIN" do
        provider.revision.should == 'MAIN'        
      end
    end
  end
  
  describe "when setting the revision property" do
    before do
      @tag = 'SOMETAG'
    end
    
    it "should use 'cvs update -r'" do
      expects_chdir
      provider.expects('cvs').with('update', '-r', @tag, '.')
      provider.revision = @tag
    end
  end

end