@@ -27,7 +27,7 @@ module JavaBuildpack::Repository
2727
2828 it 'should load index' do
2929 JavaBuildpack ::Util ::DownloadCache . stub ( :new ) . and_return ( application_cache )
30- application_cache . stub ( :get ) . with ( canonical '{platform}/{architecture}/ test-uri/index.yml' )
30+ application_cache . stub ( :get ) . with ( %r(/ test-uri/index\ . yml) )
3131 . and_yield ( File . open ( 'spec/fixtures/test-index.yml' ) )
3232 VersionResolver . stub ( :resolve ) . with ( 'test-version' , %w( resolved-version ) ) . and_return ( 'resolved-version' )
3333
@@ -52,6 +52,43 @@ module JavaBuildpack::Repository
5252 end
5353 end
5454
55+ it 'should handle Mac OS X correctly' do
56+ with_host ( 'darwin12.3.0' , 'x86_64' ) do
57+ JavaBuildpack ::Util ::DownloadCache . stub ( :new ) . and_return ( application_cache )
58+ RepositoryIndex . any_instance . stub ( :` ) . with ( 'sw_vers -productVersion' ) . and_return ( '10.8.4' )
59+ application_cache . stub ( :get ) . with ( 'mountainlion/x86_64/test-uri/index.yml' ) . and_yield ( File . open ( 'spec/fixtures/test-index.yml' ) )
60+ RepositoryIndex . new ( '{platform}/{architecture}/test-uri' )
61+ expect ( application_cache ) . to have_received ( :get ) . with ( %r(mountainlion/x86_64/test-uri/index\. yml) )
62+ end
63+ end
64+
65+ it 'should handle incorrect Mac OS X version correctly' do
66+ with_host ( 'darwin12.3.0' , 'x86_64' ) do
67+ JavaBuildpack ::Util ::DownloadCache . stub ( :new ) . and_return ( application_cache )
68+ RepositoryIndex . any_instance . stub ( :` ) . with ( 'sw_vers -productVersion' ) . and_return ( '10.7.1' )
69+ expect { RepositoryIndex . new ( '{platform}/{architecture}/test-uri' ) } . to raise_error ( /Unsupported OS X version/ )
70+ end
71+ end
72+
73+ it 'should handle Linux correctly' do
74+ with_host ( 'linux-gnu' , 'x86_64' ) do
75+ JavaBuildpack ::Util ::DownloadCache . stub ( :new ) . and_return ( application_cache )
76+ RepositoryIndex . any_instance . stub ( :` ) . with ( 'lsb_release -cs' ) . and_return ( 'precise' )
77+ application_cache . stub ( :get ) . with ( 'precise/x86_64/test-uri/index.yml' ) . and_yield ( File . open ( 'spec/fixtures/test-index.yml' ) )
78+ RepositoryIndex . new ( '{platform}/{architecture}/test-uri' )
79+ expect ( application_cache ) . to have_received ( :get ) . with ( %r(precise/x86_64/test-uri/index\. yml) )
80+ end
81+ end
82+
83+ def with_host ( host_os , host_cpu )
84+ previous_host_os , RbConfig ::CONFIG [ 'host_os' ] = RbConfig ::CONFIG [ 'host_os' ] , host_os
85+ previous_host_cpu , RbConfig ::CONFIG [ 'host_cpu' ] = RbConfig ::CONFIG [ 'host_cpu' ] , host_cpu
86+ yield
87+ ensure
88+ RbConfig ::CONFIG [ 'host_os' ] = previous_host_os
89+ RbConfig ::CONFIG [ 'host_cpu' ] = previous_host_cpu
90+ end
91+
5592 def with_buildpack_cache ( directory )
5693 previous_value , ENV [ 'BUILDPACK_CACHE' ] = ENV [ 'BUILDPACK_CACHE' ] , directory
5794 yield
0 commit comments