summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorPaul Allen <pallen@perforce.com>2014-06-12 17:50:55 +0100
committerPaul Allen <pallen@perforce.com>2014-06-20 12:16:29 +0100
commit58f9cb20657a7be01777c920a37279f30dc1fce6 (patch)
tree17c4222cd8bb43c3f9fe814147f44185cf15870e /spec/unit
parentb16e4c0f9251279fe2211f651459654e0759dbf0 (diff)
downloadpuppet-vcsrepo-58f9cb20657a7be01777c920a37279f30dc1fce6.tar.gz
puppet-vcsrepo-58f9cb20657a7be01777c920a37279f30dc1fce6.tar.bz2
Spec tests for p4 provider
Test create, destroy and exists? access points.
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/puppet/provider/vcsrepo/p4_spec.rb73
1 files changed, 73 insertions, 0 deletions
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..822106d
--- /dev/null
+++ b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb
@@ -0,0 +1,73 @@
+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 => "Root: /tmp/vcsrepo\nDescription: Generated by Puppet 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[:p4client] = 'client_ws'
+ resource[:revision] = '1'
+ provider.expects(:p4).with(['client', '-o', resource.value(:p4client)]).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'
+ resource[:p4client] = 'client_ws'
+ provider.expects(:p4).with(['client', '-o', resource.value(:p4client)]).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
+ provider.expects(:p4).with(['client', '-o', "puppet-51f0a4b45dbfc10614df94f0a189c16f"]).returns({})
+ provider.expects(:p4).with(['client', '-i'], spec)
+ provider.create
+ end
+ end
+ end
+
+ describe 'destroying' do
+ it "it should remove the directory" do
+ resource[:p4client] = 'test_client'
+ provider.expects(:p4).with(['client', '-d', '-f', resource.value(:p4client)])
+ 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