summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorBruce Williams <bruce@codefluency.com>2010-03-18 14:46:12 -0700
committerBruce Williams <bruce@codefluency.com>2010-03-18 14:46:12 -0700
commit463779ca3d297ade2568893372fb6e982fb5ec74 (patch)
tree22949e456ad799d4c7d3a328ab75fffb236b9faf /spec
parentdc64158c8cb818b7f583f5f7c8b5ce5197338ee0 (diff)
downloadpuppet-vcsrepo-463779ca3d297ade2568893372fb6e982fb5ec74.tar.gz
puppet-vcsrepo-463779ca3d297ade2568893372fb6e982fb5ec74.tar.bz2
Support different create and revision= operations depending on the revision type in Git (commit, tag, or local/remote branch)
Diffstat (limited to 'spec')
-rw-r--r--spec/fixtures/git_branch_a.txt14
-rw-r--r--spec/unit/puppet/provider/vcsrepo/git_spec.rb92
2 files changed, 92 insertions, 14 deletions
diff --git a/spec/fixtures/git_branch_a.txt b/spec/fixtures/git_branch_a.txt
new file mode 100644
index 0000000..2c99829
--- /dev/null
+++ b/spec/fixtures/git_branch_a.txt
@@ -0,0 +1,14 @@
+ feature/foo
+ feature/bar
+ feature/baz
+ feature/quux
+ only/local
+* master
+ refactor/foo
+ origin/HEAD
+ origin/feature/foo
+ origin/feature/bar
+ origin/feature/baz
+ origin/feature/quux
+ origin/only/remote
+ origin/master
diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
index f7864c0..4a1085a 100644
--- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
@@ -1,27 +1,34 @@
require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end }
describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do
-
+
context 'creating' do
resource_with :source do
resource_with :ensure => :present do
- resource_with :revision do
+ context "with a revision that is a remote branch", :resource => {:revision => 'only/remote'} do
+ it "should execute 'git clone' and 'git checkout -b'" do
+ provider.expects('git').with('clone', resource.value(:source), resource.value(:path))
+ expects_chdir
+ provider.expects(:remote_revision_branch?).returns(true)
+ provider.expects(:git).with('checkout', '-b', resource.value(:revision), '--track', "origin/#{resource.value(:revision)}")
+ provider.expects(:update_submodules)
+ provider.create
+ end
+ end
+ context "with a revision that is not a remote branch", :resource => {:revision => 'a-commit-or-tag'} do
it "should execute 'git clone' and 'git reset --hard'" do
provider.expects('git').with('clone', resource.value(:source), resource.value(:path))
expects_chdir
+ provider.expects(:remote_revision_branch?).returns(false)
provider.expects('git').with('reset', '--hard', resource.value(:revision))
- provider.expects(:git).with('submodule', 'init')
- provider.expects(:git).with('submodule', 'update')
+ provider.expects(:update_submodules)
provider.create
end
- end
-
+ end
resource_without :revision do
it "should execute 'git clone' and submodule commands" do
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
- expects_chdir
- provider.expects(:git).with('submodule', 'init')
- provider.expects(:git).with('submodule', 'update')
+ provider.expects(:update_submodules)
provider.create
end
end
@@ -137,14 +144,40 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do
end
context "setting the revision property" do
- it "should use 'git fetch' and 'git reset'" do
+ before do
expects_chdir
provider.expects(:git).with('fetch', 'origin')
- provider.expects(:git).with('reset', '--hard', 'carcar')
- provider.expects(:git).with('submodule', 'init')
- provider.expects(:git).with('submodule', 'update')
- provider.revision = 'carcar'
end
+ context "when it's an existing local branch", :resource => {:revision => 'feature/foo'} do
+ it "should use 'git fetch' and 'git reset'" do
+ provider.expects(:local_revision_branch?).returns(true)
+ provider.expects(:git).with('checkout', resource.value(:revision))
+ provider.expects(:git).with('pull', 'origin')
+ provider.expects(:update_submodules)
+ provider.revision = resource.value(:revision)
+ end
+ end
+ context "when it's a remote branch", :resource => {:revision => 'only/remote'} do
+ it "should use 'git fetch' and 'git reset'" do
+ provider.expects(:local_revision_branch?).returns(false)
+ provider.expects(:remote_revision_branch?).returns(true)
+ provider.expects(:git).with('checkout',
+ '-b', resource.value(:revision),
+ '--track', "origin/#{resource.value(:revision)}")
+ provider.expects(:update_submodules)
+ provider.revision = resource.value(:revision)
+ end
+ end
+ context "when it's a commit or tag", :resource => {:revision => 'a-commit-or-tag'} do
+ it "should use 'git fetch' and 'git reset'" do
+ provider.expects(:local_revision_branch?).returns(false)
+ provider.expects(:remote_revision_branch?).returns(false)
+ provider.expects(:git).with('reset', '--hard', resource.value(:revision))
+ provider.expects(:git).with('submodule', 'init')
+ provider.expects(:git).with('submodule', 'update')
+ provider.revision = resource.value(:revision)
+ end
+ end
end
context "updating references" do
@@ -154,5 +187,36 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do
provider.update_references
end
end
+
+ context "checking if revision" do
+ before do
+ expects_chdir
+ provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
+ end
+ context "is a local branch" do
+ context "when it's listed in 'git branch -a'", :resource => {:revision => 'feature/foo'} do
+ it "should return true" do
+ provider.should be_local_branch_revision
+ end
+ end
+ context "when it's not listed in 'git branch -a'" , :resource => {:revision => 'feature/notexist'}do
+ it "should return false" do
+ provider.should_not be_local_branch_revision
+ end
+ end
+ end
+ context "is a remote branch" do
+ context "when it's listed in 'git branch -a' with an 'origin/' prefix", :resource => {:revision => 'only/remote'} do
+ it "should return true" do
+ provider.should be_remote_branch_revision
+ end
+ end
+ context "when it's not listed in 'git branch -a' with an 'origin/' prefix" , :resource => {:revision => 'only/local'}do
+ it "should return false" do
+ provider.should_not be_remote_branch_revision
+ end
+ end
+ end
+ end
end