@@ -87,34 +87,52 @@ func TestSetAccountId(t *testing.T) {
8787
8888func TestLoginGetClusterID (t * testing.T ) {
8989 testCases := []struct {
90- name string
91- profile string
92- expected string
90+ name string
91+ profile string
92+ configFileEnv string
93+ expected string
9394 }{
9495 {
95- name : "existing cluster profile" ,
96- profile : "cluster-profile" ,
97- expected : "cluster-from-config" ,
96+ name : "cluster profile" ,
97+ profile : "cluster-profile" ,
98+ configFileEnv : "./testdata/.databrickscfg" ,
99+ expected : "cluster-from-config" ,
98100 },
99101 {
100- name : "empty profile" ,
101- profile : "no-profile" ,
102- expected : "" ,
102+ name : "empty profile" ,
103+ profile : "no-profile" ,
104+ configFileEnv : "./testdata/.databrickscfg" ,
105+ expected : "" ,
103106 },
104107 {
105- name : "account profile" ,
106- profile : "account-profile" ,
107- expected : "" ,
108+ name : "account profile" ,
109+ profile : "account-profile" ,
110+ configFileEnv : "./testdata/.databrickscfg" ,
111+ expected : "" ,
112+ },
113+ {
114+ name : "config doesn't exist" ,
115+ profile : "any-profile" ,
116+ configFileEnv : "./nonexistent/.databrickscfg" ,
117+ expected : "" ,
118+ },
119+ {
120+ name : "invalid profile (missing host)" ,
121+ profile : "invalid-profile" ,
122+ configFileEnv : "./testdata/.databrickscfg" ,
123+ expected : "" ,
108124 },
109125 }
110126
111- t .Setenv ("DATABRICKS_CONFIG_FILE" , "./testdata/.databrickscfg" )
112-
113127 for _ , tc := range testCases {
114128 t .Run (tc .name , func (t * testing.T ) {
115- clusterID , err := getClusterID (context .Background (), tc .profile , "./testdata/.databrickscfg" )
129+ t .Setenv ("DATABRICKS_CONFIG_FILE" , tc .configFileEnv )
130+
131+ clusterID , err := getClusterID (context .Background (), tc .profile )
116132 require .NoError (t , err )
117- assert .Equal (t , tc .expected , clusterID )
133+ assert .Equal (t , tc .expected , clusterID ,
134+ "Test case '%s' failed: expected cluster ID '%s', but got '%s' (profile: %s, config file: %s)" ,
135+ tc .name , tc .expected , clusterID , tc .profile , tc .configFileEnv )
118136 })
119137 }
120138}
0 commit comments