require 'test_helper' require 'build-tool/vcs/git' class GitConfigurationTest < ActiveSupport::TestCase test 'Constructor.' do cfg = BuildTool::VCS::GitConfiguration.new assert_equal( 'git', cfg.name ) assert_equal( {}, cfg.remote ) assert_equal( {}, cfg.global_options ) assert_equal( {}, cfg.options ) assert_equal( 'origin/master', cfg.track ) end test 'Track is correctly split.' do cfg = BuildTool::VCS::GitConfiguration.new assert_equal( 'origin', cfg.track_remote ) assert_equal( 'master', 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 instance.' do cfg = BuildTool::VCS::GitConfiguration.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::GitConfiguration.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::GitConfiguration.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::GitConfiguration.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::GitConfiguration.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 private def create_configuration # Reset global configuration BuildTool::VCS::GitConfiguration.global_config = nil # Create a configuration object cfg = BuildTool::VCS::GitConfiguration.new cfg.track = 'myremote/mybranch' cfg.options = { :option1 => "option 1", :option2 => "option 2" } cfg.remote['origin'] = 'GitRemoteObject 1' cfg.remote['private'] = 'GitRemoteObject 2' 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