| 
									
										
										
										
											2012-10-15 01:19:31 -05:00
										 |  |  | require 'testing_env' | 
					
						
							|  |  |  | require 'download_strategy' | 
					
						
							| 
									
										
										
										
											2013-04-07 00:49:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-30 21:36:38 -05:00
										 |  |  | class ResourceDouble | 
					
						
							| 
									
										
										
										
											2013-04-07 00:49:56 -05:00
										 |  |  |   attr_reader :url, :specs | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-12 17:58:12 -05:00
										 |  |  |   def initialize(url="http://example.com/foo.tar.gz", specs={}) | 
					
						
							| 
									
										
										
										
											2013-04-07 00:49:56 -05:00
										 |  |  |     @url = url | 
					
						
							|  |  |  |     @specs = specs | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class AbstractDownloadStrategyTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2013-04-07 00:49:56 -05:00
										 |  |  |   def setup | 
					
						
							|  |  |  |     @name = "foo" | 
					
						
							| 
									
										
										
										
											2013-09-30 21:36:38 -05:00
										 |  |  |     @resource = ResourceDouble.new | 
					
						
							|  |  |  |     @strategy = AbstractDownloadStrategy.new(@name, @resource) | 
					
						
							| 
									
										
										
										
											2013-04-07 00:49:56 -05:00
										 |  |  |     @args = %w{foo bar baz} | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_expand_safe_system_args_with_explicit_quiet_flag | 
					
						
							|  |  |  |     @args << { :quiet_flag => '--flag' } | 
					
						
							|  |  |  |     expanded_args = @strategy.expand_safe_system_args(@args) | 
					
						
							|  |  |  |     assert_equal %w{foo bar baz --flag}, expanded_args | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_expand_safe_system_args_with_implicit_quiet_flag | 
					
						
							|  |  |  |     expanded_args = @strategy.expand_safe_system_args(@args) | 
					
						
							|  |  |  |     assert_equal %w{foo bar -q baz}, expanded_args | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_expand_safe_system_args_does_not_mutate_argument | 
					
						
							|  |  |  |     result = @strategy.expand_safe_system_args(@args) | 
					
						
							|  |  |  |     assert_equal %w{foo bar baz}, @args | 
					
						
							| 
									
										
										
										
											2014-06-10 22:43:47 -05:00
										 |  |  |     refute_same @args, result | 
					
						
							| 
									
										
										
										
											2013-04-07 00:49:56 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2012-10-15 01:19:31 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class VCSDownloadStrategyTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2013-09-30 21:36:38 -05:00
										 |  |  |   def setup | 
					
						
							| 
									
										
										
										
											2014-06-12 17:58:12 -05:00
										 |  |  |     @resource = ResourceDouble.new("http://example.com/bar") | 
					
						
							| 
									
										
										
										
											2013-10-09 21:41:15 -05:00
										 |  |  |     @strategy = VCSDownloadStrategy | 
					
						
							| 
									
										
										
										
											2013-09-30 21:36:38 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def escaped(tag) | 
					
						
							|  |  |  |     "#{ERB::Util.url_encode(@resource.url)}--#{tag}" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_explicit_name | 
					
						
							|  |  |  |     downloader = @strategy.new("baz", @resource) | 
					
						
							| 
									
										
										
										
											2013-10-11 00:11:58 -05:00
										 |  |  |     assert_equal "baz--foo", downloader.cache_filename("foo") | 
					
						
							| 
									
										
										
										
											2013-09-30 21:36:38 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_empty_name | 
					
						
							|  |  |  |     downloader = @strategy.new("", @resource) | 
					
						
							| 
									
										
										
										
											2013-10-11 00:11:58 -05:00
										 |  |  |     assert_equal escaped("foo"), downloader.cache_filename("foo") | 
					
						
							| 
									
										
										
										
											2013-09-30 21:36:38 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_unknown_name | 
					
						
							|  |  |  |     downloader = @strategy.new("__UNKNOWN__", @resource) | 
					
						
							| 
									
										
										
										
											2013-10-11 00:11:58 -05:00
										 |  |  |     assert_equal escaped("foo"), downloader.cache_filename("foo") | 
					
						
							| 
									
										
										
										
											2013-09-30 21:36:38 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class DownloadStrategyDetectorTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2012-10-15 01:19:31 -05:00
										 |  |  |   def setup | 
					
						
							|  |  |  |     @d = DownloadStrategyDetector.new | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_detect_git_download_startegy | 
					
						
							| 
									
										
										
										
											2014-06-12 17:58:12 -05:00
										 |  |  |     @d = DownloadStrategyDetector.detect("git://example.com/foo.git") | 
					
						
							| 
									
										
										
										
											2012-10-15 01:19:31 -05:00
										 |  |  |     assert_equal GitDownloadStrategy, @d | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_default_to_curl_strategy | 
					
						
							|  |  |  |     @d = DownloadStrategyDetector.detect(Object.new) | 
					
						
							|  |  |  |     assert_equal CurlDownloadStrategy, @d | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-26 16:59:45 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_raises_when_passed_unrecognized_strategy | 
					
						
							|  |  |  |     assert_raises(TypeError) do | 
					
						
							|  |  |  |       DownloadStrategyDetector.detect("foo", Class.new) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-10-15 01:19:31 -05:00
										 |  |  | end |