Skip to content

Commit 8ddc65e

Browse files
committed
Refactoring of tests with comments
1 parent f8ce0f1 commit 8ddc65e

3 files changed

Lines changed: 37 additions & 23 deletions

File tree

cmd/auth/login.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ depends on the existing profiles you have set in your configuration file
136136
return err
137137
}
138138

139+
// Bug fix: Preserve cluster_id from existing profile during login
140+
// Prior to v0.233.0, the login command would overwrite the entire profile configuration,
141+
// causing loss of cluster_id and other settings. Now we first retrieve the existing
142+
// cluster_id before saving the new configuration to ensure it's preserved.
143+
cfg.ClusterID, err = getClusterID(ctx, profileName, defaultConfigPath)
144+
if err != nil {
145+
return err
146+
}
139147
if configureCluster {
140148
w, err := databricks.NewWorkspaceClient((*databricks.Config)(&cfg))
141149
if err != nil {
@@ -148,12 +156,6 @@ depends on the existing profiles you have set in your configuration file
148156
return err
149157
}
150158
cfg.ClusterID = clusterID
151-
} else {
152-
cfg.ClusterID, err = getClusterID(ctx, profileName, defaultConfigPath)
153-
if err != nil {
154-
return err
155-
}
156-
157159
}
158160

159161
if profileName != "" {

cmd/auth/login_test.go

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,36 @@ func TestSetAccountId(t *testing.T) {
8585
assert.EqualError(t, err, "the command is being run in a non-interactive environment, please specify an account ID using --account-id")
8686
}
8787

88-
func TestLoginPreservesClusterID(t *testing.T) {
89-
t.Setenv("DATABRICKS_CONFIG_FILE", "./testdata/.databrickscfg")
90-
clusterID, err := getClusterID(context.Background(), "cluster-profile", "./testdata/.databrickscfg")
91-
require.NoError(t, err)
92-
assert.Equal(t, "cluster-from-config", clusterID)
93-
}
88+
func TestLoginGetClusterID(t *testing.T) {
89+
testCases := []struct {
90+
name string
91+
profile string
92+
expected string
93+
}{
94+
{
95+
name: "existing cluster profile",
96+
profile: "cluster-profile",
97+
expected: "cluster-from-config",
98+
},
99+
{
100+
name: "empty profile",
101+
profile: "no-profile",
102+
expected: "",
103+
},
104+
{
105+
name: "account profile",
106+
profile: "account-profile",
107+
expected: "",
108+
},
109+
}
94110

95-
func TestLoginPreservesClusterIDWithEmptyHostAndAccountID(t *testing.T) {
96111
t.Setenv("DATABRICKS_CONFIG_FILE", "./testdata/.databrickscfg")
97-
clusterID, err := getClusterID(context.Background(), "no-profile", "./testdata/.databrickscfg")
98-
require.NoError(t, err)
99-
assert.Equal(t, "", clusterID)
100-
}
101112

102-
func TestLoginNoClusterIDWithAccountProfile(t *testing.T) {
103-
t.Setenv("DATABRICKS_CONFIG_FILE", "./testdata/.databrickscfg")
104-
clusterID, err := getClusterID(context.Background(), "account-profile", "./testdata/.databrickscfg")
105-
require.NoError(t, err)
106-
assert.Equal(t, "", clusterID)
113+
for _, tc := range testCases {
114+
t.Run(tc.name, func(t *testing.T) {
115+
clusterID, err := getClusterID(context.Background(), tc.profile, "./testdata/.databrickscfg")
116+
require.NoError(t, err)
117+
assert.Equal(t, tc.expected, clusterID)
118+
})
119+
}
107120
}

cmd/auth/testdata/.databrickscfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ host = https://www.host2.com
88
host = https://accounts.cloud.databricks.com
99
account_id = id-from-profile
1010

11-
1211
[cluster-profile]
1312
host = https://www.host2.com
1413
cluster_id = cluster-from-config

0 commit comments

Comments
 (0)