@@ -18,19 +18,19 @@ class DatabricksCliCredentialsProviderTest {
1818 private final DatabricksCliCredentialsProvider provider = new DatabricksCliCredentialsProvider ();
1919
2020 @ Test
21- void testBuildCliCommand_WorkspaceHost () {
21+ void testBuildHostArgs_WorkspaceHost () {
2222 DatabricksConfig config = new DatabricksConfig ().setHost (HOST );
2323
24- List <String > cmd = provider .buildCliCommand (CLI_PATH , config );
24+ List <String > cmd = provider .buildHostArgs (CLI_PATH , config );
2525
2626 assertEquals (Arrays .asList (CLI_PATH , "auth" , "token" , "--host" , HOST ), cmd );
2727 }
2828
2929 @ Test
30- void testBuildCliCommand_AccountHost () {
30+ void testBuildHostArgs_AccountHost () {
3131 DatabricksConfig config = new DatabricksConfig ().setHost (ACCOUNT_HOST ).setAccountId (ACCOUNT_ID );
3232
33- List <String > cmd = provider .buildCliCommand (CLI_PATH , config );
33+ List <String > cmd = provider .buildHostArgs (CLI_PATH , config );
3434
3535 assertEquals (
3636 Arrays .asList (
@@ -39,15 +39,15 @@ void testBuildCliCommand_AccountHost() {
3939 }
4040
4141 @ Test
42- void testBuildCliCommand_UnifiedHost_WithAccountIdAndWorkspaceId () {
42+ void testBuildHostArgs_UnifiedHost_WithAccountIdAndWorkspaceId () {
4343 DatabricksConfig config =
4444 new DatabricksConfig ()
4545 .setHost (UNIFIED_HOST )
4646 .setExperimentalIsUnifiedHost (true )
4747 .setAccountId (ACCOUNT_ID )
4848 .setWorkspaceId (WORKSPACE_ID );
4949
50- List <String > cmd = provider .buildCliCommand (CLI_PATH , config );
50+ List <String > cmd = provider .buildHostArgs (CLI_PATH , config );
5151
5252 assertEquals (
5353 Arrays .asList (
@@ -65,14 +65,14 @@ void testBuildCliCommand_UnifiedHost_WithAccountIdAndWorkspaceId() {
6565 }
6666
6767 @ Test
68- void testBuildCliCommand_UnifiedHost_WithAccountIdOnly () {
68+ void testBuildHostArgs_UnifiedHost_WithAccountIdOnly () {
6969 DatabricksConfig config =
7070 new DatabricksConfig ()
7171 .setHost (UNIFIED_HOST )
7272 .setExperimentalIsUnifiedHost (true )
7373 .setAccountId (ACCOUNT_ID );
7474
75- List <String > cmd = provider .buildCliCommand (CLI_PATH , config );
75+ List <String > cmd = provider .buildHostArgs (CLI_PATH , config );
7676
7777 assertEquals (
7878 Arrays .asList (
@@ -88,14 +88,14 @@ void testBuildCliCommand_UnifiedHost_WithAccountIdOnly() {
8888 }
8989
9090 @ Test
91- void testBuildCliCommand_UnifiedHost_WithWorkspaceIdOnly () {
91+ void testBuildHostArgs_UnifiedHost_WithWorkspaceIdOnly () {
9292 DatabricksConfig config =
9393 new DatabricksConfig ()
9494 .setHost (UNIFIED_HOST )
9595 .setExperimentalIsUnifiedHost (true )
9696 .setWorkspaceId (WORKSPACE_ID );
9797
98- List <String > cmd = provider .buildCliCommand (CLI_PATH , config );
98+ List <String > cmd = provider .buildHostArgs (CLI_PATH , config );
9999
100100 assertEquals (
101101 Arrays .asList (
@@ -111,11 +111,11 @@ void testBuildCliCommand_UnifiedHost_WithWorkspaceIdOnly() {
111111 }
112112
113113 @ Test
114- void testBuildCliCommand_UnifiedHost_WithNoAccountIdOrWorkspaceId () {
114+ void testBuildHostArgs_UnifiedHost_WithNoAccountIdOrWorkspaceId () {
115115 DatabricksConfig config =
116116 new DatabricksConfig ().setHost (UNIFIED_HOST ).setExperimentalIsUnifiedHost (true );
117117
118- List <String > cmd = provider .buildCliCommand (CLI_PATH , config );
118+ List <String > cmd = provider .buildHostArgs (CLI_PATH , config );
119119
120120 assertEquals (
121121 Arrays .asList (
@@ -124,19 +124,50 @@ void testBuildCliCommand_UnifiedHost_WithNoAccountIdOrWorkspaceId() {
124124 }
125125
126126 @ Test
127- void testBuildCliCommand_UnifiedHostFalse_WithAccountHost () {
127+ void testBuildHostArgs_UnifiedHostFalse_WithAccountHost () {
128128 // When experimentalIsUnifiedHost is explicitly false, should fall back to account-id logic
129129 DatabricksConfig config =
130130 new DatabricksConfig ()
131131 .setHost (ACCOUNT_HOST )
132132 .setExperimentalIsUnifiedHost (false )
133133 .setAccountId (ACCOUNT_ID );
134134
135- List <String > cmd = provider .buildCliCommand (CLI_PATH , config );
135+ List <String > cmd = provider .buildHostArgs (CLI_PATH , config );
136136
137137 assertEquals (
138138 Arrays .asList (
139139 CLI_PATH , "auth" , "token" , "--host" , ACCOUNT_HOST , "--account-id" , ACCOUNT_ID ),
140140 cmd );
141141 }
142+
143+ @ Test
144+ void testProfile_UsesPrimaryProfileCmdWithHostFallback () {
145+ // When profile is set and host is present, --profile is primary and --host is fallback.
146+ // We verify this by inspecting buildHostArgs (fallback path) and the profile args (primary).
147+ DatabricksConfig config = new DatabricksConfig ().setHost (HOST ).setProfile ("my-profile" );
148+
149+ // The primary command that getDatabricksCliTokenSource would build
150+ List <String > expectedPrimary =
151+ Arrays .asList (CLI_PATH , "auth" , "token" , "--profile" , "my-profile" );
152+ // The fallback command is the host-based one
153+ List <String > expectedFallback = provider .buildHostArgs (CLI_PATH , config );
154+
155+ assertEquals (Arrays .asList (CLI_PATH , "auth" , "token" , "--host" , HOST ), expectedFallback );
156+ assertEquals (
157+ Arrays .asList ("auth" , "token" , "--profile" , "my-profile" ),
158+ expectedPrimary .subList (1 , expectedPrimary .size ()));
159+ assertFalse (expectedFallback .contains ("--profile" ));
160+ assertTrue (expectedFallback .contains ("--host" ));
161+ }
162+
163+ @ Test
164+ void testProfile_NoHostFallbackWhenHostAbsent () {
165+ // When profile is set but host is null, buildHostArgs is not called so no fallback is built.
166+ // This test confirms buildHostArgs correctly uses host when present.
167+ DatabricksConfig config = new DatabricksConfig ().setHost (HOST );
168+ List <String > hostArgs = provider .buildHostArgs (CLI_PATH , config );
169+ assertTrue (hostArgs .contains ("--host" ));
170+ assertTrue (hostArgs .contains (HOST ));
171+ assertFalse (hostArgs .contains ("--profile" ));
172+ }
142173}
0 commit comments