# Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide. # # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use, # reproduction, modification, or disclosure of this program is # strictly prohibited. Any use of this program by an authorized # licensee is strictly subject to the terms and conditions, # including confidentiality obligations, set forth in the applicable # License Agreement between RightScale.com, Inc. and # the licensee require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) describe RightConf::GitRepoConfigurator do before(:each) do @configurator = create_configurator('git_repo { repo "git"; path "./git" }') @abf = { :abort_on_failure => 'Failed to clone git into ./git' } end it 'should clone' do flexmock(File).should_receive(:exist?).with('./git').and_return(false) should_execute('git', 'clone', 'git', './git', @abf).once @configurator.run_linux end it 'should checkout the right tag' do flexmock(File).should_receive(:exist?).with('./git').and_return(false) @configurator.instance_eval { tag('tag') } should_execute('git', 'clone', 'git', './git', @abf).once flexmock(Dir).should_receive(:chdir).with('./git', Proc).and_yield should_execute('git', 'checkout', 'tag', {:abort_on_failure=>"Failed to checkout tag"}).once @configurator.run_linux end it 'should skip checkout if directory already exists and contains a .git subdirectory' do flexmock(File).should_receive(:exist?).with('./git').twice.and_return(true) flexmock(File).should_receive(:exist?).with('./git/.git').once.and_return(true) should_execute.and_return { raise 'Command.execute should not be called' } @configurator.run_linux end it 'should move directory if already exists but not a git repo' do flexmock(File).should_receive(:exist?).with('./git').once.ordered.and_return(true) flexmock(File).should_receive(:exist?).with('./git/.git').once.ordered.and_return(false) flexmock(File).should_receive(:exist?).with('./git').once.ordered.and_return(false) flexmock(FileUtils).should_receive(:mv).once should_execute('git', 'clone', 'git', './git', @abf).once @configurator.run_linux end end