Basic tests for git provider, stub for svn provider
[puppet_vcsrepo.git] / spec / unit / puppet / provider / vcsrepo / git_spec.rb
1 require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end }
2
3 provider_class = Puppet::Type.type(:vcsrepo).provider(:git)
4
5 describe provider_class do
6
7   before :each do
8     @resource = stub("resource")
9     @provider = provider_class.new(@resource)
10     @path = '/tmp/vcsrepo'
11   end
12
13   context 'when creating' do
14     context "when a source is given" do
15       context "and when a revision is given" do
16         it "should execute 'git clone' and 'git reset'" do
17           @resource.expects(:value).with(:path).returns(@path).at_least_once
18           @resource.expects(:value).with(:source).returns('git://example.com/repo.git').at_least_once
19           @provider.expects(:git).with('clone', 'git://example.com/repo.git', @path)
20           @resource.expects(:value).with(:revision).returns('abcdef').at_least_once
21           Dir.expects(:chdir).with(@path).yields
22           @provider.expects('git').with('reset', '--hard', 'abcdef')
23           @provider.create
24         end        
25       end
26       context "and when a revision is not given" do
27         it "should just execute 'git clone'" do
28           @resource.expects(:value).with(:path).returns(@path).at_least_once
29           @resource.expects(:value).with(:source).returns('git://example.com/repo.git').at_least_once
30           @resource.expects(:value).with(:revision).returns(nil).at_least_once
31           @provider.expects(:git).with('clone', 'git://example.com/repo.git', @path)
32           @provider.create
33         end        
34       end
35     end
36     context "when a source is not given" do
37       it "should execute 'git init'" do
38         @resource.expects(:value).with(:path).returns(@path).at_least_once
39         @resource.expects(:value).with(:source).returns(nil)
40         Dir.expects(:chdir).with(@path).yields
41         @provider.expects(:git).with('init')
42         @provider.create
43       end
44     end
45   end
46
47   context 'when destroying' do
48     it "it should remove the directory" do
49       @resource.expects(:value).with(:path).returns(@path).at_least_once
50       FileUtils.expects(:rm_rf).with(@path)
51       @provider.destroy
52     end
53   end
54
55   context "when checking existence" do
56     it "should check for the directory" do
57       @resource.expects(:value).with(:path).returns(@path)
58       File.expects(:directory?).with(@path)
59       @provider.exists?
60     end
61   end
62
63   context "when checking 'revision' property"
64
65 end