Last active
December 30, 2015 12:39
-
-
Save glarizza/7830257 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # <modulepath>/rcsrepo/spec/unit/puppet/provider/rcsrepo/git_spec.rb | |
| require 'puppet' | |
| require 'fileutils' | |
| require 'puppet/type/rcsrepo' | |
| RSpec.configure { |config| config.mock_with :mocha } | |
| describe 'The git provider for the rcsrepo type' do | |
| let(:test_dir) { '/path/to/repo' } | |
| let(:resource) { Puppet::Type::Rcsrepo.new({:path => test_dir}) } | |
| let(:provider) { Puppet::Type.type(:rcsrepo).provider(:git).new(resource) } | |
| it 'exists? should return true if the repository exists' do | |
| File.stubs(:directory?).with("#{test_dir}/.git").returns(true) | |
| provider.exists?.should == true | |
| end | |
| it 'exists? should return false if the repository does not exist' do | |
| File.stubs(:directory?).with("#{test_dir}/.git").returns(false) | |
| provider.exists?.should == false | |
| end | |
| it 'create: should `git clone` a repository to path if a source is passed' do | |
| resource[:source] = 'https://github.com/glarizza/puppet-mac_proxy.git' | |
| provider.expects(:git).with(['clone', 'https://github.com/glarizza/puppet-mac_proxy.git', test_dir]) | |
| FileUtils.stubs(:rm_rf).with(test_dir).returns(true) | |
| File.stubs(:directory?).with(test_dir).returns(false) | |
| provider.create | |
| end | |
| it 'create: should `git init` a repository at path if a source is not passed' do | |
| provider.expects(:git).with(['init', test_dir]) | |
| FileUtils.stubs(:mkdir_p).with(test_dir).returns(true) | |
| File.stubs(:directory?).with(test_dir).returns(true) | |
| provider.create | |
| end | |
| it 'destroy: should call FileUtils.rm_rf on the path to remove a repository' do | |
| FileUtils.expects(:rm_rf).with(test_dir) | |
| provider.destroy | |
| end | |
| it 'revision: should call git_lazy to get the `rev-parse HEAD` value' do | |
| provider.expects(:git_lazy).with(['rev-parse', 'HEAD']).returns("foo\n") | |
| provider.revision | |
| end | |
| it 'revision should actually work' do | |
| current_revision = '151bc64c5c2a2ddd2156f4a61b7ad9730d04b5cf' | |
| provider.resource[:source] = 'https://github.com/glarizza/puppet-mac_proxy.git' | |
| provider.resource[:path] = '/tmp/gary' | |
| provider.create | |
| provider.revision.should == current_revision | |
| provider.destroy | |
| end | |
| it 'revision= should call git_lazy to checkout a revision of a repository' do | |
| revision = 'foo' | |
| provider.expects(:git_lazy).with(['fetch', 'origin']) | |
| provider.expects(:git_lazy).with(['checkout', revision, '-f']) | |
| provider.revision= revision | |
| end | |
| it 'revision= should actually work' do | |
| revision = '7a48aab321f615b7d48e894ff0478e8163114856' | |
| provider.resource[:source] = 'https://github.com/glarizza/puppet-mac_proxy.git' | |
| provider.resource[:path] = '/tmp/gary' | |
| provider.create | |
| provider.revision = revision | |
| provider.revision.should == revision | |
| provider.destroy | |
| end | |
| it 'create: should set the revision if a revision is passed' do | |
| revision = '7a48aab321f615b7d48e894ff0478e8163114856' | |
| provider.resource[:revision] = revision | |
| provider.resource[:source] = 'https://github.com/glarizza/puppet-mac_proxy.git' | |
| provider.resource[:path] = '/tmp/gary' | |
| provider.create | |
| provider.revision.should == revision | |
| provider.destroy | |
| end | |
| end | |
| ### Sydney 2/14/2014 | |
| require 'puppet' | |
| require 'fileutils' | |
| require 'puppet/type/rcsrepo' | |
| RSpec.configure { |config| config.mock_with :mocha } | |
| describe 'The git provider for the rcsrepo type' do | |
| let(:test_dir) { '/path/to/repo' } | |
| let(:resource) { Puppet::Type::Rcsrepo.new({:path => test_dir}) } | |
| let(:provider) { Puppet::Type.type(:rcsrepo).provider(:git).new(resource) } | |
| it 'exists? should return true if repository exists' do | |
| provider.stubs(:check_for_directory).with("#{test_dir}/.git").returns(true) | |
| provider.exists?.should == true | |
| end | |
| it 'exists? should return false if repository does not exist' do | |
| provider.stubs(:check_for_directory).with("#{test_dir}/.git").returns(false) | |
| provider.exists?.should == false | |
| end | |
| it 'create: should init a directory at path if a source is not passed' do | |
| provider.stubs(:create_directory).with(test_dir) | |
| provider.expects(:git).with(['init', test_dir]) | |
| provider.create | |
| end | |
| it 'create: should clone a repository to path if a source is passed' do | |
| source_dir = 'https://github.com/glarizza/puppet-property_list_key.git' | |
| resource[:source] = source_dir | |
| provider.stubs(:prep_file_path).with(test_dir) | |
| provider.expects(:git).with(['clone', source_dir, test_dir]) | |
| provider.create | |
| end | |
| it 'destroy: should call prep_file_path to delete a repository' do | |
| provider.expects(:prep_file_path).with(test_dir) | |
| provider.destroy | |
| end | |
| it 'revision(MOCKED): should call git to request a revision' do | |
| provider.expects(:git_lazy).with(['rev-parse', 'HEAD']).returns("blah\n") | |
| provider.revision.should == 'blah' | |
| end | |
| it 'revision(INTEGRATION): should return a valid revision' do | |
| my_current_revision = '0f1fe08ae583baea7918e8fa4c449f59a91e981d' | |
| resource[:path] = '/tmp/plk' | |
| resource[:source] = 'https://github.com/glarizza/puppet-property_list_key.git' | |
| provider.create | |
| provider.revision.should == my_current_revision | |
| end | |
| it 'revision=(MOCKED): should call git_lazy to set a revision' do | |
| revision = 'foo' | |
| provider.expects(:git_lazy).with(['fetch', 'origin']) | |
| provider.expects(:git_lazy).with(['checkout', revision, '-f']) | |
| provider.revision=(revision) | |
| end | |
| it 'revision=(INTEGRATION): should ensure that create() will set a revision' do | |
| revision = '8dccef3177893ba039f9e638f1f511c4840178bc' | |
| resource[:revision] = revision | |
| resource[:path] = '/tmp/plk' | |
| resource[:source] = 'https://github.com/glarizza/puppet-property_list_key.git' | |
| provider.create | |
| provider.revision.should == revision | |
| end | |
| it 'revision=(INTEGRATION): should set a valid revision' do | |
| revision = '8dccef3177893ba039f9e638f1f511c4840178bc' | |
| resource[:revision] = revision | |
| resource[:path] = '/tmp/plk' | |
| resource[:source] = 'https://github.com/glarizza/puppet-property_list_key.git' | |
| provider.create | |
| provider.revision.should == revision | |
| my_current_revision = '0f1fe08ae583baea7918e8fa4c449f59a91e981d' | |
| provider.revision=(my_current_revision) | |
| provider.revision.should == my_current_revision | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment