mirror of https://github.com/databricks/cli.git
Rename types and add tests
This commit is contained in:
parent
ed62d0821c
commit
354d765833
|
@ -41,37 +41,37 @@ func (l *Lookup) constructResolver() (resolver, error) {
|
||||||
var resolvers []resolver
|
var resolvers []resolver
|
||||||
|
|
||||||
if l.Alert != "" {
|
if l.Alert != "" {
|
||||||
resolvers = append(resolvers, lookupAlert{name: l.Alert})
|
resolvers = append(resolvers, resolveAlert{name: l.Alert})
|
||||||
}
|
}
|
||||||
if l.ClusterPolicy != "" {
|
if l.ClusterPolicy != "" {
|
||||||
resolvers = append(resolvers, lookupClusterPolicy{name: l.ClusterPolicy})
|
resolvers = append(resolvers, resolveClusterPolicy{name: l.ClusterPolicy})
|
||||||
}
|
}
|
||||||
if l.Cluster != "" {
|
if l.Cluster != "" {
|
||||||
resolvers = append(resolvers, lookupCluster{name: l.Cluster})
|
resolvers = append(resolvers, resolveCluster{name: l.Cluster})
|
||||||
}
|
}
|
||||||
if l.Dashboard != "" {
|
if l.Dashboard != "" {
|
||||||
resolvers = append(resolvers, lookupDashboard{name: l.Dashboard})
|
resolvers = append(resolvers, resolveDashboard{name: l.Dashboard})
|
||||||
}
|
}
|
||||||
if l.InstancePool != "" {
|
if l.InstancePool != "" {
|
||||||
resolvers = append(resolvers, lookupInstancePool{name: l.InstancePool})
|
resolvers = append(resolvers, resolveInstancePool{name: l.InstancePool})
|
||||||
}
|
}
|
||||||
if l.Job != "" {
|
if l.Job != "" {
|
||||||
resolvers = append(resolvers, lookupJob{name: l.Job})
|
resolvers = append(resolvers, resolveJob{name: l.Job})
|
||||||
}
|
}
|
||||||
if l.Metastore != "" {
|
if l.Metastore != "" {
|
||||||
resolvers = append(resolvers, lookupMetastore{name: l.Metastore})
|
resolvers = append(resolvers, resolveMetastore{name: l.Metastore})
|
||||||
}
|
}
|
||||||
if l.Pipeline != "" {
|
if l.Pipeline != "" {
|
||||||
resolvers = append(resolvers, lookupPipeline{name: l.Pipeline})
|
resolvers = append(resolvers, resolvePipeline{name: l.Pipeline})
|
||||||
}
|
}
|
||||||
if l.Query != "" {
|
if l.Query != "" {
|
||||||
resolvers = append(resolvers, lookupQuery{name: l.Query})
|
resolvers = append(resolvers, resolveQuery{name: l.Query})
|
||||||
}
|
}
|
||||||
if l.ServicePrincipal != "" {
|
if l.ServicePrincipal != "" {
|
||||||
resolvers = append(resolvers, lookupServicePrincipal{name: l.ServicePrincipal})
|
resolvers = append(resolvers, resolveServicePrincipal{name: l.ServicePrincipal})
|
||||||
}
|
}
|
||||||
if l.Warehouse != "" {
|
if l.Warehouse != "" {
|
||||||
resolvers = append(resolvers, lookupWarehouse{name: l.Warehouse})
|
resolvers = append(resolvers, resolveWarehouse{name: l.Warehouse})
|
||||||
}
|
}
|
||||||
|
|
||||||
switch len(resolvers) {
|
switch len(resolvers) {
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package variable
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLookup_Coverage(t *testing.T) {
|
||||||
|
var lookup Lookup
|
||||||
|
val := reflect.ValueOf(lookup)
|
||||||
|
typ := val.Type()
|
||||||
|
|
||||||
|
for i := 0; i < val.NumField(); i++ {
|
||||||
|
field := val.Field(i)
|
||||||
|
if field.Kind() != reflect.String {
|
||||||
|
t.Fatalf("Field %s is not a string", typ.Field(i).Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldType := typ.Field(i)
|
||||||
|
t.Run(fieldType.Name, func(t *testing.T) {
|
||||||
|
// Use a fresh instance of the struct in each test
|
||||||
|
var lookup Lookup
|
||||||
|
|
||||||
|
// Set the field to a non-empty string
|
||||||
|
reflect.ValueOf(&lookup).Elem().Field(i).SetString("value")
|
||||||
|
|
||||||
|
// Test the [String] function
|
||||||
|
assert.NotEmpty(t, lookup.String())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLookup_Empty(t *testing.T) {
|
||||||
|
var lookup Lookup
|
||||||
|
|
||||||
|
// Resolve returns an error when no fields are provided
|
||||||
|
_, err := lookup.Resolve(context.Background(), nil)
|
||||||
|
assert.ErrorContains(t, err, "no valid lookup fields provided")
|
||||||
|
|
||||||
|
// No string representation for an invalid lookup
|
||||||
|
assert.Empty(t, lookup.String())
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLookup_Multiple(t *testing.T) {
|
||||||
|
lookup := Lookup{
|
||||||
|
Alert: "alert",
|
||||||
|
Query: "query",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve returns an error when multiple fields are provided
|
||||||
|
_, err := lookup.Resolve(context.Background(), nil)
|
||||||
|
assert.ErrorContains(t, err, "exactly one lookup field must be provided")
|
||||||
|
|
||||||
|
// No string representation for an invalid lookup
|
||||||
|
assert.Empty(t, lookup.String())
|
||||||
|
}
|
|
@ -7,11 +7,11 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lookupAlert struct {
|
type resolveAlert struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupAlert) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l resolveAlert) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Alerts.GetByDisplayName(ctx, l.name)
|
entity, err := w.Alerts.GetByDisplayName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l lookupAlert) Resolve(ctx context.Context, w *databricks.WorkspaceClient)
|
||||||
return fmt.Sprint(entity.Id), nil
|
return fmt.Sprint(entity.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupAlert) String() string {
|
func (l resolveAlert) String() string {
|
||||||
return fmt.Sprintf("alert: %s", l.name)
|
return fmt.Sprintf("alert: %s", l.name)
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookupAlert_ResolveSuccess(t *testing.T) {
|
func TestResolveAlert_ResolveSuccess(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockAlertsAPI()
|
api := m.GetMockAlertsAPI()
|
||||||
|
@ -23,13 +23,13 @@ func TestLookupAlert_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupAlert{name: "alert"}
|
l := resolveAlert{name: "alert"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "1234", result)
|
assert.Equal(t, "1234", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupAlert_ResolveNotFound(t *testing.T) {
|
func TestResolveAlert_ResolveNotFound(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockAlertsAPI()
|
api := m.GetMockAlertsAPI()
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupAlert_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupAlert{name: "alert"}
|
l := resolveAlert{name: "alert"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupAlert_String(t *testing.T) {
|
func TestResolveAlert_String(t *testing.T) {
|
||||||
l := lookupAlert{name: "name"}
|
l := resolveAlert{name: "name"}
|
||||||
assert.Equal(t, "alert: name", l.String())
|
assert.Equal(t, "alert: name", l.String())
|
||||||
}
|
}
|
|
@ -8,13 +8,13 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go/service/compute"
|
"github.com/databricks/databricks-sdk-go/service/compute"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lookupCluster struct {
|
type resolveCluster struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
// We added a custom resolver for the cluster to add filtering for the cluster source when we list all clusters.
|
// We added a custom resolver for the cluster to add filtering for the cluster source when we list all clusters.
|
||||||
// Without the filtering listing could take a very long time (5-10 mins) which leads to lookup timeouts.
|
// Without the filtering listing could take a very long time (5-10 mins) which leads to lookup timeouts.
|
||||||
func (l lookupCluster) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l resolveCluster) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
result, err := w.Clusters.ListAll(ctx, compute.ListClustersRequest{
|
result, err := w.Clusters.ListAll(ctx, compute.ListClustersRequest{
|
||||||
FilterBy: &compute.ListClustersFilterBy{
|
FilterBy: &compute.ListClustersFilterBy{
|
||||||
ClusterSources: []compute.ClusterSource{compute.ClusterSourceApi, compute.ClusterSourceUi},
|
ClusterSources: []compute.ClusterSource{compute.ClusterSourceApi, compute.ClusterSourceUi},
|
||||||
|
@ -42,6 +42,6 @@ func (l lookupCluster) Resolve(ctx context.Context, w *databricks.WorkspaceClien
|
||||||
return alternatives[0].ClusterId, nil
|
return alternatives[0].ClusterId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupCluster) String() string {
|
func (l resolveCluster) String() string {
|
||||||
return fmt.Sprintf("cluster: %s", l.name)
|
return fmt.Sprintf("cluster: %s", l.name)
|
||||||
}
|
}
|
|
@ -7,11 +7,11 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lookupClusterPolicy struct {
|
type resolveClusterPolicy struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupClusterPolicy) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l resolveClusterPolicy) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.ClusterPolicies.GetByName(ctx, l.name)
|
entity, err := w.ClusterPolicies.GetByName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l lookupClusterPolicy) Resolve(ctx context.Context, w *databricks.Workspac
|
||||||
return fmt.Sprint(entity.PolicyId), nil
|
return fmt.Sprint(entity.PolicyId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupClusterPolicy) String() string {
|
func (l resolveClusterPolicy) String() string {
|
||||||
return fmt.Sprintf("cluster-policy: %s", l.name)
|
return fmt.Sprintf("cluster-policy: %s", l.name)
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookupClusterPolicy_ResolveSuccess(t *testing.T) {
|
func TestResolveClusterPolicy_ResolveSuccess(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockClusterPoliciesAPI()
|
api := m.GetMockClusterPoliciesAPI()
|
||||||
|
@ -23,13 +23,13 @@ func TestLookupClusterPolicy_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupClusterPolicy{name: "policy"}
|
l := resolveClusterPolicy{name: "policy"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "1234", result)
|
assert.Equal(t, "1234", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupClusterPolicy_ResolveNotFound(t *testing.T) {
|
func TestResolveClusterPolicy_ResolveNotFound(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockClusterPoliciesAPI()
|
api := m.GetMockClusterPoliciesAPI()
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupClusterPolicy_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupClusterPolicy{name: "policy"}
|
l := resolveClusterPolicy{name: "policy"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupClusterPolicy_String(t *testing.T) {
|
func TestResolveClusterPolicy_String(t *testing.T) {
|
||||||
l := lookupClusterPolicy{name: "name"}
|
l := resolveClusterPolicy{name: "name"}
|
||||||
assert.Equal(t, "cluster-policy: name", l.String())
|
assert.Equal(t, "cluster-policy: name", l.String())
|
||||||
}
|
}
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookupCluster_ResolveSuccess(t *testing.T) {
|
func TestResolveCluster_ResolveSuccess(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockClustersAPI()
|
api := m.GetMockClustersAPI()
|
||||||
|
@ -23,13 +23,13 @@ func TestLookupCluster_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupCluster{name: "cluster2"}
|
l := resolveCluster{name: "cluster2"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "2345", result)
|
assert.Equal(t, "2345", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupCluster_ResolveNotFound(t *testing.T) {
|
func TestResolveCluster_ResolveNotFound(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockClustersAPI()
|
api := m.GetMockClustersAPI()
|
||||||
|
@ -38,13 +38,13 @@ func TestLookupCluster_ResolveNotFound(t *testing.T) {
|
||||||
Return([]compute.ClusterDetails{}, nil)
|
Return([]compute.ClusterDetails{}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupCluster{name: "cluster"}
|
l := resolveCluster{name: "cluster"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
assert.Contains(t, err.Error(), "cluster named 'cluster' does not exist")
|
assert.Contains(t, err.Error(), "cluster named 'cluster' does not exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupCluster_String(t *testing.T) {
|
func TestResolveCluster_String(t *testing.T) {
|
||||||
l := lookupCluster{name: "name"}
|
l := resolveCluster{name: "name"}
|
||||||
assert.Equal(t, "cluster: name", l.String())
|
assert.Equal(t, "cluster: name", l.String())
|
||||||
}
|
}
|
|
@ -7,11 +7,11 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lookupDashboard struct {
|
type resolveDashboard struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupDashboard) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l resolveDashboard) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Dashboards.GetByName(ctx, l.name)
|
entity, err := w.Dashboards.GetByName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l lookupDashboard) Resolve(ctx context.Context, w *databricks.WorkspaceCli
|
||||||
return fmt.Sprint(entity.Id), nil
|
return fmt.Sprint(entity.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupDashboard) String() string {
|
func (l resolveDashboard) String() string {
|
||||||
return fmt.Sprintf("dashboard: %s", l.name)
|
return fmt.Sprintf("dashboard: %s", l.name)
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookupDashboard_ResolveSuccess(t *testing.T) {
|
func TestResolveDashboard_ResolveSuccess(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockDashboardsAPI()
|
api := m.GetMockDashboardsAPI()
|
||||||
|
@ -23,13 +23,13 @@ func TestLookupDashboard_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupDashboard{name: "dashboard"}
|
l := resolveDashboard{name: "dashboard"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "1234", result)
|
assert.Equal(t, "1234", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupDashboard_ResolveNotFound(t *testing.T) {
|
func TestResolveDashboard_ResolveNotFound(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockDashboardsAPI()
|
api := m.GetMockDashboardsAPI()
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupDashboard_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupDashboard{name: "dashboard"}
|
l := resolveDashboard{name: "dashboard"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupDashboard_String(t *testing.T) {
|
func TestResolveDashboard_String(t *testing.T) {
|
||||||
l := lookupDashboard{name: "name"}
|
l := resolveDashboard{name: "name"}
|
||||||
assert.Equal(t, "dashboard: name", l.String())
|
assert.Equal(t, "dashboard: name", l.String())
|
||||||
}
|
}
|
|
@ -7,11 +7,11 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lookupInstancePool struct {
|
type resolveInstancePool struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupInstancePool) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l resolveInstancePool) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.InstancePools.GetByInstancePoolName(ctx, l.name)
|
entity, err := w.InstancePools.GetByInstancePoolName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l lookupInstancePool) Resolve(ctx context.Context, w *databricks.Workspace
|
||||||
return fmt.Sprint(entity.InstancePoolId), nil
|
return fmt.Sprint(entity.InstancePoolId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupInstancePool) String() string {
|
func (l resolveInstancePool) String() string {
|
||||||
return fmt.Sprintf("instance-pool: %s", l.name)
|
return fmt.Sprintf("instance-pool: %s", l.name)
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookupInstancePool_ResolveSuccess(t *testing.T) {
|
func TestResolveInstancePool_ResolveSuccess(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockInstancePoolsAPI()
|
api := m.GetMockInstancePoolsAPI()
|
||||||
|
@ -23,13 +23,13 @@ func TestLookupInstancePool_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupInstancePool{name: "instance_pool"}
|
l := resolveInstancePool{name: "instance_pool"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "5678", result)
|
assert.Equal(t, "5678", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupInstancePool_ResolveNotFound(t *testing.T) {
|
func TestResolveInstancePool_ResolveNotFound(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockInstancePoolsAPI()
|
api := m.GetMockInstancePoolsAPI()
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupInstancePool_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupInstancePool{name: "instance_pool"}
|
l := resolveInstancePool{name: "instance_pool"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupInstancePool_String(t *testing.T) {
|
func TestResolveInstancePool_String(t *testing.T) {
|
||||||
l := lookupInstancePool{name: "name"}
|
l := resolveInstancePool{name: "name"}
|
||||||
assert.Equal(t, "instance-pool: name", l.String())
|
assert.Equal(t, "instance-pool: name", l.String())
|
||||||
}
|
}
|
|
@ -7,11 +7,11 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lookupJob struct {
|
type resolveJob struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupJob) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l resolveJob) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Jobs.GetBySettingsName(ctx, l.name)
|
entity, err := w.Jobs.GetBySettingsName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l lookupJob) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (
|
||||||
return fmt.Sprint(entity.JobId), nil
|
return fmt.Sprint(entity.JobId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupJob) String() string {
|
func (l resolveJob) String() string {
|
||||||
return fmt.Sprintf("job: %s", l.name)
|
return fmt.Sprintf("job: %s", l.name)
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookupJob_ResolveSuccess(t *testing.T) {
|
func TestResolveJob_ResolveSuccess(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockJobsAPI()
|
api := m.GetMockJobsAPI()
|
||||||
|
@ -23,13 +23,13 @@ func TestLookupJob_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupJob{name: "job"}
|
l := resolveJob{name: "job"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "5678", result)
|
assert.Equal(t, "5678", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupJob_ResolveNotFound(t *testing.T) {
|
func TestResolveJob_ResolveNotFound(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockJobsAPI()
|
api := m.GetMockJobsAPI()
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupJob_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupJob{name: "job"}
|
l := resolveJob{name: "job"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupJob_String(t *testing.T) {
|
func TestResolveJob_String(t *testing.T) {
|
||||||
l := lookupJob{name: "name"}
|
l := resolveJob{name: "name"}
|
||||||
assert.Equal(t, "job: name", l.String())
|
assert.Equal(t, "job: name", l.String())
|
||||||
}
|
}
|
|
@ -7,11 +7,11 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lookupMetastore struct {
|
type resolveMetastore struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupMetastore) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l resolveMetastore) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Metastores.GetByName(ctx, l.name)
|
entity, err := w.Metastores.GetByName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l lookupMetastore) Resolve(ctx context.Context, w *databricks.WorkspaceCli
|
||||||
return fmt.Sprint(entity.MetastoreId), nil
|
return fmt.Sprint(entity.MetastoreId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupMetastore) String() string {
|
func (l resolveMetastore) String() string {
|
||||||
return fmt.Sprintf("metastore: %s", l.name)
|
return fmt.Sprintf("metastore: %s", l.name)
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookupMetastore_ResolveSuccess(t *testing.T) {
|
func TestResolveMetastore_ResolveSuccess(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockMetastoresAPI()
|
api := m.GetMockMetastoresAPI()
|
||||||
|
@ -23,13 +23,13 @@ func TestLookupMetastore_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupMetastore{name: "metastore"}
|
l := resolveMetastore{name: "metastore"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "abcd", result)
|
assert.Equal(t, "abcd", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupMetastore_ResolveNotFound(t *testing.T) {
|
func TestResolveMetastore_ResolveNotFound(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockMetastoresAPI()
|
api := m.GetMockMetastoresAPI()
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupMetastore_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupMetastore{name: "metastore"}
|
l := resolveMetastore{name: "metastore"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupMetastore_String(t *testing.T) {
|
func TestResolveMetastore_String(t *testing.T) {
|
||||||
l := lookupMetastore{name: "name"}
|
l := resolveMetastore{name: "name"}
|
||||||
assert.Equal(t, "metastore: name", l.String())
|
assert.Equal(t, "metastore: name", l.String())
|
||||||
}
|
}
|
|
@ -7,11 +7,11 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lookupPipeline struct {
|
type resolvePipeline struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupPipeline) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l resolvePipeline) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Pipelines.GetByName(ctx, l.name)
|
entity, err := w.Pipelines.GetByName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l lookupPipeline) Resolve(ctx context.Context, w *databricks.WorkspaceClie
|
||||||
return fmt.Sprint(entity.PipelineId), nil
|
return fmt.Sprint(entity.PipelineId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupPipeline) String() string {
|
func (l resolvePipeline) String() string {
|
||||||
return fmt.Sprintf("pipeline: %s", l.name)
|
return fmt.Sprintf("pipeline: %s", l.name)
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookupPipeline_ResolveSuccess(t *testing.T) {
|
func TestResolvePipeline_ResolveSuccess(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockPipelinesAPI()
|
api := m.GetMockPipelinesAPI()
|
||||||
|
@ -23,13 +23,13 @@ func TestLookupPipeline_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupPipeline{name: "pipeline"}
|
l := resolvePipeline{name: "pipeline"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "abcd", result)
|
assert.Equal(t, "abcd", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupPipeline_ResolveNotFound(t *testing.T) {
|
func TestResolvePipeline_ResolveNotFound(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockPipelinesAPI()
|
api := m.GetMockPipelinesAPI()
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupPipeline_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupPipeline{name: "pipeline"}
|
l := resolvePipeline{name: "pipeline"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupPipeline_String(t *testing.T) {
|
func TestResolvePipeline_String(t *testing.T) {
|
||||||
l := lookupPipeline{name: "name"}
|
l := resolvePipeline{name: "name"}
|
||||||
assert.Equal(t, "pipeline: name", l.String())
|
assert.Equal(t, "pipeline: name", l.String())
|
||||||
}
|
}
|
|
@ -7,11 +7,11 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lookupQuery struct {
|
type resolveQuery struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupQuery) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l resolveQuery) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Queries.GetByDisplayName(ctx, l.name)
|
entity, err := w.Queries.GetByDisplayName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l lookupQuery) Resolve(ctx context.Context, w *databricks.WorkspaceClient)
|
||||||
return fmt.Sprint(entity.Id), nil
|
return fmt.Sprint(entity.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupQuery) String() string {
|
func (l resolveQuery) String() string {
|
||||||
return fmt.Sprintf("query: %s", l.name)
|
return fmt.Sprintf("query: %s", l.name)
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookupQuery_ResolveSuccess(t *testing.T) {
|
func TestResolveQuery_ResolveSuccess(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockQueriesAPI()
|
api := m.GetMockQueriesAPI()
|
||||||
|
@ -23,13 +23,13 @@ func TestLookupQuery_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupQuery{name: "query"}
|
l := resolveQuery{name: "query"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "1234", result)
|
assert.Equal(t, "1234", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupQuery_ResolveNotFound(t *testing.T) {
|
func TestResolveQuery_ResolveNotFound(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockQueriesAPI()
|
api := m.GetMockQueriesAPI()
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupQuery_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupQuery{name: "query"}
|
l := resolveQuery{name: "query"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupQuery_String(t *testing.T) {
|
func TestResolveQuery_String(t *testing.T) {
|
||||||
l := lookupQuery{name: "name"}
|
l := resolveQuery{name: "name"}
|
||||||
assert.Equal(t, "query: name", l.String())
|
assert.Equal(t, "query: name", l.String())
|
||||||
}
|
}
|
|
@ -7,11 +7,11 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lookupServicePrincipal struct {
|
type resolveServicePrincipal struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupServicePrincipal) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l resolveServicePrincipal) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.ServicePrincipals.GetByDisplayName(ctx, l.name)
|
entity, err := w.ServicePrincipals.GetByDisplayName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l lookupServicePrincipal) Resolve(ctx context.Context, w *databricks.Works
|
||||||
return fmt.Sprint(entity.ApplicationId), nil
|
return fmt.Sprint(entity.ApplicationId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupServicePrincipal) String() string {
|
func (l resolveServicePrincipal) String() string {
|
||||||
return fmt.Sprintf("service-principal: %s", l.name)
|
return fmt.Sprintf("service-principal: %s", l.name)
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookupServicePrincipal_ResolveSuccess(t *testing.T) {
|
func TestResolveServicePrincipal_ResolveSuccess(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockServicePrincipalsAPI()
|
api := m.GetMockServicePrincipalsAPI()
|
||||||
|
@ -23,13 +23,13 @@ func TestLookupServicePrincipal_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupServicePrincipal{name: "service-principal"}
|
l := resolveServicePrincipal{name: "service-principal"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "5678", result)
|
assert.Equal(t, "5678", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupServicePrincipal_ResolveNotFound(t *testing.T) {
|
func TestResolveServicePrincipal_ResolveNotFound(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockServicePrincipalsAPI()
|
api := m.GetMockServicePrincipalsAPI()
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupServicePrincipal_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupServicePrincipal{name: "service-principal"}
|
l := resolveServicePrincipal{name: "service-principal"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupServicePrincipal_String(t *testing.T) {
|
func TestResolveServicePrincipal_String(t *testing.T) {
|
||||||
l := lookupServicePrincipal{name: "name"}
|
l := resolveServicePrincipal{name: "name"}
|
||||||
assert.Equal(t, "service-principal: name", l.String())
|
assert.Equal(t, "service-principal: name", l.String())
|
||||||
}
|
}
|
|
@ -7,11 +7,11 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lookupWarehouse struct {
|
type resolveWarehouse struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupWarehouse) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
func (l resolveWarehouse) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) {
|
||||||
entity, err := w.Warehouses.GetByName(ctx, l.name)
|
entity, err := w.Warehouses.GetByName(ctx, l.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -19,6 +19,6 @@ func (l lookupWarehouse) Resolve(ctx context.Context, w *databricks.WorkspaceCli
|
||||||
return fmt.Sprint(entity.Id), nil
|
return fmt.Sprint(entity.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l lookupWarehouse) String() string {
|
func (l resolveWarehouse) String() string {
|
||||||
return fmt.Sprintf("warehouse: %s", l.name)
|
return fmt.Sprintf("warehouse: %s", l.name)
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLookupWarehouse_ResolveSuccess(t *testing.T) {
|
func TestResolveWarehouse_ResolveSuccess(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockWarehousesAPI()
|
api := m.GetMockWarehousesAPI()
|
||||||
|
@ -23,13 +23,13 @@ func TestLookupWarehouse_ResolveSuccess(t *testing.T) {
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupWarehouse{name: "warehouse"}
|
l := resolveWarehouse{name: "warehouse"}
|
||||||
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "abcd", result)
|
assert.Equal(t, "abcd", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupWarehouse_ResolveNotFound(t *testing.T) {
|
func TestResolveWarehouse_ResolveNotFound(t *testing.T) {
|
||||||
m := mocks.NewMockWorkspaceClient(t)
|
m := mocks.NewMockWorkspaceClient(t)
|
||||||
|
|
||||||
api := m.GetMockWarehousesAPI()
|
api := m.GetMockWarehousesAPI()
|
||||||
|
@ -38,12 +38,12 @@ func TestLookupWarehouse_ResolveNotFound(t *testing.T) {
|
||||||
Return(nil, &apierr.APIError{StatusCode: 404})
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l := lookupWarehouse{name: "warehouse"}
|
l := resolveWarehouse{name: "warehouse"}
|
||||||
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
||||||
require.ErrorIs(t, err, apierr.ErrNotFound)
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookupWarehouse_String(t *testing.T) {
|
func TestResolveWarehouse_String(t *testing.T) {
|
||||||
l := lookupWarehouse{name: "name"}
|
l := resolveWarehouse{name: "name"}
|
||||||
assert.Equal(t, "warehouse: name", l.String())
|
assert.Equal(t, "warehouse: name", l.String())
|
||||||
}
|
}
|
Loading…
Reference in New Issue