CVS uses provider example group for specs
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
module VcsrepoHelpers
|
module VcsrepoHelpers
|
||||||
|
|
||||||
def expects_chdir
|
def expects_chdir(path = resource.value(:path))
|
||||||
Dir.expects(:chdir).with(resource.value(:path)).at_least_once.yields
|
Dir.expects(:chdir).with(path).at_least_once.yields
|
||||||
end
|
end
|
||||||
|
|
||||||
def expects_mkdir
|
def expects_mkdir(path = resource.value(:path))
|
||||||
Dir.expects(:mkdir).with(resource.value(:path)).at_least_once
|
Dir.expects(:mkdir).with(path).at_least_once
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,107 +1,70 @@
|
|||||||
require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end }
|
require 'pathname'; Pathname.new(__FILE__).realpath.ascend { |x| begin; require (x + 'spec_helper.rb'); break; rescue LoadError; end }
|
||||||
|
|
||||||
provider_class = Puppet::Type.type(:vcsrepo).provider(:cvs)
|
describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do
|
||||||
|
|
||||||
describe provider_class do
|
describe 'creating' do
|
||||||
|
context "with a source", :resource => {:source => ':ext:source@example.com:/foo/bar'} do
|
||||||
before :each do
|
context_with :revision do
|
||||||
@resource = stub("resource")
|
|
||||||
@provider = provider_class.new(@resource)
|
|
||||||
@path = '/tmp/vcsrepo'
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'when creating' do
|
|
||||||
before do
|
|
||||||
@resource.expects(:value).with(:path).returns(@path).at_least_once
|
|
||||||
end
|
|
||||||
context "when a source is given" do
|
|
||||||
before do
|
|
||||||
@source = ":pserver:anonymous@example.com:/sources/myproj"
|
|
||||||
@resource.expects(:value).with(:source).returns(@source).at_least_once
|
|
||||||
Dir.expects(:chdir).with(File.dirname(@path)).yields
|
|
||||||
end
|
|
||||||
context "and when a revision is given" do
|
|
||||||
before do
|
|
||||||
@tag = 'SOMETAG'
|
|
||||||
@resource.expects(:value).with(:revision).returns(@tag).at_least_once
|
|
||||||
@resource.expects(:value).with(:compression).returns(nil).at_least_once
|
|
||||||
end
|
|
||||||
it "should execute 'cvs checkout' and 'cvs update -r'" do
|
it "should execute 'cvs checkout' and 'cvs update -r'" do
|
||||||
@provider.expects(:cvs).with('-d', @source, 'checkout', '-d', File.basename(@path), File.basename(@source))
|
expects_chdir
|
||||||
Dir.expects(:chdir).with(@path).yields
|
expects_chdir(File.dirname(resource.value(:path)))
|
||||||
@provider.expects(:cvs).with('update', '-r', @tag, '.')
|
provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
|
||||||
@provider.create
|
provider.expects(:cvs).with('update', '-r', resource.value(:revision), '.')
|
||||||
|
provider.create
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "and when a revision is not given" do
|
|
||||||
before do
|
context_without :revision do
|
||||||
@resource.expects(:value).with(:revision).returns(nil).at_least_once
|
|
||||||
@resource.expects(:value).with(:compression).returns(nil).at_least_once
|
|
||||||
end
|
|
||||||
it "should just execute 'cvs checkout' without a revision" do
|
it "should just execute 'cvs checkout' without a revision" do
|
||||||
@provider.expects(:cvs).with('-d', @source, 'checkout', '-d', File.basename(@path), File.basename(@source))
|
provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
|
||||||
@provider.create
|
provider.create
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "when a compression level is given" do
|
|
||||||
before do
|
context "with a compression", :resource => {:compression => '3'} do
|
||||||
@resource.expects(:value).with(:revision).returns(nil).at_least_once
|
|
||||||
@resource.expects(:value).with(:compression).returns('3').at_least_once
|
|
||||||
end
|
|
||||||
it "should just execute 'cvs checkout' without a revision" do
|
it "should just execute 'cvs checkout' without a revision" do
|
||||||
@provider.expects(:cvs).with('-d', @source, '-z', '3', 'checkout', '-d', File.basename(@path), File.basename(@source))
|
provider.expects(:cvs).with('-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
|
||||||
@provider.create
|
provider.create
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when a source is not given" do
|
context "when a source is not given" do
|
||||||
before do
|
|
||||||
@resource.expects(:value).with(:source).returns(nil)
|
|
||||||
end
|
|
||||||
it "should execute 'cvs init'" do
|
it "should execute 'cvs init'" do
|
||||||
@provider.expects(:cvs).with('-d', @path, 'init')
|
provider.expects(:cvs).with('-d', resource.value(:path), 'init')
|
||||||
@provider.create
|
provider.create
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when destroying' do
|
describe 'destroying' do
|
||||||
it "it should remove the directory" do
|
it "it should remove the directory" do
|
||||||
@resource.expects(:value).with(:path).returns(@path).at_least_once
|
FileUtils.expects(:rm_rf).with(resource.value(:path))
|
||||||
FileUtils.expects(:rm_rf).with(@path)
|
provider.destroy
|
||||||
@provider.destroy
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when checking existence" do
|
describe "checking existence" do
|
||||||
before do
|
context_with :source do
|
||||||
@resource.expects(:value).with(:path).returns(@path)
|
|
||||||
end
|
|
||||||
context "when a source is provided" do
|
|
||||||
before do
|
|
||||||
@resource.expects(:value).with(:source).returns(":pserver:anonymous@example.com:/sources/myproj")
|
|
||||||
end
|
|
||||||
it "should check for the CVS directory" do
|
it "should check for the CVS directory" do
|
||||||
File.expects(:directory?).with(File.join(@path, 'CVS'))
|
File.expects(:directory?).with(File.join(resource.value(:path), 'CVS'))
|
||||||
@provider.exists?
|
provider.exists?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "when a source is not provided" do
|
|
||||||
before do
|
context_without :source do
|
||||||
@resource.expects(:value).with(:source).returns(nil)
|
|
||||||
end
|
|
||||||
it "should check for the CVSROOT directory" do
|
it "should check for the CVSROOT directory" do
|
||||||
File.expects(:directory?).with(File.join(@path, 'CVSROOT'))
|
File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT'))
|
||||||
@provider.exists?
|
provider.exists?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when checking the revision property" do
|
describe "checking the revision property" do
|
||||||
before do
|
before do
|
||||||
@resource.expects(:value).with(:path).returns(@path).at_least_once
|
@tag_file = File.join(resource.value(:path), 'CVS', 'Tag')
|
||||||
@tag_file = File.join(@path, 'CVS', 'Tag')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when CVS/Tag exists" do
|
context "when CVS/Tag exists" do
|
||||||
before do
|
before do
|
||||||
@tag = 'HEAD'
|
@tag = 'HEAD'
|
||||||
@@ -109,28 +72,29 @@ describe provider_class do
|
|||||||
end
|
end
|
||||||
it "should read CVS/Tag" do
|
it "should read CVS/Tag" do
|
||||||
File.expects(:read).with(@tag_file).returns("T#{@tag}")
|
File.expects(:read).with(@tag_file).returns("T#{@tag}")
|
||||||
@provider.revision.should == @tag
|
provider.revision.should == @tag
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when CVS/Tag does not exist" do
|
context "when CVS/Tag does not exist" do
|
||||||
before do
|
before do
|
||||||
File.expects(:exist?).with(@tag_file).returns(false)
|
File.expects(:exist?).with(@tag_file).returns(false)
|
||||||
end
|
end
|
||||||
it "assumes MAIN" do
|
it "assumes MAIN" do
|
||||||
@provider.revision.should == 'MAIN'
|
provider.revision.should == 'MAIN'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when setting the revision property" do
|
describe "when setting the revision property" do
|
||||||
before do
|
before do
|
||||||
@resource.expects(:value).with(:path).returns(@path).at_least_once
|
|
||||||
@tag = 'SOMETAG'
|
@tag = 'SOMETAG'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should use 'cvs update -r'" do
|
it "should use 'cvs update -r'" do
|
||||||
Dir.expects(:chdir).with(@path).yields
|
expects_chdir
|
||||||
@provider.expects('cvs').with('update', '-r', @tag, '.')
|
provider.expects('cvs').with('update', '-r', @tag, '.')
|
||||||
@provider.revision = @tag
|
provider.revision = @tag
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user