mirror of https://github.com/databricks/cli.git
add unit test
This commit is contained in:
parent
010ea442d0
commit
93928e25e6
|
@ -6,21 +6,6 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
// func SetWorkspaceClient(ctx context.Context, w *databricks.WorkspaceClient) context.Context {
|
|
||||||
// if v := ctx.Value(workspaceClientKey); v != nil {
|
|
||||||
// panic("command.SetWorkspaceClient called twice on the same context.")
|
|
||||||
// }
|
|
||||||
// return context.WithValue(ctx, workspaceClientKey, w)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func WorkspaceClient(ctx context.Context) *databricks.WorkspaceClient {
|
|
||||||
// v := ctx.Value(workspaceClientKey)
|
|
||||||
// if v == nil {
|
|
||||||
// panic("command.WorkspaceClient called without calling command.SetWorkspaceClient first.")
|
|
||||||
// }
|
|
||||||
// return v.(*databricks.WorkspaceClient)
|
|
||||||
// }
|
|
||||||
|
|
||||||
func SetAccountClient(ctx context.Context, a *databricks.AccountClient) context.Context {
|
func SetAccountClient(ctx context.Context, a *databricks.AccountClient) context.Context {
|
||||||
if v := ctx.Value(accountClientKey); v != nil {
|
if v := ctx.Value(accountClientKey); v != nil {
|
||||||
panic("command.SetAccountClient called twice on the same context")
|
panic("command.SetAccountClient called twice on the same context")
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package command
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/databricks/databricks-sdk-go"
|
||||||
|
"github.com/databricks/databricks-sdk-go/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCommandAccountClient(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
client := &databricks.AccountClient{
|
||||||
|
Config: &config.Config{
|
||||||
|
AccountID: "test-account",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Panic if AccountClient is called before SetAccountClient.
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
AccountClient(ctx)
|
||||||
|
})
|
||||||
|
|
||||||
|
ctx = SetAccountClient(context.Background(), client)
|
||||||
|
|
||||||
|
// Multiple calls should return a pointer to the same client.
|
||||||
|
a := AccountClient(ctx)
|
||||||
|
assert.Same(t, a, AccountClient(ctx))
|
||||||
|
|
||||||
|
// The client should have the correct configuration.
|
||||||
|
assert.Equal(t, "test-account", AccountClient(ctx).Config.AccountID)
|
||||||
|
|
||||||
|
// Second call should panic.
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
SetAccountClient(ctx, client)
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue