Skip to content

Commit 4d15ff1

Browse files
committed
add ut
1 parent 03341ad commit 4d15ff1

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

  • src/azure-cli/azure/cli/command_modules/acs/tests/latest

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,40 @@ def test_k8s_install_kubelogin_with_custom_source_url(self, logger_mock, mock_ur
690690
finally:
691691
shutil.rmtree(temp_dir)
692692

693+
@mock.patch('azure.cli.command_modules.acs.custom._urlopen_read')
694+
@mock.patch('azure.cli.command_modules.acs.custom._urlretrieve')
695+
@mock.patch('azure.cli.command_modules.acs.custom.logger')
696+
def test_k8s_install_kubelogin_with_gh_token(self, logger_mock, mock_url_retrieve, mock_urlopen_read):
697+
"""Test that gh_token parameter is properly passed to HTTP requests when installing kubelogin."""
698+
# Mock the GitHub API response for latest release
699+
mock_urlopen_read.return_value = b'{"tag_name": "v0.0.30"}'
700+
# Mock the zip file download
701+
mock_url_retrieve.side_effect = create_kubelogin_zip
702+
703+
try:
704+
temp_dir = tempfile.mkdtemp()
705+
test_location = os.path.join(temp_dir, 'foo', 'kubelogin')
706+
test_gh_token = 'ghp_test_token_123'
707+
708+
# Install kubelogin with gh_token
709+
k8s_install_kubelogin(
710+
mock.MagicMock(),
711+
client_version='latest',
712+
install_location=test_location,
713+
arch="amd64",
714+
gh_token=test_gh_token
715+
)
716+
717+
# Verify gh_token was passed to _urlopen_read for GitHub API call
718+
mock_urlopen_read.assert_called_once()
719+
call_args = mock_urlopen_read.call_args
720+
self.assertEqual(call_args.kwargs.get('gh_token'), test_gh_token)
721+
722+
# Verify the installation completed
723+
self.assertTrue(os.path.exists(test_location))
724+
finally:
725+
shutil.rmtree(temp_dir)
726+
693727
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_rg_location', return_value='eastus')
694728
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resource_groups_client', autospec=True)
695729
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resources_client', autospec=True)

0 commit comments

Comments
 (0)