summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/puppet/provider/vcsrepo/git_spec.rb116
-rw-r--r--spec/unit/puppet/provider/vcsrepo/hg_spec.rb16
-rw-r--r--spec/unit/puppet/provider/vcsrepo/p4_spec.rb82
3 files changed, 140 insertions, 74 deletions
diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
index a753610..3f81cc8 100644
--- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do
- def branch_a_list(include_branch)
+ def branch_a_list(include_branch = nil?)
<<branches
end
#{"* master" unless include_branch.nil?}
@@ -175,6 +175,28 @@ branches
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
end
+ it "should warn about destroying it using force and noop attribute" do
+ resource[:force] = true
+ resource[:noop] = true
+ resource.delete(:revision)
+ provider.expects(:working_copy_exists?).returns(true)
+
+ provider.expects(:destroy).never
+ provider.expects(:create).never
+ Puppet::Type::Vcsrepo::Ensure.any_instance.expects(:send_log).with(:notice, "Noop Mode - Would have deleted repository and re-created from latest")
+ provider.resource.retrieve
+ end
+ it "should warn about destroying it using force and global noop" do
+ resource[:force] = true
+ Puppet[:noop] = true
+ resource.delete(:revision)
+ provider.expects(:working_copy_exists?).returns(true)
+
+ provider.expects(:destroy).never
+ provider.expects(:create).never
+ Puppet::Type::Vcsrepo::Ensure.any_instance.expects(:send_log).with(:notice, "Noop Mode - Would have deleted repository and re-created from latest")
+ provider.resource.retrieve
+ end
end
context "when the path is not empty and not a repository" do
@@ -200,51 +222,41 @@ branches
expects_chdir('/tmp/test')
resource[:revision] = 'currentsha'
resource.delete(:source)
- provider.expects(:git).with('rev-parse', 'HEAD').returns('currentsha')
+ provider.stubs(:git).with('config', 'remote.origin.url').returns('')
+ provider.stubs(:git).with('fetch', 'origin') # FIXME
+ provider.stubs(:git).with('fetch', '--tags', 'origin')
+ provider.stubs(:git).with('rev-parse', 'HEAD').returns('currentsha')
+ provider.stubs(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
+ provider.stubs(:git).with('tag', '-l').returns("Hello")
end
context "when its SHA is not different than the current SHA" do
it "should return the ref" do
- provider.expects(:git).with('config', 'remote.origin.url').returns('')
- provider.expects(:git).with('fetch', 'origin') # FIXME
- provider.expects(:git).with('fetch', '--tags', 'origin')
- provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('currentsha')
- provider.expects(:git).with('tag', '-l').returns("Hello")
+ provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
provider.revision.should == resource.value(:revision)
end
end
context "when its SHA is different than the current SHA" do
it "should return the current SHA" do
- provider.expects(:git).with('config', 'remote.origin.url').returns('')
- provider.expects(:git).with('fetch', 'origin') # FIXME
- provider.expects(:git).with('fetch', '--tags', 'origin')
- provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('othersha')
- provider.expects(:git).with('tag', '-l').returns("Hello")
- provider.revision.should == 'currentsha'
+ provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha')
+ provider.revision.should == resource.value(:revision)
end
end
context "when its a ref to a remote head" do
it "should return the revision" do
- provider.expects(:git).with('config', 'remote.origin.url').returns('')
- provider.expects(:git).with('fetch', 'origin') # FIXME
- provider.expects(:git).with('fetch', '--tags', 'origin')
- provider.expects(:git).with('tag', '-l').returns("Hello")
- provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('')
- provider.expects(:git).with('ls-remote', '--heads', '--tags', 'origin', resource.value(:revision)).returns("newsha refs/heads/#{resource.value(:revision)}")
- provider.revision.should == 'currentsha'
+ provider.stubs(:git).with('branch', '-a').returns(" remotes/origin/#{resource.value(:revision)}")
+ provider.expects(:git).with('rev-parse', "origin/#{resource.value(:revision)}").returns("newsha")
+ provider.revision.should == resource.value(:revision)
end
end
context "when its a ref to non existant remote head" do
it "should fail" do
- provider.expects(:git).with('config', 'remote.origin.url').returns('')
- provider.expects(:git).with('fetch', 'origin') # FIXME
- provider.expects(:git).with('fetch', '--tags', 'origin')
- provider.expects(:git).with('tag', '-l').returns("Hello")
+ provider.expects(:git).with('branch', '-a').returns(branch_a_list)
provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('')
- provider.expects(:git).with('ls-remote', '--heads', '--tags', 'origin', resource.value(:revision)).returns('')
+
expect { provider.revision }.to raise_error(Puppet::Error, /not a local or remote ref$/)
end
end
@@ -254,10 +266,7 @@ branches
resource[:source] = 'git://git@foo.com/bar.git'
provider.expects(:git).with('config', 'remote.origin.url').returns('old')
provider.expects(:git).with('config', 'remote.origin.url', 'git://git@foo.com/bar.git')
- provider.expects(:git).with('fetch', 'origin') # FIXME
- provider.expects(:git).with('fetch', '--tags', 'origin')
- provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('currentsha')
- provider.expects(:git).with('tag', '-l').returns("Hello")
+ provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
provider.revision.should == resource.value(:revision)
end
end
@@ -273,7 +282,7 @@ branches
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').at_least_once.returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
- provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
+ provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
provider.revision = resource.value(:revision)
end
end
@@ -283,7 +292,7 @@ branches
provider.expects(:update_submodules)
provider.expects(:git).with('branch', '-a').at_least_once.returns(resource.value(:revision))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
- provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
+ provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}")
provider.revision = resource.value(:revision)
end
end
@@ -346,64 +355,23 @@ branches
end
end
- context "retrieving the current revision" do
- before do
- expects_chdir
- provider.expects(:git).with('branch','-a').returns("* foo")
- end
-
- it "will strip trailing newlines" do
- provider.expects(:get_revision).with('origin/foo')
- provider.latest
- end
- end
-
describe 'latest?' do
- before do
- expects_chdir('/tmp/test')
- end
context 'when true' do
it do
provider.expects(:revision).returns('testrev')
- provider.expects(:latest).returns('testrev')
+ provider.expects(:latest_revision).returns('testrev')
provider.latest?.should be_true
end
end
context 'when false' do
it do
provider.expects(:revision).returns('master')
- provider.expects(:latest).returns('testrev')
+ provider.expects(:latest_revision).returns('testrev')
provider.latest?.should be_false
end
end
end
- describe 'latest' do
- before do
- provider.expects(:get_revision).returns('master')
- expects_chdir
- end
- context 'on master' do
- it do
- provider.expects(:git).with('branch','-a').returns("* master")
- provider.latest.should == 'master'
- end
- end
- context 'no branch' do
- it do
- provider.expects(:git).with('branch','-a').returns("* master")
-
- provider.latest.should == 'master'
- end
- end
- context 'feature/bar' do
- it do
- provider.expects(:git).with('branch','-a').returns("* master")
- provider.latest.should == 'master'
- end
- end
- end
-
describe 'convert_working_copy_to_bare' do
it do
FileUtils.expects(:mv).returns(true)
diff --git a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb
index 7fd5348..6b21c1c 100644
--- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb
@@ -42,6 +42,22 @@ describe Puppet::Type.type(:vcsrepo).provider(:hg) do
provider.create
end
end
+
+ context "when basic auth is used" do
+ it "should execute 'hg clone'" do
+ resource[:source] = 'something'
+ resource[:basic_auth_username] = 'user'
+ resource[:basic_auth_password] = 'pass'
+ provider.expects(:hg).with('clone',
+ resource.value(:source),
+ resource.value(:path),
+ "--config","\"auth.x.prefix=" + resource.value(:source) + "\"",
+ "--config","\"auth.x.username=" + resource.value(:basic_auth_username) + "\"",
+ "--config","\"auth.x.password=" + resource.value(:basic_auth_password) + "\"",
+ "--config","\"auth.x.schemes=http https" + "\"")
+ provider.create
+ end
+ end
end
describe 'destroying' do
diff --git a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb
new file mode 100644
index 0000000..2d382da
--- /dev/null
+++ b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb
@@ -0,0 +1,82 @@
+require 'spec_helper'
+
+describe Puppet::Type.type(:vcsrepo).provider(:p4) do
+
+ let(:resource) { Puppet::Type.type(:vcsrepo).new({
+ :name => 'test',
+ :ensure => :present,
+ :provider => :p4,
+ :path => '/tmp/vcsrepo',
+ })}
+
+ let(:provider) { resource.provider }
+
+ before :each do
+ Puppet::Util.stubs(:which).with('p4').returns('/usr/local/bin/p4')
+ end
+
+ spec = {
+ :input => "Description: Generated by Puppet VCSrepo\nRoot: /tmp/vcsrepo\n\nView:\n",
+ :marshal => false
+ }
+
+ describe 'creating' do
+ context 'with source and revision' do
+ it "should execute 'p4 sync' with the revision" do
+ resource[:source] = 'something'
+ resource[:revision] = '1'
+ ENV['P4CLIENT'] = 'client_ws1'
+
+ provider.expects(:p4).with(['client', '-o', 'client_ws1']).returns({})
+ provider.expects(:p4).with(['client', '-i'], spec)
+ provider.expects(:p4).with(['sync', resource.value(:source) + "@" + resource.value(:revision)])
+ provider.create
+ end
+ end
+
+ context 'without revision' do
+ it "should just execute 'p4 sync' without a revision" do
+ resource[:source] = 'something'
+ ENV['P4CLIENT'] = 'client_ws2'
+
+ provider.expects(:p4).with(['client', '-o', 'client_ws2']).returns({})
+ provider.expects(:p4).with(['client', '-i'], spec)
+ provider.expects(:p4).with(['sync', resource.value(:source)])
+ provider.create
+ end
+ end
+
+ context "when a client and source are not given" do
+ it "should execute 'p4 client'" do
+ ENV['P4CLIENT'] = nil
+
+ path = resource.value(:path)
+ host = Facter.value('hostname')
+ default = "puppet-" + Digest::MD5.hexdigest(path + host)
+
+ provider.expects(:p4).with(['client', '-o', default]).returns({})
+ provider.expects(:p4).with(['client', '-i'], spec)
+ provider.create
+ end
+ end
+ end
+
+ describe 'destroying' do
+ it "it should remove the directory" do
+ ENV['P4CLIENT'] = 'test_client'
+
+ provider.expects(:p4).with(['client', '-d', '-f', 'test_client'])
+ expects_rm_rf
+ provider.destroy
+ end
+ end
+
+ describe "checking existence" do
+ it "should check for the directory" do
+ provider.expects(:p4).with(['info'], {:marshal => false}).returns({})
+ provider.expects(:p4).with(['where', resource.value(:path) + "..."], {:raise => false}).returns({})
+ provider.exists?
+ end
+ end
+
+end