require 'test_helper' require 'build-tool/vcs/git-svn' class GitSvnConfigurationTest < ActiveSupport::TestCase ####################### # THE GIT FUNCTIONALITY # test 'Constructor.' do cfg = BuildTool::VCS::GitSvnConfiguration.new() cfg.vcs( ModuleMock.new( 'test' ) ) assert_equal( 'git-svn', cfg.name ) assert_equal( {}, cfg.remote ) assert_equal( {}, cfg.global_options ) assert_equal( {}, cfg.options ) assert_equal( 'remotes/git-svn', cfg.track ) assert_raise( BuildTool::ConfigurationError ) { cfg.repository } end test 'Track is correctly split.' do cfg = BuildTool::VCS::GitSvnConfiguration.new assert_equal( 'remotes', cfg.track_remote ) assert_equal( 'git-svn', cfg.track_branch ) cfg.track = 'myremote/mybranch' assert_equal( 'myremote', cfg.track_remote ) assert_equal( 'mybranch', cfg.track_branch ) end test 'Vcs() returns a git-svn instance.' do cfg = BuildTool::VCS::GitSvnConfiguration.new # :TODO: # assert( cfg.vcs.is_a?( BuildTool::VCS::Git ), "vcs() returns a instance of Git." ) end test 'track() accessor works.' do cfg = create_configuration assert_equal( 'myremote/mybranch', cfg.track ) end test 'track() accessor works with inheritance.' do parent = create_configuration # Create a empty object with a parent cfg = BuildTool::VCS::GitSvnConfiguration.new cfg.parent = parent # Value is taken from parent assert_equal( 'myremote/mybranch', cfg.track ) # Unless we set it locally cfg.track = 'repo1/test' assert_equal( 'repo1/test', cfg.track ) # After a reset cfg.track = nil assert_equal( 'myremote/mybranch', cfg.track ) end test 'options() accessor works.' do cfg = create_configuration assert_equal( 'option 1', cfg.options[:option1] ) assert_equal( 'option 2', cfg.options[:option2] ) assert_nil( cfg.options[:option3] ) end test 'options() accessor works with inheritance.' do parent = create_configuration # Create a empty object with a parent cfg = BuildTool::VCS::GitSvnConfiguration.new cfg.parent = parent # Options are not merged. assert_nil( cfg.options[:option1] ) assert_nil( cfg.options[:option2] ) assert_nil( cfg.options[:option3] ) # Merged_options is merged with the parent. assert_equal( 'option 1', cfg.merged_options[:option1] ) assert_equal( 'option 2', cfg.merged_options[:option2] ) assert_nil( cfg.merged_options[:option3] ) # But ours have priority cfg.options[:option1] = 'overwritten' assert_equal( 'overwritten', cfg.merged_options[:option1] ) end test 'options() accessor works with global configuration.' do cfg = create_configuration create_global_configuration assert_equal( 'option 1', cfg.merged_options[:option1] ) assert_equal( 'option 2', cfg.merged_options[:option2] ) assert_equal( 'option 3(set globally)', cfg.merged_options[:option3] ) end test 'options() accessor works with global configuration and inheritance.' do parent = create_configuration # Create a empty object with a parent cfg = BuildTool::VCS::GitSvnConfiguration.new cfg.parent = parent cfg.options[:option1] = 'overwritten' # Merged_options is merged with the parent and global create_global_configuration assert_equal( 'overwritten', cfg.merged_options[:option1] ) assert_equal( 'option 2', cfg.merged_options[:option2] ) assert_equal( 'option 3(set globally)', cfg.merged_options[:option3] ) # And we can reset them cfg.options.delete(:option1) assert_equal( 'option 1', cfg.merged_options[:option1] ) end test 'global_options() works.' do cfg = create_configuration assert_equal( {}, cfg.global_options ) end test 'global_options() works with global configuration.' do cfg = create_configuration create_global_configuration assert_equal( 'global option 1', cfg.merged_global_options[:globaloption1] ) assert_equal( 'global option 2', cfg.merged_global_options[:globaloption2] ) end test 'remote() accessor works.' do cfg = create_configuration assert_equal( 'GitRemoteObject 1', cfg.remote['origin'] ) assert_equal( 'GitRemoteObject 1', cfg.merged_remote['origin'] ) end test 'remote() accessor works with inheritance.' do parent = create_configuration cfg = BuildTool::VCS::GitSvnConfiguration.new cfg.parent = parent cfg.remote['other'] = 'other' assert_nil( cfg.remote['origin'] ) assert_equal( 'GitRemoteObject 1', cfg.merged_remote['origin'] ) assert_equal( 'other', cfg.merged_remote['other'] ) cfg.remote['origin'] = 'test' assert_equal( 'test', cfg.merged_remote['origin'] ) assert_equal( 'other', cfg.merged_remote['other'] ) end ####################### # THE GIT-SVN FUNCTIONALITY # test 'Constructor Git-SVN.' do cfg = BuildTool::VCS::GitSvnConfiguration.new assert_equal( {}, cfg.externals ) assert_equal( {}, cfg.merged_externals ) end test 'external() accessor works.' do cfg = create_configuration assert_equal( 'svn+ssh@user@example.com/remote/path', cfg.externals[ 'local/path' ] ) end test 'external() accessor works with inheritance.' do parent = create_configuration # Create a empty object with a parent cfg = BuildTool::VCS::GitSvnConfiguration.new cfg.parent = parent # Value is taken from parent assert_equal( 'svn+ssh@user@example.com/remote/path', cfg.merged_externals[ 'local/path' ] ) # Unless we set it locally cfg.externals['local/path'] ='svn+ssh@user@example.com/remote/other/path' assert_equal( 'svn+ssh@user@example.com/remote/other/path', cfg.merged_externals[ 'local/path' ] ) # After a reset cfg.externals.delete( 'local/path' ) assert_equal( 'svn+ssh@user@example.com/remote/path', cfg.merged_externals[ 'local/path' ] ) end test 'repository() accessor works.' do cfg = create_configuration assert_equal( 'repo', cfg.repository.name ) end test 'repository() accessor works with inheritance.' do parent = create_configuration # Create a empty object with a parent cfg = BuildTool::VCS::GitSvnConfiguration.new cfg.parent = parent # Value is taken from parent assert_equal( 'repo', cfg.repository.name ) # Unless we set it locally cfg.repository = RepositoryMock.new( 'repo2' ) assert_equal( 'repo2', cfg.repository.name ) # After a reset cfg.repository = nil assert_equal( 'repo', cfg.repository.name ) end test 'accessor remote_path() works.' do cfg = create_configuration assert_equal( 'remote/path', cfg.remote_path ) end test 'accessor remote_path() works with inheritance.' do parent = create_configuration cfg = BuildTool::VCS::GitSvnConfiguration.new cfg.vcs( ModuleMock.new( 'test' ) ) cfg.parent = parent # We get the value from the parent assert_equal( 'remote/path', cfg.remote_path ) # Unless we override it cfg.remote_path = 'remote/other_path' assert_equal( 'remote/other_path', cfg.remote_path ) # And we can reset it cfg.remote_path = nil assert_equal( 'remote/path', cfg.remote_path ) end private def create_configuration # Reset global configuration BuildTool::VCS::GitConfiguration.global_config = nil # Create a configuration object cfg = BuildTool::VCS::GitSvnConfiguration.new cfg.track = 'myremote/mybranch' cfg.options = { :option1 => "option 1", :option2 => "option 2" } cfg.remote['origin'] = 'GitRemoteObject 1' cfg.remote['private'] = 'GitRemoteObject 2' cfg.externals['local/path'] ='svn+ssh@user@example.com/remote/path' cfg.repository = RepositoryMock.new( 'repo' ) cfg.remote_path = 'remote/path' cfg end def create_global_configuration # Add a global configuration object global = BuildTool::VCS::GitConfiguration.new BuildTool::VCS::GitConfiguration.global_config = global global.options = { :option1 => "option 1(set globally)", :option3 => "option 3(set globally)" } global.global_options = { :globaloption1 => "global option 1", :globaloption2 => "global option 2" } global end end # class GitSvnConfigurationTest