mirror of https://github.com/databricks/cli.git
set client during initialization
This commit is contained in:
parent
bebbf4b767
commit
8cc50c2a19
|
@ -143,20 +143,14 @@ func (b *Bundle) InitializeWorkspaceClient() (*databricks.WorkspaceClient, error
|
|||
}
|
||||
|
||||
func (b *Bundle) WorkspaceClient() *databricks.WorkspaceClient {
|
||||
b.clientOnce.Do(func() {
|
||||
var err error
|
||||
b.client, err = b.InitializeWorkspaceClient()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
if b.client == nil {
|
||||
panic("workspace client not initialized yet. This is a bug in the Databricks CLI.")
|
||||
}
|
||||
return b.client
|
||||
}
|
||||
|
||||
// SetWorkpaceClient sets the workspace client for this bundle.
|
||||
// This is used to inject a mock client for testing.
|
||||
func (b *Bundle) SetWorkpaceClient(w *databricks.WorkspaceClient) {
|
||||
b.clientOnce.Do(func() {})
|
||||
b.client = w
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,10 @@ func TestInitEnvironmentVariables(t *testing.T) {
|
|||
// TODO(pietern): create test fixture that initializes a mocked client.
|
||||
t.Setenv("DATABRICKS_HOST", "https://x")
|
||||
t.Setenv("DATABRICKS_TOKEN", "foobar")
|
||||
b.WorkspaceClient()
|
||||
|
||||
client, err := b.InitializeWorkspaceClient()
|
||||
require.NoError(t, err)
|
||||
b.SetWorkpaceClient(client)
|
||||
|
||||
diags := bundle.Apply(context.Background(), b, Initialize())
|
||||
require.NoError(t, diags.Error())
|
||||
|
|
|
@ -30,7 +30,10 @@ func TestLoadWithNoState(t *testing.T) {
|
|||
|
||||
t.Setenv("DATABRICKS_HOST", "https://x")
|
||||
t.Setenv("DATABRICKS_TOKEN", "foobar")
|
||||
b.WorkspaceClient()
|
||||
|
||||
client, err := b.InitializeWorkspaceClient()
|
||||
require.NoError(t, err)
|
||||
b.SetWorkpaceClient(client)
|
||||
|
||||
diags := bundle.Apply(context.Background(), b, bundle.Seq(
|
||||
Initialize(),
|
||||
|
|
|
@ -93,6 +93,7 @@ func configureBundle(cmd *cobra.Command, b *bundle.Bundle) (*bundle.Bundle, diag
|
|||
}
|
||||
ctx = context.WithValue(ctx, &configUsed, client.Config)
|
||||
cmd.SetContext(ctx)
|
||||
b.SetWorkpaceClient(client)
|
||||
|
||||
return b, diags
|
||||
}
|
||||
|
|
|
@ -91,7 +91,10 @@ func assertBuiltinTemplateValid(t *testing.T, template string, settings map[stri
|
|||
})
|
||||
|
||||
b.Tagging = tags.ForCloud(w.Config)
|
||||
b.WorkspaceClient()
|
||||
|
||||
client, err := b.InitializeWorkspaceClient()
|
||||
require.NoError(t, err)
|
||||
b.SetWorkpaceClient(client)
|
||||
|
||||
diags = bundle.Apply(ctx, b, bundle.Seq(
|
||||
phases.Initialize(),
|
||||
|
|
Loading…
Reference in New Issue