@@ -34,9 +34,9 @@ def test_download_scanner(self, mock_urlopen, mock_write_binaries):
3434 mock_urlopen .return_value = bytes ()
3535
3636 expected_destination = "destination/scanner.zip"
37- destination = environment ._download_scanner_binaries ("destination" , "test_version" , "os_name" )
37+ destination = environment ._download_scanner_binaries ("destination" , "test_version" , "os_name" , "aarch64" )
3838
39- mock_urlopen .assert_called_once_with ("http://scanner.com/download-test_version-os_name.zip" )
39+ mock_urlopen .assert_called_once_with ("http://scanner.com/download-test_version-os_name-aarch64 .zip" )
4040 mock_write_binaries .assert_called_once_with (bytes (), expected_destination )
4141 assert destination == expected_destination
4242
@@ -46,12 +46,12 @@ def test_download_scanner_http_error(self, mock_urlopen, mock_write_binaries):
4646 cfg = Configuration ()
4747 environment = Environment (cfg )
4848 environment .scanner_base_url = "http://scanner.com/download"
49- url = "http://scanner.com/download-test_version-os_name.zip"
49+ url = "http://scanner.com/download-test_version-os_name-x64 .zip"
5050 mock_urlopen .side_effect = Mock (side_effect = HTTPError (url , 504 , "Test" , {}, None ))
5151
5252 with self .assertLogs (environment .log ) as log :
5353 with self .assertRaises (HTTPError ):
54- environment ._download_scanner_binaries ("destination" , "test_version" , "os_name" )
54+ environment ._download_scanner_binaries ("destination" , "test_version" , "os_name" , "x64" )
5555 mock_urlopen .assert_called_once_with (url )
5656 assert not mock_write_binaries .called
5757 expected_error_message = "ERROR: could not download scanner binaries - 504 - Test"
@@ -75,10 +75,13 @@ def test_install_scanner(self, mock_os, mock_unzip_binaries):
7575 environment ._change_permissions_recursive = Mock ()
7676
7777 system_name = "test"
78- environment ._install_scanner (system_name )
78+ arch_name = "arch-test"
79+ environment ._install_scanner (system_name , arch_name )
7980
8081 mock_os .mkdir .assert_called_once_with (scanner_path )
81- environment ._download_scanner_binaries .assert_called_once_with (scanner_path , scanner_version , system_name )
82+ environment ._download_scanner_binaries .assert_called_once_with (
83+ scanner_path , scanner_version , system_name , arch_name
84+ )
8285 mock_unzip_binaries .assert_called_once_with (download_destination , scanner_path )
8386
8487 mock_os .remove .assert_called_once_with (download_destination )
@@ -103,16 +106,19 @@ def test_setup_when_scanner_is_not_on_path(self, mock_systems):
103106 environment = Environment (cfg )
104107 environment .cleanup = Mock ()
105108 system_name = "test"
109+ arch_name = "arch-test"
110+ environment ._get_platform_arch = Mock (return_value = arch_name )
106111 mock_systems .get = Mock (return_value = system_name )
107112 environment ._is_sonar_scanner_on_path = Mock (return_value = False )
108113 environment ._install_scanner = Mock ()
109- expected_path = "path/sonar-scanner-4.1.2-test/bin/sonar-scanner"
114+ expected_path = "path/sonar-scanner-4.1.2-test-arch-test /bin/sonar-scanner"
110115
111116 environment .setup ()
112117
113118 environment .cleanup .assert_called_once ()
114119 mock_systems .get .assert_called_once ()
115- environment ._install_scanner .assert_called_once_with (system_name )
120+ environment ._get_platform_arch .assert_called_once ()
121+ environment ._install_scanner .assert_called_once_with (system_name , arch_name )
116122
117123 assert cfg .sonar_scanner_executable_path == expected_path
118124
@@ -158,6 +164,21 @@ def test_is_sonar_scanner_on_path(self, mock_shutil):
158164
159165 mock_shutil .which .assert_called_once_with ("sonar-scanner" )
160166
167+ def test_get_platform_arch (self ):
168+ release_names = ["root:test/release_arm64_T8101" , "6.0.1-generic" , "root:xnu-7195.60.75~1/RELEASE_ARM64_T8101" ]
169+
170+ def releases ():
171+ return release_names .pop (0 )
172+
173+ cfg = Configuration ()
174+ cfg .sonar_scanner_path = "path"
175+ cfg .sonar_scanner_version = "4.1.2"
176+ environment = Environment (cfg )
177+ environment ._get_release = Mock (side_effect = releases )
178+ assert environment ._get_platform_arch () == "aarch64"
179+ assert environment ._get_platform_arch () == "x64"
180+ assert environment ._get_platform_arch () == "aarch64"
181+
161182 def test_env_scan (self ):
162183 cfg = Configuration ()
163184 environment = Environment (cfg )
0 commit comments